import cv2 import numpy as np import tensorflow as tf import sudoku_solver as ss from time import sleep import operator marge=4 case=28+2*marge taille_grille=9*case flag=0 cap=cv2.VideoCapture(0) with tf.Session() as s: saver=tf.train.import_meta_graph('./mon_modele/modele.meta') saver.restore(s, tf.train.latest_checkpoint('./mon_modele/')) graph=tf.get_default_graph() images=graph.get_tensor_by_name("entree:0") sortie=graph.get_tensor_by_name("sortie:0") is_training=graph.get_tensor_by_name("is_training:0") maxArea=0 while True: ret, frame=cap.read() if maxArea==0: cv2.imshow("frame", frame) gray=cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) gray=cv2.GaussianBlur(gray, (5, 5), 0) thresh=cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY_INV, 9, 2) 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.02*peri, True) if area>maxArea and len(polygone)==4: contour_grille=polygone maxArea=area if contour_grille is not None: points=np.vstack(contour_grille).squeeze() points=sorted(points, key=operator.itemgetter(1)) if points[0][0]