0
  1. recently i have the problem about converting yuv to rgb by opencv .
  2. my system is win 7 opencv 2.4.10 vs2013.
  3. yuvImg.convertTo(yuvimg_out, CV_16U, (pow(2, 10) - 1) / 255);I want to get the 10bit image from the 8bit. i dont know if it works because of the converting question.
  4. the following is my code:

Code:

int main()
{
    FILE*f;
    if (!(f = fopen("1.yuv", "rb")))
    {
        cout << "file open erro";
    }
    char *savename = "../10bit.yuv";
    FILE *pf = fopen(savename, "wb");

    int width = 1920;
    int height = 1080;
    int frame_count = 0;
    fseek(f, 0, SEEK_END);
    frame_count = (int)((int)ftell(f) / (width * height/3*2));

    unsigned char* yuv_img = new unsigned char[width * height*3/2];

    Mat yuvimg_out(height + height/2, width, CV_16UC1);
    Mat dst;

    char *filename = "1.yuv";
    ifstream readMe(filename, ios::in | ios::binary);

    for (int i = 0; i < frame_count; i++)
    {
        cout << "the num is :" << i << endl;
        readMe.read((char*)yuv_img, (width * height*3/2));
        Mat yuvImg;
        yuvImg.create(height * 3 / 2, width, CV_8UC1);
        memcpy(yuvImg.data, yuv_img, (width * height * 3 / 2)*sizeof(unsigned char));
        yuvImg.convertTo(yuvimg_out, CV_16U, (pow(2, 10) - 1) / 255);
        cvtColor(yuvimg_out, dst, CV_YUV2RGB);
        waitKey();
        //fwrite(yimg_out.data, 1, width*height, pf);
        //fwrite(uimg_out.data, 1, width*height/4, pf);
        //fwrite(vimg_out.data, 1, width*height/4, pf);
    }
    readMe.close();
    waitKey();
    system("pause");
    return 0;
}
  1. when i run it ,it will be: the bug image is
Miki
  • 40,887
  • 13
  • 123
  • 202
zhx
  • 9
  • 4
  • You are defining `yuvImg` as `CV_8UC1` (i.e. single channel), while you want to convert from an image with 3 channels. – Miki Jun 21 '16 at 10:35
  • [link](http://stackoverflow.com/questions/25666120/converting-from-yuv-colour-space-to-rgb-using-opencv) i follow this . – zhx Jun 21 '16 at 10:54

0 Answers0