import cv2
import numpy as np
# 创建空白图像
img = np.ones((500, 500, 3), dtype=np.uint8) * 255 # 白色背景
# 定义一组随机点(示例数据)
points = np.array([
[100, 100], [200, 50],
# [350, 250], [250, 300], [150, 250],
# [50, 200]
], dtype=np.int32)
# 计算凸包
hull = cv2.convexHull(points)
# 绘制凸包(使用抗锯齿)
cv2.polylines(img, [hull], isClosed=True, color=(0, 0, 255), thickness=2, lineType=cv2.LINE_AA)
# # 绘制原始点
# for p in points:
# cv2.circle(img, tuple(p), 5, (0, 255, 0), -1)
# 显示结果
cv2.imshow('Convex Hull with Antialiasing', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
06-11
5160
