Hello,
I am trying to process YCrCb data from file and convert it to RGB. For this task I am using the following code:
#define DEFAULT_FRAME_Y 288
#define DEFAULT_FRAME_X 544
Mat yuyvFrame = Mat::zeros(DEFAULT_FRAME_Y, DEFAULT_FRAME_X, CV_8UC3);
Mat rgbFrame = Mat::zeros(DEFAULT_FRAME_Y, DEFAULT_FRAME_X, CV_8UC3);
const char rawFileName[] "data.raw";
// data.raw is 544 * 288 * 2 = 313344 bytes long
uint32_t rawSize = 2 * DEFAULT_FRAME_Y, DEFAULT_FRAME_X;
FILE *file = fopen(rawFileName, "r");
if (file == NULL)
{
cout << "Error opening " << rawFileName << endl;
return 1;
}
fread(yuyvFrame.data, sizeof(char), rawSize, file);
cvtColor(yuyvFrame, rgbFrame, CV_YCrCb2BGR);
imwrite("imageRGB.png", rgbFrame);
The good RGB image taken from the camera is the following:
while the generated image is:
The data.raw file has been generated from the following gst-launch pipeline execution:
gst-launch-1.0 -e v4l2src device=/dev/webcam ! videoconvert ! video/x-raw,width=544,height=288,framerate=10/1 ! multifilesink location=data.raw
while the v4l2-ctl --list-formats --device=/dev/webcam
output is the following:
ioctl: VIDIOC_ENUM_FMT
Index : 0
Type : Video Capture
Pixel Format: 'YUYV'
Name : YUYV 4:2:2
Index : 1
Type : Video Capture
Pixel Format: 'MJPG' (compressed)
Name : Motion-JPEG
What's wrong with my code and how can I solve this problem ?