我正在尝试获取图像的 imageData,其中 w= 图像宽度,h = 图像高度
for (int i = x; i < x+h; i++) //height of frame pixels
{
for (int j = y; j < y+w; j++)//width of frame pixels
{
int pos = i * w * Channels + j; //channels is 3 as rgb
// if any data exists
if (data->imageData[pos]>0) //Taking data (here is the problem how to take)
{
xPos += j;
yPos += i;
nPix++;
}
}
}
最佳答案
jeff7 为您提供了 OpenCV 非常旧版本的链接。 OpenCV 2.0 有一个新的 C++ 包装器,它比链接中提到的 C++ 包装器要好得多。我建议您阅读C++ reference of OpenCV有关如何访问各个像素的信息。
另一件事需要注意的是:外循环应该是 y 方向(垂直)的循环,内循环应该是 x 方向的循环。 OpenCV 采用 C/C++ 语言,它以行专业存储值。
关于c++ - 如何在opencv中访问RGB图像(3 channel 图像)的图像数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2325576/