Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

if your data comes as consecutive image "planes" you will need 3 seperate 1 channel Mat's with the color channels, and then merge them (we also need to swap b<-->r for opencv):

Mat chn[] = {
    Mat(img->h, img->w, CV_8UC1, pData + img->h*img->w*2),  // starting at 1st blue pixel 
    Mat(img->h, img->w, CV_8UC1, pData + img->h*img->w),    // 1st green pixel
    Mat(img->h, img->w, CV_8UC1, pData)                     // 1st red pixel
};

Mat bgr;
merge(chn,3,bgr);

if your data comes as consecutive image "planes" you will need 3 seperate 1 channel Mat's with the color channels, and then merge them (we also need to swap b<-->r for opencv):

Mat chn[] = {
    Mat(img->h, img->w, CV_8UC1, pData + img->h*img->w*2),  // starting at 1st blue pixel 
    Mat(img->h, img->w, CV_8UC1, pData + img->h*img->w),    // 1st green pixel
    Mat(img->h, img->w, CV_8UC1, pData)                     // 1st red pixel
};

Mat bgr;
merge(chn,3,bgr);
imshow("my image !", bgr);
waitKey(33); // else it won't show anything