gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:50:00 24 4
gpt4 key购买 nike

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

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

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 循环!只有在按下任何按键后才会恢复。

我认为您要实现的目标是使用背景减除进行对象跟踪。 Refer Here看看它是否符合您的要求。

编辑:

我猜你想徒手画一个入侵区域的形状! This Link会指导你去做。希望对您有所帮助

关于python - 如何通过在opencv python中单击鼠标按钮在播放视频的顶部绘制形状,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54125451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com