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) res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC) ret,th1 = cv2.threshold(res,127,255,cv2.THRESH_BINARY) th2 = cv2.adaptiveThreshold(res,255,cv2.ADAPTIVE_THRESH_MEAN_C,\ cv2.THRESH_BINARY,11,2) th3 = cv2.adaptiveThreshold(res,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv2.THRESH_BINARY,11,2) ret3,th4 = cv2.threshold(res,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) cv2.imshow('frame',frame) cv2.imshow('T1',th1) cv2.imshow('T2',th2) cv2.imshow('T3',th3) cv2.imshow('T4',th4) k = cv2.waitKey(5) & 0xFF if k == 27: break cv2.destroyAllWindows()