在MATLAB中我们经常会使用find函数来查找对应像素所在所有的行向量和列向量(对应的坐标值),
在MATLAB中的书写格式为:
[rows, cols] = find(X == n); % 即为你想查找的像素值
在OpenCV中我并没有找到相对应的函数,如果有谁知道什么函数函数能够实现相对应的功能,麻烦告知我一下,下面的这个函数是我自己写的一个代码段,如果有什么问题,接受批评和指教。
void find(Mat image, int num, vector<Point>& points)
{
uchar* pPixel;
for (int row = 0; row < image.rows; ++row)
{
pPixel = image.ptr(row);
for (int col = 0; col < image.cols; ++col)
{
if (*pPixel == num)
{
points.push_back(Point(col, row));
}
++pPixel;
}
}
}