def extract_corners(self, image):
"""
Find the 4 corners of a binary image
:param image: binary image
:return: 4 main vertices or None
"""
cnts, _ = cv2.findContours(image.copy(),
cv2.RETR_EXTERNAL,
cv2.CHAIN_APPROX_SIMPLE)[-2:]
cnt = cnts[0]
_, _, h, w = cv2.boundingRect(cnt)
epsilon = min(h, w) * 0.5
vertices = cv2.approxPolyDP(cnt, epsilon, True)
vertices = cv2.convexHull(vertices, clockwise=True)
vertices = self.correct_vertices(vertices)
return vertices
评论列表
文章目录