OpenCV - VideoWriter 生成带有“重复”视频的视频图像

发布于 2024-09-06 13:45:55 字数 607 浏览 7 评论 0原文

我正在尝试在 OpenCV 中处理一对视频文件中的每一帧,然后将生成的帧写入输出 avi 文件。一切正常,除了输出视频文件看起来很奇怪:该图像不是一张实心图像,而是重复三次并水平压缩,以便所有三个副本都适合窗口。我怀疑作者期望的通道数量出了问题,但我给了它 8 位单通道图像来写入。以下是我初始化视频编写器的设置:

  //Initialize the video writer
  CvVideoWriter *writer = cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'), 30, frame_sizeL, 0);

以前有人遇到过 openCV 视频编写器的这种奇怪的输出吗?我一直在使用 cvSaveImage 检查生成的帧,只是为了看看我的处理步骤是否正在创建“三重”图像,但事实并非如此。只有当我使用 cvWriteFrame 写入输出 avi 时,图像才会“增加三倍”并被压缩。

编辑:所以我发现只有当我尝试使用写入框架写入单通道图像时才会发生这种情况。如果我写入 3 通道 8 位 RGB 图像,输出视频效果很好。它为什么要这样做?在初始化 CvVideoWriter 时,我正确地为颜色参数传递了“0”,因此它应该期待单通道图像。

I'm trying to process each frame in a pair of video files in OpenCV and then write the resulting frames to an output avi file. Everything works, except that the output video file looks strange: instead of one solid image, the image is repeated three times and horizontally compressed so all three copies fit into the window. I suspect there is something going wrong with the number of channels the writer is expecting, but I'm giving it 8-bit single channel images to write. Below are the setting with which I'm initializing my videowriter:

  //Initialize the video writer
  CvVideoWriter *writer = cvCreateVideoWriter("out.avi",CV_FOURCC('D','I','V','X'), 30, frame_sizeL, 0);

Has anyone encountered this strange output from the openCV videowriter before? I've been checking the resulting frames with cvSaveImage just to see if somehow my processing step is creating the "tripled" image, but it's not. It's only when I write to the output avi with cvWriteFrame that the image gets "tripled" and compressed.

Edit: So I've discovered that this only happens when I attempt to write single channel images using write frame. If I write 3 channel 8-bit RGB images, the output video turns out fine. Why is it doing this? I am correctly passing "0" for the color argument when initializing the CvVideoWriter, so it should be expecting single channel images.

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

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

发布评论

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

评论(1

为你拒绝所有暧昧 2024-09-13 13:45:55

在 C++ 版本中,您必须通过设置最后一个参数“false”来告诉 cv::VideoWriter 您正在发送单通道图像,您确定要这样做吗?

编辑:或者,您可以使用 cvtColor( ) 和 CV_GRAY2RGB

In the C++ version you have to tell cv::VideoWriter that you are sending a single channel image by setting the last paramter "false", are you sure you are doing this?

edit: alternatively you can convert a greyscale image to color using cvtColor() and CV_GRAY2RGB

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