使用OpenCV编写16位视频 [英] Write 16-bit video with OpenCV

查看:369
本文介绍了使用OpenCV编写16位视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许这是显而易见的,但我仍然是新手... ^^"

Maybe this is somehow obvious, but I'm still a newbie... ^^"

我使用OpenCV将一些图像保存到视频文件中.我有16位灰度图像,发现cvWriteFrame仅能处理8位图像.由于我需要稍后在另一种情况下处理视频,并且为此目的我无法承受信息丢失的困扰,因此,我试图找到一种方法来将16位图像保存到视频中.

I use OpenCV to save some images to a video-file. I have 16-bit grayscale images and I found out that cvWriteFrame can only handle 8-bit images. Since I need to process the video later in another context and for that purpose I can't afford the information loss, I'm trying to find a way to save my 16-bit images to videos.

我尝试了文档中的每个CV_FOURCC.但是我不确定这是否真的是编解码器问题.

I tried every CV_FOURCC from this documentation. But I'm not sure if it's really a codec problem.

PS:我知道可以将它们另存为16位图像文件,但是我发现视频解决方案更干净.

PS: I know it's possible to save them as separate 16-bit image-files, but I find the video solution cleaner.

推荐答案

OPencv应该在#12284中支持16位FFMPEG.

OPencv should support 16 bit FFMPEG as part of #12284.

https://github.com/opencv/opencv/pull/12284

Mat frame, frame_split[3];
VideoWriter 8_bit_vid,16_bit_vid;


//for lossless, use 'F''F''V''1', for lossy with good compression, //'X''2''6''4' 

//For 8bit writing

8_bit_vid.open("8_bit_video.avi",('F','F','V','1'),30,[rows,cols],true);

frame_split[0]= Mat Red_channel([rows,cols],CV8_UC1);
frame_split[1]= Mat Green_channel([rows,cols],CV8_UC1);
frame_split[2]= Mat Blue_channel([rows,cols],CV8_UC1);

merge(frame_split,3,frame);

8_bit_vid.write(frame);
8_bit_vid.release();



//For 16bit writing

16_bit_vid.open("16_bit_video.avi",('F','F','V','1'),30,[rows,cols],true);

frame_split[0]= Mat Red_channel([rows,cols],CV16_UC1);
frame_split[1]= Mat Green_channel([rows,cols],CV16_UC1);
frame_split[2]= Mat Blue_channel([rows,cols],CV16_UC1);

merge(frame_split,3,frame);

16_bit_vid.write(frame);
16_bit_vid.release();

希望这会有所帮助

这篇关于使用OpenCV编写16位视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆