使用 OpenCV 写入 16 位视频
也许这在某种程度上是显而易见的,但我仍然是一个新手... ^^”
我使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
OPencv 应支持 16 位 FFMPEG 作为 #12284 的一部分。
帮助
希望这有
OPencv should support 16 bit FFMPEG as part of #12284.
https://github.com/opencv/opencv/pull/12284
Hope this helps
自 OpenCV 4.7.0 起,
VideoWriter
支持16位灰度视频。VideoWriter 定义的简短 C++ 示例,带有一些典型参数:
如果您正在寻找具有更多解释的 Python 替代方案,请参阅 这个答案。
Since OpenCV 4.7.0,
VideoWriter
supports 16-bit grayscale videos.Short C++ example of the VideoWriter definition with some typical parameters:
If you're looking for a Python alternative with a little bit more explanation, see this answer.
我不知道支持 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 thatffmpeg
does not do 16-bit video (there is one message stating it does, but is inaccessible).使用简单的文件 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:)
解决方法是同时录制两个 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.