【发布时间】:2016-02-28 19:16:48
【问题描述】:
我正在尝试做帧差异这是我下面的代码
import numpy as np
import cv2
current_frame =cv2.VideoCapture(0)
previous_frame=current_frame
while(current_frame.isOpened()):
current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
previous_frame_gray= cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)
frame_diff=cv2.absdiff(current_frame_gray,previous_frame_gray)
cv2.imshow('frame diff ',frame_diff)
cv2.waitKey(1)
current_frame.copyto(previous_frame)
ret, current_frame = current_frame.read()
current_frame.release()
cv2.destroyAllWindows()
我的问题是我试图创建空帧来保存 current_frame 的第一帧
previous_frame=np.zeros(current_frame.shape,dtype=current_frame.dtype)
但我认为这是不正确的,然后我尝试像这样传递 current_frame:
previous_frame=current_frame
现在我收到此错误:
current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY) TypeError: src 不是 numpy 数组,也不是标量
那我该怎么办呢?
感谢您的帮助
【问题讨论】: