Get超炫技能:如何使用 Python 执行运动检测?

To find the changes creating a GaussianBlur from the gray scale image

gray_frame = cv2.GaussianBlur(gray_image, (21, 21), 0)

For the first iteration checking the condition

we will assign grayFrame to initalState if is none

if initialState is None:

   initialState = gray_frame  

   continue  

Calculation of difference between static or initial and gray frame we created

differ_frame = cv2.absdiff(initialState, gray_frame)

the change between static or initial background and current gray frame are highlighted

thresh_frame = cv2.threshold(differ_frame, 30, 255, cv2.THRESH_BINARY)[1]

thresh_frame = cv2.dilate(thresh_frame, None, iterations = 2)

For the moving object in the frame finding the coutours

cont,_ = cv2.findContours(thresh_frame.copy(),

                  cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)  

for cur in cont:

   if cv2.contourArea(cur) < 10000:  

       continue  

   var_motion = 1  

   (cur_x, cur_y,cur_w, cur_h) = cv2.boundingRect(cur)  

   

   # To create a rectangle of green color around the moving object 

   cv2.rectangle(cur_frame, (cur_x, cur_y), (cur_x + cur_w, cur_y + cur_h), (0, 255, 0), 3)  

from the frame adding the motion status

motionTrackList.append(var_motion)

motionTrackList = motionTrackList[-2:]

Adding the Start time of the motion

if motionTrackList[-1] == 1 and motionTrackList[-2] == 0:

   motionTime.append(datetime.now())  

Adding the End time of the motion

if motionTrackList[-1] == 0 and motionTrackList[-2] == 1:

   motionTime.append(datetime.now())  

In the gray scale displaying the captured image

cv2.imshow("The image captured in the Gray Frame is shown below: ", gray_frame)

To display the difference between inital static frame and the current frame

cv2.imshow(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值