hello I'm not good very in english I want open a "10 bit YCbCr 4:2:2 frame" and show it in openCV frame size is: 720 * 576 my source code :
void main (int argc, char ** argv) { streampos size; char *pData; ifstream file("C:\639.bin", ios::in | ios::binary | ios::ate);
Mat YUV(576, 720, CV_8UC3);
Mat RGB(576,720, CV_8UC3);
if (file.is_open())
{
size = file.tellg();
pData = new char[size];
file.seekg(0, ios::beg);
file.read(pData, size);
file.close();
long k = 0;
int n = 0;
int Y, Cb, Cr;
for (int i = 0; i < 576; i++)
{
n = 0;
for (int j = 0; j < 1920; j += 16)
{
k = i * 1920 + j;
Y=YUV.at<Vec<uchar, 3>>(Point(n, i))[0] = ((pData[k+1]&252)/4.0 + (pData[k + 2] & 15) * 64)/4.0;
Cb =YUV.at<Vec<uchar, 3>>(Point(n, i))[1] = (pData[k] + (pData[k + 1] & 3) * 256) / 4.0;
Cr =YUV.at<Vec<uchar, 3>>(Point(n, i))[2] = ((pData[k + 2] & 240) / 16 + (pData[k + 3] & 63) * 16) / 4.0;
RGB.at<Vec<uchar, 3>>(Point(n, i))[0] = Y + 1.773*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n, i))[1] = Y - 0.714*(Cr - 128)-0.344*(Cb-128);
RGB.at<Vec<uchar, 3>>(Point(n, i))[2] = Y + 1.403*(Cr - 128);
//-------------------------------------------------------------------------------------------------------
Y=YUV.at<Vec<uchar, 3>>(Point(n + 1, i))[0] = (pData[k + 4] + (pData[k + 5] & 3) * 256)/4.0;
Cb =YUV.at<Vec<uchar, 3>>(Point(n + 1, i))[1] = YUV.at<Vec<uchar, 3>>(Point(n, i))[1];
Cr =YUV.at<Vec<uchar, 3>>(Point(n + 1, i))[2] = YUV.at<Vec<uchar, 3>>(Point(n, i))[2];
RGB.at<Vec<uchar, 3>>(Point(n+1, i))[0] = Y + 1.773*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+1, i))[1] = Y - 0.714*(Cr - 128) - 0.344*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+1, i))[2] = Y + 1.403*(Cr - 128);
//--------------------------------------------------------------------------------------------------------
Y=YUV.at<Vec<uchar, 3>>(Point(n + 2, i))[0] = ((pData[k + 6] & 240) / 16 + (pData[k + 7] & 63) * 16)/4.0;
Cb =YUV.at<Vec<uchar, 3>>(Point(n + 2, i))[1] = ((pData[k + 5] & 252) / 4 + (pData[k + 6] & 15) * 64) / 4.0;
Cr =YUV.at<Vec<uchar, 3>>(Point(n + 2, i))[2] = (pData[k + 8] + (pData[k + 9] & 3) * 256) / 4.0;
RGB.at<Vec<uchar, 3>>(Point(n+2, i))[0] = Y + 1.773*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+2, i))[1] = Y - 0.714*(Cr - 128) - 0.344*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+2, i))[2] = Y + 1.403*(Cr - 128);
//--------------------------------------------------------------------------------------------------------
Y=YUV.at<Vec<uchar, 3>>(Point(n + 3, i))[0] = ((pData[k + 9] & 252) / 4 + (pData[k + 10] & 15) * 64)/4.0;
Cb =YUV.at<Vec<uchar, 3>>(Point(n + 3, i))[1] = YUV.at<Vec<uchar, 3>>(Point(n + 2, i))[1];
Cr =YUV.at<Vec<uchar, 3>>(Point(n + 3, i))[2] = YUV.at<Vec<uchar, 3>>(Point(n + 2, i))[2];
RGB.at<Vec<uchar, 3>>(Point(n+3, i))[0] = Y + 1.773*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+3, i))[1] = Y - 0.714*(Cr - 128) - 0.344*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+3, i))[2] = Y + 1.403*(Cr - 128);
//--------------------------------------------------------------------------------------------------------
Y=YUV.at<Vec<uchar, 3>>(Point(n + 4, i))[0] = (pData[k + 12] + (pData[k + 13] & 3) * 256)/4.0;
Cb =YUV.at<Vec<uchar, 3>>(Point(n + 4, i))[1] = ((pData[k + 10] & 240) / 16 + (pData[k + 11] & 63) * 16) / 4.0;
Cr = YUV.at<Vec<uchar, 3>>(Point(n + 4, i))[2] = ((pData[k + 13] & 252) / 4 + (pData[k + 14] & 15) * 64) / 4.0;
RGB.at<Vec<uchar, 3>>(Point(n+4, i))[0] = Y + 1.773*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+4, i))[1] = Y - 0.714*(Cr - 128) - 0.344*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+4, i))[2] = Y + 1.403*(Cr - 128);
//---------------------------------------------------------------------------------------------------------
Y=YUV.at<Vec<uchar, 3>>(Point(n + 5, i))[0] = ((pData[k + 14] & 240) / 16 + (pData[k + 15] & 63) * 16)/4.0;
Cb = YUV.at<Vec<uchar, 3>>(Point(n + 5, i))[1] = YUV.at<Vec<uchar, 3>>(Point(n + 4, i))[1];
Cr = YUV.at<Vec<uchar, 3>>(Point(n + 5, i))[2] = YUV.at<Vec<uchar, 3>>(Point(n + 4, i))[2];
RGB.at<Vec<uchar, 3>>(Point(n+5, i))[0] = Y + 1.773*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+5, i))[1] = Y - 0.714*(Cr - 128) - 0.344*(Cb - 128);
RGB.at<Vec<uchar, 3>>(Point(n+5, i))[2] = Y + 1.403*(Cr - 128);
//---------------------------------------------------------------------------------------------------------
n = n + 6;
}
}
cvtColor(YUV, RGB, CV_YUV2RGB);
imwrite("C:\\1.jpg", RGB);
namedWindow("1");
imshow("1", RGB);
waitKey(0);
}
}
after run source code following image is shown:
but orginal frame is:
this frame captured from Intensity DeckLink Black MagicDesign Capture Card and Pixel Format is:
please help for solve this problem thanks