python 多边形越界
import mathimport numpy as np
import cv2# 裁剪多边形顶点使其位于图像内部
def clip_polygon_to_image(poly_a, image_shape):h, w = image_shape[:2] # 获取图像的宽度和高度clipped_polygon = []for point in poly_a:# 限制x和y坐标在图像范围内x = min(max(point[0], 0), w - 1)y = min(max(point[1], 0), h - 1)clipped_polygon.append([x, y])return clipped_polygon# 顺时针排序多边形顶点
def sort_polygon_clockwise(poly_a):# 计算多边形的中心点center_x = sum([point[0] for point in poly_a]) / len(poly_a)center_y = sum([point[1] for point in poly_a]) / len(poly_a)# 计算每个点相对于中心点的角度,并按顺时针顺序排序def angle_from_center(point):return math.atan2(point[1] - center_y, point[