OpenCV中的随机顺序随机播放cv :: Mat [英] Random order shuffle cv::Mat in OpenCV

查看:229
本文介绍了OpenCV中的随机顺序随机播放cv :: Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenCV中是否没有功能可以随机排序矩阵(按行排序)?

Is there no function in OpenCV to randomly shuffle a matrx (ordered by rows)?

输入:

1 2 3
4 5 6
7 8 9

输出:

4 5 6
7 8 9
1 2 3

cv :: randShuffle函数似乎只能随机排列整个数组中的元素 我正在使用更新的C ++ API

cv::randShuffle function only seems to randomly order the elements in the entire array I'm using the newer C++ API

推荐答案

用于改组矩阵行的代码:

Code to shuffle the rows of a matrix:

cv::Mat shuffleRows(const cv::Mat &matrix)
{
  std::vector <int> seeds;
  for (int cont = 0; cont < matrix.rows; cont++)
    seeds.push_back(cont);

  cv::randShuffle(seeds);

  cv::Mat output;
  for (int cont = 0; cont < matrix.rows; cont++)
    output.push_back(matrix.row(seeds[cont]));

  return output;
}

这篇关于OpenCV中的随机顺序随机播放cv :: Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆