yuvImg.convertTo(yuvimg_out, CV_16U, (pow(2, 10) - 1) / 255);
我想从8位获取10位图像。我不知道它是否有效,因为转换问题。代码:
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;
}