求点的最小外接矩
rect1 = cv2.minAreaRect(box):
def back_forward_convert(coordinate, with_label=True): """ :param coordinate: format [x1, y1, x2, y2, x3, y3, x4, y4, (label)] :param with_label: default True :return: format [x_c, y_c, w, h, theta, (label)] """ boxes = [] if with_label: for rect in coordinate: box = np.int0(rect[:-1]) box = box.reshape([4, 2]) rect1 = cv2.minAreaRect(box) x, y, w, h, theta = rect1[0][0], rect1[0][1], rect1[1][0], rect1[1][1], rect1[2] boxes.append([x, y, w, h, theta, rect[-1]]) else: for rect in coordinate: box = np.int0(rect) box = box.reshape([4, 2]) rect1 = cv2.minAreaRect(box) x, y, w, h, theta = rect1[0][0], rect1[0][1], rect1[1][0], rect1[1][1], rect1[2] boxes.append([x, y, w, h, theta]) return np.array(boxes, dtype=np.float32)