使用 OpenCV 写入 16 位视频

发布于 2025-01-06 11:04:06 字数 404 浏览 1 评论 0原文

也许这在某种程度上是显而易见的,但我仍然是一个新手... ^^”

我使用 OpenCV 将一些图像保存到视频文件中。我有 16 位灰度图像,我发现 cvWriteFrame 只能处理 8 位图像。由于我需要稍后在另一个上下文中处理视频,为此我无法承受信息丢失,因此我正在尝试找到一种方法将我的 16 位图像保存到 视频。

我尝试了每个 CV_FOURCC 来自文档,但我不确定它是否真的是一个文档。 。

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

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

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.

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

万水千山粽是情ミ 2025-01-13 11:04:06

OPencv 应支持 16 位 FFMPEG 作为 #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 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();

Hope this helps

情释 2025-01-13 11:04:06

自 OpenCV 4.7.0 起,VideoWriter 支持16位灰度视频。

VideoWriter 定义的简短 C++ 示例,带有一些典型参数:

#include <opencv2/videoio.hpp>

cv::VideoWriter video;
Size frameSize = cv::Size(1920, 1080);
double fps = 25.0;
video.open(
    "video.mkv", 
    cv::CAP_FFMPEG, 
    cv::VideoWriter::fourcc('F', 'F', 'V', '1'), 
    fps, 
    frameSize, 
    {
        cv::VideoWriterProperties::VIDEOWRITER_PROP_DEPTH, CV_16UC1, 
        cv::VideoWriterProperties::VIDEOWRITER_PROP_IS_COLOR, false
    }
);

如果您正在寻找具有更多解释的 Python 替代方案,请参阅 这个答案

Since OpenCV 4.7.0, VideoWriter supports 16-bit grayscale videos.

Short C++ example of the VideoWriter definition with some typical parameters:

#include <opencv2/videoio.hpp>

cv::VideoWriter video;
Size frameSize = cv::Size(1920, 1080);
double fps = 25.0;
video.open(
    "video.mkv", 
    cv::CAP_FFMPEG, 
    cv::VideoWriter::fourcc('F', 'F', 'V', '1'), 
    fps, 
    frameSize, 
    {
        cv::VideoWriterProperties::VIDEOWRITER_PROP_DEPTH, CV_16UC1, 
        cv::VideoWriterProperties::VIDEOWRITER_PROP_IS_COLOR, false
    }
);

If you're looking for a Python alternative with a little bit more explanation, see this answer.

坐在坟头思考人生 2025-01-13 11:04:06

我不知道支持 16 位灰度图像的编解码器,但我只使用 OpenCV ffmpeg 支持,所以我可能是错的。 此帖子似乎支持我的理论,即 ffmpeg 不支持 16 位视频(有一条消息表明它支持,但无法访问)。

I am not aware of a codec which supports 16-bit grayscale images, but I only use OpenCV ffmpeg support, so I could be wrong. This thread seems to support my theory that ffmpeg does not do 16-bit video (there is one message stating it does, but is inaccessible).

不可一世的女人 2025-01-13 11:04:06

使用简单的文件 I/O 操作写入未经压缩或格式化的原始图像数据怎么样?我确信这会给你任何你想要的位图像文件:)

How about writing the raw image data without compression or formatting using simple file I/O operations? I'm sure this will give you whatever bits image file you want:)

风铃鹿 2025-01-13 11:04:06

解决方法是同时录制两个 8 位灰度视频。第一个可以使用 16 位数字的前 8 位作为像素,另一个使用最后 8 位。

另一种选择是记录彩色图像,并以类似的方式将蓝色通道设置为前 8 位,将绿色通道设置为最后 8 位。您可以忽略红色通道,或者将其设置为 0。

然后您可以同步播放两个或单色视频,并将它们操纵回原始 16 位视频。

A work around could be to record two 8-bit grayscale videos at the same time. The first one can use the first 8 bits of the 16-bit number as pixels and the other use the last 8 bits.

Another option would be to record a colored image and in a similar fashion set the blue channel to be the first 8-bits and the green channel to the last 8-bits. You can just ignore the red channel maybe set it to 0.

You can then play back the two or single color videos in synch and manipulate them back into your original 16-bit video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文