无法在python和opencv中计算运动

时间:2014-04-24 19:21:35

标签: python opencv

我试图检测动作并获得仅改变像素的彩色图像

我认为下面的方法应该有效,但输出不准确

import numpy as np
import cv2
cap = cv2.VideoCapture(0)
ret, prevframe = cap.read() #Motion Detection
while not(cv2.waitKey(1000) & 0xFF == ord('q')):
    # Capture frame-by-frame
    ret, frame = cap.read() # get frame
    gray1 = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)#convert frame to grayscale
    gray2 = cv2.cvtColor(prevframe, cv2.COLOR_BGR2GRAY) #convert other frame
    z = ~(gray1 == gray2) # get which pixels has been changed

    #keep the pixels that are changed
    out = frame * ([[[b,b,b] for b in i] for i in z] * 1) 
    cv2.imshow("test",out)    
    prevframe = frame
cap.release()
cv2.destroyAllWindows() 

我如何才能准确 我试图用计数器,阈值处理,guassianblur等来检测运动。

由于

0 个答案:

没有答案