我想检测视频中的动态对象,但是上限似乎没有阅读视频。我使用conda jupyter并使用brew安装ffmpeg并使用macOS。不过,我无法捕捉视频。
import numpy as np
import cv2
import time
cap = cv2.VideoCapture('test.avi')
time.sleep(2)
fgbg = cv2.createBackgroundSubtractorKNN(detectShadows=True)
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
cv2.imshow('original',frame)
cv2.imshow('fg',fgmask)
k = cv2.waitKey(30) & 0xff
for c in contours:
# 获取矩形框边界坐标
x, y, w, h = cv2.boundingRect(c)
# 计算矩形框的面积
area = cv2.contourArea(c)
if 500 < area < 3000:
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
cv2.imshow("detection", frame)
cv2.imshow("back", dilated)
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
无法从文件&#34; test.avi&#34;
读取视频流