gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-10-31 00:05:26 26 4
gpt4 key购买 nike

我正在尝试获取图像的图像数据,其中 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com