【发布时间】:2012-06-23 04:06:05
【问题描述】:
我正在尝试将图像的像素值(例如 80x20)从最低到最高排序。
下面是部分代码:
bool sortPixel(int first, int second)
{
return (first < second);
}
vector<int>vect_sortPixel;
for(int y=0; y<height; y++)
{
for(int x=0; x<width; x++)
{
vect_sortPixel.push_back(cvGetReal2D(srcImg, y, x));
sort(vect_sortPixel.begin(), vect_sortPixel.end(), sortPixel);
}
}
但是计算需要相当长的时间。有什么减少处理时间的建议吗? 谢谢。
【问题讨论】:
-
您可以为
sort()方法添加代码吗? -
对不起。排序是从(algorithm.h)调用的
-
在OpenCV中使用
sort函数怎么样? docs.opencv.org/modules/core/doc/… -
但它声明“如果您想按字典顺序对矩阵行或列进行排序,您可以使用带有适当比较谓词的 STL std::sort 泛型函数。”