import cv2 import numpy as np # NOT WORCK !!!! def find_contours_of_cards(image): blurred = cv2.GaussianBlur(image, (3, 3), 0) T, thresh_img = cv2.threshold(blurred, 215, 255, cv2.THRESH_BINARY) (cnts, _) = cv2.findContours(thresh_img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) return cnts def find_coordinates_of_cards(cnts, image): cards_coordinates = {} for i in range(0, len(cnts)): x, y, w, h = cv2.boundingRect(cnts[i]) if w > 20 and h > 30: img_crop = image[y - 15:y + h + 15, x - 15:x + w + 15] cards_name = find_features(img_crop) cards_coordinates[cards_name] = (x - 15, y - 15, x + w + 15, y + h + 15) return cards_coordinates cam = cv2.VideoCapture(0) while True: _, frame = cam.read() img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) img = cv2.GaussianBlur(img, (3, 3), 0) # Все больше 215 станет 255, все что меньше 0 T, thresh_img = cv2.threshold(img, 215, 255, cv2.THRESH_BINARY) cv2.imshow("Image", img) cv2.imshow("Image with opening", thresh_img) #cv2.imshow("Image with closing", res) k = cv2.waitKey(2) if k == 27: cv2.destroyAllWindows() break