如何通过在opencv python中单击鼠标按钮在正在播放的视频顶部绘制形状

2023-12-02

好吧,首先,我应该承认这是一个相当长的问题,我未能通过谷歌搜索找到可能的解决方案

我有一段视频,其中入侵者试图闯入栅栏的另一边。

enter image description here

我可以追踪入侵者,但是当他在另一边时,我应该能够将入侵持续时间保存到文件中。入侵区域会是这样的

enter image description here

我认为这些步骤:

I. Reading a video file;
II. Getting the very first frame displayed,
  1. Pausing the video playback;
  2. Manually drawing intrusion area on that frame with a mouse; (making draw and reset buttons as events maybe)
  3. Replaying the video again
III. Waiting for the intruder to appear, etc. (III part is not important)

到目前为止,我已经完成了 I 和 II(我知道这很愚蠢),并且应该完成步骤 II 的 1,2,3 个子部分。

import cv2

file  = "intrusion.mp4"
capture = cv2.VideoCapture(file)

ret, firstFrame= capture.read()

while True:
    cv2.imshow("First Frame", firstFrame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cv2.destroyAllWindows()

希望您给予建议和指导!

PS: 参考任何相关的帖子、博客或链接,我很高兴找到答案


添加 cv2.waitKey(0) 将无限期地暂停 while 循环!仅在按下任意键后才会恢复。

我认为您想要实现的是使用背景减法进行对象跟踪。参考这里并看看它是否符合您的要求。

EDIT:

我猜你想徒手画一个入侵区域的形状!这个链接将指导您这样做。我希望这有帮助

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何通过在opencv python中单击鼠标按钮在正在播放的视频顶部绘制形状 的相关文章

随机推荐