import cv2 import numpy as np cap = cv2.VideoCapture(0) while(1): # Take each frame _, frame = cap.read() # Convert BGR to HSV img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) ret,thresh1 = cv2.threshold(img,157,255,cv2.THRESH_BINARY) ret,thresh2 = cv2.threshold(img,137,255,cv2.THRESH_BINARY_INV) ret,thresh3 = cv2.threshold(img,207,255,cv2.THRESH_TRUNC) ret,thresh4 = cv2.threshold(img,77,255,cv2.THRESH_TOZERO) ret,thresh5 = cv2.threshold(img,197,255,cv2.THRESH_TOZERO_INV) cv2.imshow('frame',frame) cv2.imshow('T1',thresh1) cv2.imshow('T2',thresh2) cv2.imshow('T3',thresh3) cv2.imshow('T4',thresh4) cv2.imshow('T5',thresh5) k = cv2.waitKey(5) & 0xFF if k == 27: break cv2.destroyAllWindows()