我在将数据复制到cvMat时遇到问题。我也试过创建一个结构,但它没有用。我得到的输出是黑色图像。 这是相关的代码:
CvMat* rgbMat = cvCreateMat(480,640,CV_8UC3);
IplImage *kinectRgbImage;
RgbImage = cvCreateImage( cvSize(640,480),8,3);
...stuff...
//from pImageMap you can access to the blue,red,green color parts of the image
for (int y=0; y<XN_VGA_Y_RES; y++)
{
for(int x=0;x<XN_VGA_X_RES;x++)
{
rgbPointer[y * XN_VGA_X_RES + x ].blue= pImageMap[y * XN_VGA_X_RES + x].nBlue;
rgbPointer[y * XN_VGA_X_RES + x ].green= pImageMap[y * XN_VGA_X_RES + x].nGreen;
rgbPointer[y * XN_VGA_X_RES + x ].red= pImageMap[y * XN_VGA_X_RES + x].nRed;
}}
cvGetImage(rgbPointer,RgbImage);
cvShowImage( "Rgb", RgbImage);
我还试图用
复制数据rgbMat->data.s[ 3 * (y * XN_VGA_X_RES + x ) + 0 ] = pImageMap[ 3 * (y * XN_VGA_X_RES + x ) + 0 ] .nBlue;
和其他方式,但没办法..
答案 0 :(得分:0)
在opencv2.2中使用新的cv :: MAt略有改变,但请参阅individual colour pixel access
I(x,y)blue ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3]
I(x,y)green ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+1]
I(x,y)red ~ ((uchar*)(img->imageData + img->widthStep*y))[x*3+2]