DirectX 和 OpenCV

发布于 2024-07-17 07:08:51 字数 510 浏览 5 评论 0原文

所以我已经编写了一个程序,可以将网络摄像头的图像捕获到名为 pBuffer 的向量中。 我可以轻松访问每个像素的 RGB 像素信息,只需通过

pBuffer[i]=R;pBuffer[i+1]=G;Buffer[i+2]=B。

这里没问题。

现在下一步是创建一个 IplImage* img,并用 pBuffer 的信息填充它......某种 SetPixel。

网络上有一个 SetPixel 函数,即:

(((uchar*)(image­>imageData + image­>widthStep*(y))))[x * image­>nChannels + channel] = (uchar)value;

其中值是 pBuffer 信息,x 和 y 是像素坐标。但是我根本无法将其发挥作用。 有任何想法吗?? 我正在使用 C++。

So i have a program written already that captures the image from a webcam, into a vector called pBuffer.
I can easily acess the RGB pixel information of each pixel, simply by

pBuffer[i]=R;pBuffer[i+1]=G;Buffer[i+2]=B.

No problem in here.

The next step is now create an IplImage* img, and fill it in with the information of the pBuffer...some sort of SetPixel.

There is a SetPixel Function on the web, that is :

(((uchar*)(image­>imageData + image­>widthStep*(y))))[x * image­>nChannels + channel] = (uchar)value;

where the value is the pBuffer information, x and y the pixel coordinates.However i simply cannot put this to work. Any ideas?? I am working with C++.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2024-07-24 07:08:51

您想要做的事情可以这样做(假设宽度和高度是图像尺寸):

CvSize size;
size.height = height;
size.width = width;
IplImage* ipl_image_p = cvCreateImage(size, IPL_DEPTH_8U, 3);

for (int y = 0; y < height; ++y)
    for (int x = 0; x < width; ++x)
        for (int channel = 0; channel < 3; ++channel)
            *(ipl_image_p->imageData + ipl_image_p->widthStep * y + x * ipl_image_p->nChannels + channel) = pBuffer[x*y*3+channel];

但是,您不必复制数据。 您还可以通过 IplImage 使用图像数据(假设 pBuffer 是 char* 类型,否则您可能需要强制转换它):

CvSize size;
size.height = height ;
size.width = width;
IplImage* ipl_image_p = cvCreateImageHeader(size, IPL_DEPTH_8U, 3);
ipl_image_p->imageData = pBuffer;
ipl_image_p->imageDataOrigin = ipl_image_p->imageData;

What you are trying to do you can do like this (assuming width and height are the image dimensions):

CvSize size;
size.height = height;
size.width = width;
IplImage* ipl_image_p = cvCreateImage(size, IPL_DEPTH_8U, 3);

for (int y = 0; y < height; ++y)
    for (int x = 0; x < width; ++x)
        for (int channel = 0; channel < 3; ++channel)
            *(ipl_image_p->imageData + ipl_image_p->widthStep * y + x * ipl_image_p->nChannels + channel) = pBuffer[x*y*3+channel];

However, you don't have to copy the data. You can also use your image data by IplImage (assuming pBuffer is of type char*, otherwise you need possibly to cast it):

CvSize size;
size.height = height ;
size.width = width;
IplImage* ipl_image_p = cvCreateImageHeader(size, IPL_DEPTH_8U, 3);
ipl_image_p->imageData = pBuffer;
ipl_image_p->imageDataOrigin = ipl_image_p->imageData;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文