# Obtener la orientacion de los contornos y quedarnos con aquellos especificados en un rango import numpy as np import cv2 import time cap = cv2.VideoCapture(0) def orientacionContorno(contornos): mayor=0 i=0 for cont in contornos: if len(cont) > 5: (x,y),(MA,ma),angle = cv2.fitEllipse(cont) if abs(MA - ma) > 15 and abs(MA - ma) < 20: mayor=i print i, angle,MA,ma 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_GAUSSIAN_C, cv2.THRESH_BINARY,11,2) contours,hierarchy = cv2.findContours(It, 1, 2) mayor = orientacionContorno(contours) ellipse = cv2.fitEllipse(contours[mayor]) cv2.ellipse(img,ellipse,(0,255,0),2) # 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()