yangakw yangakw

运动检测实现交互

in 记录read (59) 文章转载请注明来源!
    import cv2
import numpy as np 

img_pre = None
def Init(cap):
    global img_pre
    while(1): 
        ret, frame = cap.read()
        if (img_pre == None):
            img_pre = frame.copy()
 
        tmp=frame-img_pre
        

        gray = cv2.cvtColor(tmp,cv2.COLOR_BGR2GRAY)
        #gray = cv2.GaussianBlur(gray, (21, 21), 0)#gaussian
        #gray = cv2.medianBlur(gray,6)
        gray = cv2.blur(gray,(100,100))
        ret,edge = cv2.threshold(gray,200,255,cv2.THRESH_BINARY)
        #edge = cv2.Canny(tmp.copy(), 1000, 2000, apertureSize=5)#bianjie
        contours, hierarchy = cv2.findContours(edge.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) #position
        for i in contours:
            x, y, w, h = cv2.boundingRect(i)  
            print x,y
            
        #cv2.imshow("img_pre", img_pre)
        cv2.imshow("frame", tmp)
        cv2.imshow("gray", gray)
        img_pre = frame.copy() 
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break 
    cap.release()
    cv2.destroyAllWindows() 


cap = cv2.VideoCapture(0)
Init(cap)
jrotty WeChat Pay

微信打赏

jrotty Alipay

支付宝打赏

文章二维码

扫描二维码,在手机上阅读!

发表新评论
博客已运行
© 2017 yangakw
PREVIOUS NEXT
雷姆
拉姆