本文介绍了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 arrayI'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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!