#if(cam.isOpened()==False): # print("cam isnt opened") # exit() i=[None,None,None] flag=False for n in range(3): i[n]=motion.getGrayCamImg(cam) checkFlag=0 while True: diff=motion.diffImage(i) thrimg=cv2.threshold(diff,thresh,1,cv2.THRESH_BINARY)[1] count=cv2.countNonZero(thrimg) #if invader is checked. print(count) if count>1: checkFlag+=1 if checkFlag>=10 and flag==False: sendMail(i[2]) flag=True print("invader is coming!!!") elif count==0 and flag==True: flag=False checkFlag=0 # process next image motion.updateCameraImage(cam, i) key = cv2.waitKey(10) if key == 27: break
cam.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 240) if cam.isOpened() == False: print "Cam isn't opened" exit() i = [None, None, None] for n in range(3): i[n] = motion.getGrayCameraImage(cam) flag = False checkFlag = 0 while True: diff = motion.diffImage(i) ret,thrimg=cv2.threshold(diff, thresh, 1, cv2.THRESH_BINARY) count = cv2.countNonZero(thrimg) # if invader is checked if (count > 1): checkFlag += 1 if checkFlag >= 10 and flag == False: sendmail(i[2]) flag = True print "Invader is coming!" elif count == 0 and flag == True: flag = False checkFlag = 0 # process next image motion.updateCameraImage(cam, i) key = cv2.waitKey(10) if key == 27: break