import cv2 import numpy as np import matplotlib.pyplot as plt import math import copy from t2 import RANSAC #xc, yc = 400, 396 path = './CgpbbmO676KAGdMIAAeMtJ1X3Mc346_seg5_pointer.png' pointer = cv2.imread(path) grayImage = cv2.cvtColor(pointer, cv2.COLOR_BGR2GRAY) contours, hierarchy = cv2.findContours(grayImage, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(pointer, contours, -1, (0, 255, 255), 1) #cv2.circle(pointer, (int(xc), int(yc)), 2, (0, 255, 0), 2) contour = [] for cont in contours: contour.extend(cont) min_rect = cv2.minAreaRect(np.array(contour)) print(min_rect) box = cv2.boxPoints(min_rect) box = np.int0(box) print(box) box2 = cv2.drawContours(pointer, [box], 0, [0, 0, 255], 1) cv2.imwrite("./2tout.png", pointer)