我熟悉OpenCV 1.1中使用的IPL图像格式。然而,我现在正在使用最新的2.4版本并希望切换到OpenCV的C++接口。以下是我访问图像像素的方法:
int step = img->widthStep;
int height = img->height;
int width = img->width;
unsigned char* data = (unsigned char*) img->imageData;
for (int i=0; i<height; i++)
{
for (int j=0; j<step; j+=3) // 3 is the number of channels.
{
if (data[i*step + j] > 200) // For blue
data[i*step + j] = 255;
if (data[i*step + j + 1] > 200) // For green
data[i*step + j + 1] = 255;
if (data[i*step + j + 2] > 200) // For red
data[i*step + j + 2] = 255;
}
}
我需要帮助将这个包含 Mat 结构的代码块转换。虽然我找到了几个函数,但是如果能够整体得到上面几行的精确转换会非常有帮助。