python结合opencv点击屏幕按钮,如何通过在opencv python中单击鼠标按钮在正在播放的视频上方绘制形状...

Well, to begin with, I should admit that it is a pretty long question and I failed to find possible solutions through googling

I have a video in which an intruder tries to intrude into the other side of the fence.

4d7827883fde709a39a05529dffc544c.png

I can track the intruder, but when he is in the other side, I should be able to save the intrusion duration into a file. The intrusion area would be something like this

a9ccf5b053157223aa7ec219bb7951b1.png

I thought these steps:

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)

So far, I've done I and II (silly, I know) and should accomplish 1,2,3 subparts of step II.

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()

I hope you can give your advice and instructions!

PS: refer to any related posts, blogs or links, I am excited to find out

解决方案

adding cv2.waitKey(0) will pause your while loop indefinitely! It will resume only after any key press.

I think what you're trying to achieve is object tracking using Background Subtraction. Refer Here and see if it fits your requirements.

EDIT:

I guess you want to draw a freehand shape for intrusion area! This Link will guide you to do it. I hope this helps

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值