通过opencv:ynv420转换为rgb24:scn == 3(dcn == 3&& dcn == 4)

时间:2016-06-21 09:47:22

标签: c++ opencv rgb yuv

  1. 最近我有关于通过opencv将yuv转换为rgb的问题。
  2. 我的系统是win 7 opencv 2.4.10 vs2013。
  3. yuvImg.convertTo(yuvimg_out, CV_16U, (pow(2, 10) - 1) / 255);我想从8位获取10位图像。我不知道它是否有效,因为转换问题。
  4. 以下是我的代码:
  5. 代码:

    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. 当我运行它时,它将是: the bug image is

0 个答案:

没有答案