import numpy as np import cv2 points = [ [ 350, 329 ], [ 347, 332 ], [ 304, 332 ], [ 301, 335 ], [ 301, 2045 ], [ 297, 2049 ], [ 297, 2262 ], [ 301, 2266 ], [ 301, 2371 ], [ 297, 2374 ], [ 297, 3136 ], [ 301, 3140 ], [ 301, 3607 ], [ 304, 3611 ], [ 1611, 3611 ], [ 1614, 3607 ], [ 1689, 3607 ], [ 1692, 3611 ], [ 2563, 3611 ], [ 2566, 3614 ], [ 2591, 3614 ], [ 2594, 3611 ], [ 2597, 3611 ], [ 2600, 3607 ], [ 2600, 3592 ], [ 2597, 3589 ], [ 2597, 3462 ], [ 2600, 3459 ], [ 2600, 1760 ], [ 2603, 1757 ], [ 2603, 1674 ], [ 2600, 1670 ], [ 2600, 1593 ], [ 2603, 1590 ], [ 2603, 335 ], [ 2597, 335 ], [ 2594, 332 ], [ 2572, 332 ], [ 2569, 335 ], [ 2553, 335 ], [ 2550, 332 ], [ 2144, 332 ], [ 2141, 335 ], [ 1872, 335 ], [ 1869, 332 ], [ 1841, 332 ], [ 1838, 335 ], [ 1751, 335 ], [ 1748, 332 ], [ 449, 332 ], [ 446, 329 ] ] points = np.array(points, dtype=np.int32) x, y, w, h = cv2.boundingRect(points) # 2. 构造 4 个顶点坐标 result = np.array([ [x, y], # 左上 [x + w, y], # 右上 [x + w, y + h], # 右下 [x, y + h] # 左下 ], dtype=np.int32).tolist() print(f"Bounding Rect (x,y,w,h): {x}, {y}, {w}, {h}") print(f"Result (4 points):\n{result}")