- recently i have the problem about converting yuv to rgb by opencv .
- my system is win 7 opencv 2.4.10 vs2013.
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.- 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;
}
- when i run it ,it will be: the bug image is