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?
1 | initial version |
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?
2 | No.2 Revision |
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?
3 | No.3 Revision |
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;
}
}
}