import numpy as np import cv2 import time cap = cv2.VideoCapture(0) def mayorContorno(contornos): mayor=0;puntosmax=0;i=0 for cont in contornos: # print puntosmax, len(cont) if puntosmax < len(cont): mayor = i puntosmax=len(cont) i = i + 1 return mayor while(True): # Capture frame-by-frame ret, img = cap.read() It = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) It = cv2.adaptiveThreshold(It,255,cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV,7,2) contours,hierarchy = cv2.findContours(It, 1, 2) mayor = mayorContorno(contours) cv2.drawContours(img, contours[mayor], -1, (0,255,0), 1) hull = cv2.convexHull(contours[mayor]) print hull[0], hull[len(hull)-1] cv2.drawContours(img, [hull], -1, (255,0,0), 3) # Display the resulting frame cv2.imshow('Imagen en tiempo t',img) cv2.imshow('Imagen contonrnos',It) if cv2.waitKey(1) & 0xFF == ord('q'): break # When everything done, release the capture cap.release() cv2.destroyAllWindows()