Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get raw image data from Matrix?

Hello, I am new to OpenCV. I need to get raw image data from a Matrix in C++. The matrix is of type CvType.CV_8UC4 Can anyone point me in the right direction? Or even better some sample code?

How to get raw RGBA8888 image data from 8UC4 Matrix?

Hello, I am new to OpenCV. I need to get raw RGBA8888 image data from a Matrix in C++. The matrix is of type CvType.CV_8UC4 CvType.CV_8UC4 . Is this possible? Can anyone point me in the right direction? Or even better some sample code?

How to get RGBA8888 image data from 8UC4 Matrix?

Hello, I am new to OpenCV. I need to get raw RGBA8888 image data from a Matrix in C++. The matrix is of type CvType.CV_8UC4 . Is this possible? Can anyone point me in the right direction? Or even better some sample code?

UPDATE I have created the following methods to da that with help from Mathiew. Is this correct?

void HelloWorld::convertBRGAtoRGBA(Mat mat, Mat dst)
{
    dst(mat); //create a copy
    for( int rowIndex = 0 ; rowIndex < mat.rows ; ++rowIndex )
    {
        for( int colIndex = 0 ; colIndex < mat.cols ; ++colIndex )
        {
            cv::Vec4b val = mat.at<cv::Vec4b>(rowIndex,colIndex);
        char blue = val[0];
        char green = val[1];
        char red = val[2];
        char alpha = val[3];
       //do anything you want here...
        dst.at<Vec4b>(rowIndex, colIndex)[0] = red;
        dst.at<Vec4b>(rowIndex, colIndex)[1] = green;
        dst.at<Vec4b>(rowIndex, colIndex)[2] = blue;
        dst.at<Vec4b>(rowIndex, colIndex)[3] = alpha;
    }
}
}