OpenCV显示图像比视频更苍白

发布于 2025-01-17 11:15:13 字数 1131 浏览 6 评论 0原文

我有一个Python代码,在那里我将图像加载到窗口中,然后用不同的视频覆盖它。 确切地说,视频的图像和第一帧是相同的,我从第一个视频中提取了一个带有shotcut的位置的框架,并使用框架将其融合到每个视频中。但是,当视频启动时,颜色总是有所增加。我首先认为这可能是.jpg压缩的问题,但这不可能是,因为我使用.jpg文件在第一个视频(使用视频编辑软件编辑)之外的所有内容中进行混合,而且颜色总是有变化。我的动画和第一帧也与JPG相同,但在此视频中几乎看不到它。但是,由于数据隐私,我无法上传视频,但这是图像: “视频帧”

差异几乎看不见,但是我在鼻子的某个地方(右侧,什么都没有改变),正如您在底部所看到的,它显示了RGB值,即使我没有移动鼠标,r和g也增加了,而b也减少了。 我的python代码:

#Imports    
img = cv2.imread(path + "name.jpg")
cv2.imshow("Image", img)
cv2.waitKey(20)
vid = cv2.VideoCapture(path + "vid.mp4")
while True:
     ret, frame = self.vid.read()
     if ret:
        cv2.imshow("Image", frame)
        cv2.waitKey(20)
     else:
        vid.release()
        break

在这种情况下,它不是那么严重,但是与真实人的视频更为红色,因此红色的增加显然是可见的。 我确定它们是相同的帧,因为在发送任何命令以启动视频并在视频末尾制作屏幕截图之前,我已经制作了屏幕截图(该视频包含回到JPG)。 视频为.mp4,编码在H.264视频流中。

I have a python code, where I load an image into a window and later overwrite it with different videos.
The image and the first frame of the videos is the same, to be exact, I extracted the frame from position one from the first video with Shotcut and used the frame to blend over into each video. However there is always a jump in coloring when the video starts. I first thought it might be an issue of .jpg compression, but this cannot be, since I used the .jpg file for blending in all but the first video (edited them with a video editing software) and there always is a shift in color. I have the same effect with a rendered animation and the first frame as a jpg from such as well, but it is barely visible with this video. However, due to data privacy, I can't upload the videos, but here are the images:
ImageVideo Frame

The difference is barely visible, but I had my mouse somewhere at the nose (on the right side, where nothing changed) and as you can see at the bottom, where it shows the RGB values, even though I didn't move the mouse, R and G increased, while B decreased.
My python code:

#Imports    
img = cv2.imread(path + "name.jpg")
cv2.imshow("Image", img)
cv2.waitKey(20)
vid = cv2.VideoCapture(path + "vid.mp4")
while True:
     ret, frame = self.vid.read()
     if ret:
        cv2.imshow("Image", frame)
        cv2.waitKey(20)
     else:
        vid.release()
        break

In this case it is not so serious, but the video with the real person has a lot more reddish, so the increase in red is clearly visible.
I am sure they are the same frames, for I have made a screenshot before sending any command to start the video and made a screenshot at the end of the video (the video contains a blend over back to the jpg).
The videos are .mp4, encoded in H.264 video stream.

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

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

发布评论

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

评论(1

怪我鬧 2025-01-24 11:15:13

因此,显然这确实是OpenCV中的一个错误,Rotem在评论中如何指出。
可以在

So, apparently this is indeed a bug in OpenCV, how Rotem pointed out in the comments.
A work-around can be found in this post with GStream, though it brings some down-sides. (As mentioned in the comments GStream is not appropriate for not streamed videos.) The compression of the video might also need to be considered.

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