在OpenCv中排序cv :: Mat [英] Sorting cv::Mat in OpenCv

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

问题描述

在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 :: sortIdx()


而不是重新排序元素本身,它存储输出数组中的排序元素的索引。

Instead of reordering the elements themselves, it stores the indices of sorted elements in the output array.

这意味着你需要调用 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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