Opencv how to fill a polyline

偶尔善良 提交于 2020-01-14 09:20:10

问题


the python code given below draws a triangle, how can I fill inside? Or other 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)

回答1:


You have to use cv2.fillPoly().

Change the second line to:

cv2.fillPoly(img, [pts], 255)

Illustration:

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)

Result:



来源:https://stackoverflow.com/questions/51121978/opencv-how-to-fill-a-polyline

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!