import numpy as np import cv2 cap = cv2.VideoCapture(0) while(1): ret ,frame = cap.read() if ret == True: img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) ret,thresh1 = cv2.threshold(img,100,255,cv2.THRESH_BINARY) # ret,thresh2 = cv2.threshold(img,127,255,cv2.THRESH_BINARY_INV) # ret,thresh3 = cv2.threshold(img,127,255,cv2.THRESH_TRUNC) # ret,thresh4 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO) # ret,thresh5 = cv2.threshold(img,127,255,cv2.THRESH_TOZERO_INV) th2 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2) th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2) # Otsu's thresholding # blur = cv2.GaussianBlur(img,(5,5),0) # ret2,th6 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) # ret2,th7 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) cv2.imshow('umbral1',thresh1) # cv2.imshow('umbral2',thresh2) # cv2.imshow('umbral3',thresh3) # cv2.imshow('umbral4',thresh4) # cv2.imshow('umbral5',thresh5) # cv2.imshow('Otsu 1',th6) # cv2.imshow('Otsu 2',th7) cv2.imshow('Adaptativo',th2) cv2.imshow('Gausiano',th3) cv2.imshow('original',img) k = cv2.waitKey(60) & 0xff if k == 27: break cv2.destroyAllWindows() cap.release()