I have a simple problem but I dont know it reason
i did draw 2 lines between points x1-y1 and x2-y2 and
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
CodePudding user response:
If you want to draw a triangle pts should be:
pts = np.array([(x1, y1), (x2, y2), (x1, y2)])
CodePudding user response:
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))