#WebcamCounter.py import cv2 threshold = input('Threshold(0<255)? ') cap = cv2.VideoCapture(0) ret, frame1 = cap.read() img1 = cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY) img0 = img1 count = 0 m = 0 n = 0 k = 1 while k <= 6: ret, frame2 = cap.read() img2 = cv2.cvtColor(frame2, cv2.COLOR_BGR2GRAY) if m == 300: # cv2.imshow('frame-10sec', img1) m = 0 for a in range(60, 419): for b in range(80, 559): px = img1[a, b] # print(px) if px > int(threshold): # print(px) count += 1 print('CP10/3S= ' + str(count)) k += 1 count = 0 img1 = img0 if n == 3: n = 0 img = img1 + img2 img1 = img m += 1 n += 1 cap.release()