问题
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