c++ - 如何在opencv中访问RGB图像(3 channel 图像)的图像数据

标签 c++ c opencv computer-vision

我正在尝试获取图像的 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/

相关文章:

c++ - 具有相同 src 的多个 'strcat' 上的内存损坏

c - C中通过指针将函数的返回值传递给另一个函数

performance - OpenCV findChessboardCorners 很慢

c++ - opencv 将图像与文本二值化

c++ - 将 c++11 之前的设置函数更改为带有转发功能的现代模板化函数是个好主意吗

c++ - 在 C++ 中隐藏黑色窗口

c++ - 使用 Emscripten 将 OpenGL ES 转换反馈数据返回给主机

c - 如何从 Void 函数返回值?

c - 在 C 中实现管道

android - 未找到 native Stitch 的实现