import numpy as np import argparse import cv2 def searchReferencePointCorner(image): height = image.shape[0] width = image.shape[1] # Obróbka graficzna dla wyostrzenia konturów edged = cv2.Canny(image, 20, 200) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) thresh = cv2.threshold(edged, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1] # Szukanie konturów oraz koordynatów punktu odniesienia threshold_max_area = 60000 threshold_min_area = 20000 cnts = cv2.findContours(edged, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cnts = cnts[0] if len(cnts) == 2 else cnts[1] for c in cnts: peri = cv2.arcLength(c, True) approx = cv2.approxPolyDP(c, 0.035 * peri, True) x, y, w, h = cv2.boundingRect(approx) aspect_ratio = w / float(h) area = cv2.contourArea(c) if len(approx) == 4 and area < threshold_max_area and area > threshold_min_area and (aspect_ratio >= 0.9 and aspect_ratio <= 1.1): # Prawy górny róg if x > width * 0.80 and y < height * 0.20: cv2.rectangle(image, (x, y), (x + w, y + h), (36, 255, 12), 2) return image, x, y