[英]rgb 8 bits cvMat from other data
我有一個問題,將數據復制到與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;
和其他方式,但沒有辦法。
在opencv2.2中使用新的cv :: MAt時,它已經稍有變化,但是可以看到單獨的彩色像素訪問
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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.