简体   繁体   English

在opencv python中绘制多边形的问题

[英]problem for draw polygon in opencv python

I have a simple problem but I dont know it reason我有一个简单的问题,但我不知道原因

i did draw 2 lines between points x1-y1 and x2-y2 and我确实在点 x1-y1 和 x2-y2 之间画了 2 条线和

now i would like draw fill polygon between these points现在我想在这些点之间绘制填充多边形

this is (part of code) for that :这是(代码的一部分):

    for i in range(0, len(reverse_output), 2):
    x1, y1 = reverse_output[i]
    x2, y2 = reverse_output[i + 1]

    x1 = int(x1)
    y1 = int(y1)
    x2 = int(x2)
    y2 = int(y2)
    pts = np.array([(x1, y1), (x2, y2), (x2, y2), (x1, x2)])

    color = [255, 255, 0] if i < 1 else [0, 0, 255]
    cv2.fillPoly(overlay_img, [pts], (255,0,0))
    cv2.line(overlay_img, (x1, y1), (x2, y2), color, 2)

lines can draw good but when i draw polygon between these 2 lines have this problem线条可以画得很好但是当我在这两条线之间画多边形时有这个问题

在此处输入图片说明 i like to draw this blue polygon only between 2 drawn lines i think problem is for (pts) but i could not solve it any help is great thanks我喜欢只在两条绘制的线之间绘制这个蓝色多边形我认为问题是(pts)但我无法解决它任何帮助非常感谢

如果你想画一个三角形pts应该是:

pts = np.array([(x1, y1), (x2, y2), (x1, y2)])

thank you all, i found the solution my self谢谢大家,我自己找到了解决方案

pts1 = (int(reverse_output[0][0]), int(reverse_output[0][1]))
pts2 = (int(reverse_output[1][0]), int(reverse_output[1][1]))
pts3 = (int(reverse_output[2][0]), int(reverse_output[2][1]))
pts4 = (int(reverse_output[3][0]), int(reverse_output[3][1]))

pts = np.array([pts1, pts2, pt3, pts4])

cv2.fillPoly(overlay_img, [pts], (180,0,0))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM