如何在OpenCV中填充折线? [英] How to fill a polyline in OpenCV?
本文介绍了如何在OpenCV中填充折线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面给出的Python代码绘制了一个三角形,如何在其中填充颜色?还是在OpenCV中绘制三角形的另一种简便方法?
The Python code given below draws a triangle, how can I fill it with a color inside? Or another easier way to draw a triangle in OpenCV?
pts = np.array([[100,350],[165,350],[165,240]], np.int32)
cv2.polylines(img,[pts],True,(0,255,255),2)
推荐答案
您必须使用cv2.fillPoly()
.
将第二行更改为:
cv2.fillPoly(img, [pts], 255)
插图:
img = np.zeros([400, 400],dtype=np.uint8)
pts = np.array([[100,350],[165,350],[165,240]], np.int32)
cv2.fillPoly(img, [pts], 255)
cv2.imshow('Original', img)
结果:
这篇关于如何在OpenCV中填充折线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文