四边形顶点排序

四边形顶点排序算法

将四边形顶点按照一定的算法进行排序
顺时针顺序进行排序
预先得到四个点的坐标或者没有也行,通过opencv画出矩形框并使用opencv自带的算法进行多边形取点,取完点之后 findCounters所得到的坐标点是逆时针排序的,所以如果使用顺时针进行排序则需要进一步对点进行处理

label=[x1,y1,x2,y2,x3,y3,x4,y4]
points = [label[0],label[1],label[2],label[3],label[4],label[5],label[6],label[7]]
points = list(map(int,points))
max_x=max(int(label[0]),int(label[0]),int(label[4]),int(label[6]))+100
max_y=max(int(label[1]),int(label[3]),int(label[5]),int(label[7]))+100
mask=np.zeros((max_y,max_x,3)).astype(np.uint8)
points_1=list(map(int,[label[0],label[1],label[2],label[3],label[6],label[7],label[4],label[5]]))
points_2=list(map(int,[label[0],label[n1],label[4],label[5],label[2],label[3],label[6],label[7]]))
points_3=list(map(int,[label[0],label[1],label[4],label[5],label[6],label[7],label[2],label[3]]))
points_4=list(map(int,[label[0],label[1],label[6],label[7],label[2],label[3],label[4],label[5]]))
points_5=list(map(int,[label[0],label[1],label[6],label[7],label[n4],label[5],label[2],label[3]]))
points = np.int32(points).reshape(4, 2)
points_1 = np.int32(points_1).reshape(4, 2)
points_2 = np.int32(points_2).reshape(4, 2)
points_3 = np.int32(points_3).reshape(4, 2)
points_4 = np.int32(points_4).reshape(4, 2)
points_5 = np.int32(points_5).reshape(4, 2)
cv2.fillPoly(mask, [points], (255,255,255))
cv2.fillPoly(mask, [points_1], (255, 255, 255))
cv2.fillPoly(mask, [points_2], (255,255,255))
cv2.fillPoly(mask, [points_3], (255,255,255))
cv2.fillPoly(mask, [points_4], (255,255,255))
cv2.fillPoly(mask, [points_5], (255,255,255))
mask=cv2.cvtColor(mask,cv2.COLOR_RGB2GRAY)
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = cv2.approxPolyDP(contours[0], 5, True)
contours=sort_contours(contours)
print(contours)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值