Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

C++ - Y'CbCr422 to RGB - convert from raw data file

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:

image description

while the generated image is:

image description

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 ?

C++ - Y'CbCr422 to RGB - convert from raw data file

Hello,

I am trying to process YCrCb data from file and convert it to RGB. RGB.
For this task I am using the following code:

#define DEFAULT_FRAME_Y 288
#define DEFAULT_FRAME_X 544

Mat yuyvFrame ycbcrFrame = 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_Y * DEFAULT_FRAME_X;

FILE *file = fopen(rawFileName, "r");
if (file == NULL)
{
    cout << "Error opening " << rawFileName << endl;
    return 1;
}

fread(yuyvFrame.data, fread(ycbcr.data, sizeof(char), rawSize, file);
cvtColor(yuyvFrame, fclose(file);
cvtColor(ycbcr, rgbFrame, CV_YCrCb2BGR);
imwrite("imageRGB.png", rgbFrame);

The good RGB image taken from the camera is the following:

image description

while the generated image is:

image description

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 ?

C++ - Y'CbCr422 to RGB - convert from raw data file

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 ycbcrFrame = 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(ycbcr.data, sizeof(char), rawSize, file);
fclose(file);
cvtColor(ycbcr, rgbFrame, CV_YCrCb2BGR);
imwrite("imageRGB.png", rgbFrame);

The good RGB image taken from the camera is the following:

image description

while the generated image is:

image description

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 ?

EDIT: changing the code as follows: #define DEFAULT_FRAME_Y 288 #define DEFAULT_FRAME_X 544

Mat ycbcrFrame = Mat::zeros(DEFAULT_FRAME_Y, DEFAULT_FRAME_X, CV_8UC2);
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(ycbcr.data, sizeof(char), rawSize, file);
fclose(file);
cvtColor(ycbcr, rgbFrame, CV_YUV2BGR_UYVY);
imwrite("imageRGB.png", rgbFrame);

produces this image:

image description

which is still wrong.