gpt4 book ai didi

c++ - 在 OpenCv 中对 cv::Mat 进行排序

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:19:33 26 4
gpt4 key购买 nike

OpenCV 中是否有类似于 Matlab 中的 [srtd,srtdinds] = sort(dst,'ascend'); 的等效函数?我试过 cv::sortIdx(source, dst, cv::SORT_ASCENDING); 但它不起作用。我的源 Mat 包含一个列。

最佳答案

来自 cv::sortIdx() 的文档:

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

这意味着在调用 cv::sortIdx() 复制 Matlab 的行为后,您需要调用 cv::sort() 对元素本身进行排序sort() 函数:

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 包含排序后的数据本身。

关于c++ - 在 OpenCv 中对 cv::Mat 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17831753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com