Python opencv 找包含多个区域的最小外接矩形

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)






Python opencv 找包含多个区域的最小外接矩形_第1张图片

 

你可能感兴趣的:(python,opencv,图像处理,计算机视觉)