图像上划凸多边形(convexHull()函数)

import numpy as np
import cv2 as cv
img=np.zeros((400,410),np.uint8)
points=np.random.randint(100,400,(20,2),np.int32)
c = cv.convexHull(points) # 此函数包含所有points点,且为3维矩阵【n,1,2】
print(c.shape)
# print(c)

for i in range(c.shape[0]-1):
cv.line(img,(c[i,0,0],c[i,0,1]),(c[i+1,0,0],c[i+1,0,1]),255,3)
cv.line(img,(c[c.shape[0]-1,0,0],c[c.shape[0]-1,0,1] ),(c[0,0,0],c[0,0,1] ),255,3)
cv.imshow('img',img)
cv.waitKey()
cv.destroyAllWindows()

 

 

 

posted @ 2019-10-21 23:18  tangjunjun  阅读(937)  评论(0编辑  收藏  举报
https://rpc.cnblogs.com/metaweblog/tangjunjun