import cv2 import numpy as np import operator marge=4 case=28+2*marge taille_grille=9*case methode=cv2.ADAPTIVE_THRESH_GAUSSIAN_C v1=9 cap=cv2.VideoCapture(0) while True: ret, frame=cap.read() gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray=cv2.GaussianBlur(gray, (5, 5), 0) thresh=cv2.adaptiveThreshold(gray, 255, methode, cv2.THRESH_BINARY_INV, v1, 2) #cv2.imshow("thresh", thresh) contours, hierarchy=cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) contour_grille=None maxArea=0 for c in contours: area=cv2.contourArea(c) if area>25000: peri=cv2.arcLength(c, True) polygone=cv2.approxPolyDP(c, 0.01*peri, True) if area>maxArea and len(polygone)==4: contour_grille=polygone maxArea=area if contour_grille is not None: cv2.drawContours(frame, [contour_grille], 0, (0, 255, 0), 2) points=np.vstack(contour_grille).squeeze() points=sorted(points, key=operator.itemgetter(1)) if points[0][0]