开发者

rgb 8 bits cvMat from other data

I have a problem copying data to a cvMat. I tried also creating a structure but it didn't work. The output I get is a black image. This is the relevant code:

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++)
{ 
rgbPoi开发者_开发百科nter[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);

I tried also to copy the data with

rgbMat->data.s[ 3 * (y * XN_VGA_X_RES + x ) + 0 ] = pImageMap[ 3 * (y * XN_VGA_X_RES + x ) + 0 ] .nBlue;

and other ways but no way..


It has changed slightly with the new cv::MAt in opencv2.2 but see 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]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜