问题描述
我的代码有问题。我不知道可以将cv.resize()
放在哪里以获取需求解决方案。我要更改它,因为我上传的文件是全高清分辨率,并且我想获得较小的分辨率。我将为解决方案和解释感到高兴。
import cv2
import numpy as np
cap = cv2.VideoCapture('DJI_0037.MP4')
while cap.isOpened():
ret,frame = cap.read()
if ret == True:
frame_resize = cv2.resize(frame,(640,480),interpolation=cv2.INTER_CUBIC)
else:
break
ret,frame_resize1 = cap.read(frame_resize)
ret,frame_resize2 = cap.read(frame_resize)
diff = cv2.absdiff(frame_resize1,frame_resize2)
gray = cv2.cvtColor(diff,cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray,(5,5),0)
_,thresh = cv2.threshold(blur,20,255,cv2.THRESH_BINARY)
dilated = cv2.dilate(thresh,None,iterations=3)
contours,_ = cv2.findContours(dilated,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for contour in contours:
(x,y,w,h) = cv2.boundingRect(contour)
if cv2.contourArea(contour) < 2000:
continue
cv2.rectangle(frame_resize1,(x,y),(x + w,y + h),(0,0),2)
cv2.putText(frame_resize1,"Status: {}".format('Movement'),(10,20),cv2.FONT_HERShey_SIMPLEX,1,255),3)
cv2.imshow("Feed",frame_resize1)
frame_resize1 = frame_resize2
ret,frame_resize2 = cap.read()
if cv2.waitKey(40) == 27:
break
cap.release()
cv2.destroyAllWindows()
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)