问题描述
在OpenCV中有一个等价的函数,类似于Matlab中的 [srtd,srtdinds] = sort(dst,'ascend');
我试过 cv :: sortIdx(source,dst,cv :: SORT_ASCENDING);
但它不工作。我的来源 Mat
包含一列。
Is there an equivalent function in OpenCV similar to [srtd,srtdinds] = sort(dst,'ascend');
in Matlab? I have tried cv::sortIdx(source, dst, cv::SORT_ASCENDING);
but it doesn't work. My source Mat
contains a single column.
推荐答案
:
这意味着你需要调用 cv :: sort()
来调用 cv :: sortIdx()
,以便复制Matlab的 sort()
函数:
This means that you will need to call cv::sort()
to sort the elements themselves after calling cv::sortIdx()
to replicate the behavior of Matlab's sort()
function:
cv::Mat source = cv::Mat::eye(3,3,CV_32F), dst;
cv::sortIdx(source, dst, CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);
cv::sort(source, source, CV_SORT_EVERY_ROW + CV_SORT_ASCENDING);
现在 dst
包含置换的索引, source
包含已排序数据本身。
Now dst
contains the permuted indices, and source
contains the sorted data itself.
这篇关于在OpenCv中排序cv :: Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!