Opencv how to fill a polyline


Opencv how to fill a polyline



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 Answer
1



You have to use cv2.fillPoly().


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:



enter image description here






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to input without newline? (Python)

C++ thread error: no type named ‘type’ MINGW

Analog for TagView in flutter