help me to read 10 bit YCbCr raw data from file

asked 2016-07-28 13:47:10 -0500

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 ...
(more)
edit retag flag offensive close merge delete

Comments

opencv uses BGR, not RGB (that's why it looks in reverse with imshow)

berak gravatar imageberak ( 2016-07-29 03:12:30 -0500 )edit