目前,我正在尝试使用OpenCV执行运动检测。对于每个新帧,我使用下面的函数与前一帧进行比较:
def detect(new_frame, kernel_size):
frame=cv2.cvtColor(new_frame,cv2.COLOR_BGR2GRAY) #Grayscale conversion of the frame
frame=cv2.GaussianBlur(frame, (kernel_size, kernel_size),0)
deltaFrame=cv2.absdiff(old_frame, frame)
old_frame = frame
threshFrame=cv2.threshold(deltaFrame, 5, 255, cv2.THRESH_BINARY)[1]
threshFrame=cv2.dilate(threshFrame, None, iterations=2)
(cnts,_)=cv2.findContours(threshFrame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
return cnts
我的问题是,我必须检测两种类型的对象的运动,每种类型都有它自己的内核大小参数的有效值(即:5和11)。因此,我必须对每个新帧使用该函数2次。但是我的设备有资源限制,所以我想尽量减少这个过程。我怎么做
在掩码上尝试按位函数。检测每个像素是否移动。很快
对我来说,诀窍是处理小尺寸的帧图像
您可以应用自己的遮罩来检测一个或另一个正在播放模糊值的obj
相关问题 更多 >
编程相关推荐