c++ - How to extend a line segment in open cv using python -
i having 2 end points of line segment , want extend line. found following algorithm through website
lengthab = sqrt((a.x - b.x)^2 + (a.y - b.y)^2) c.x = b.x + (b.x - a.x) / lengthab * length; c.y = b.y + (b.y - a.y) / lengthab * length;
but can't output while implement on program. need int value cx , cy in float.
![ a(x,y)=(200,140) , b(x,y)=(232,146) ][1]
import numpy np import cv2 import math img = np.zeros((500,500,3), np.uint8) lenab = math.sqrt((200-232)**2+(158-146)**2) length = 100 cx = 232 + (232-200) / lenab*length cy = 146 + (146-158) / lenab*length cv2.line(img,(200,158),(cx,cy),(33,322,122),3) cv2.imshow('tha',img) cv2.waitkey(0) cv2.destroyallwindows()
my o/p screen :
traceback (most recent call last): file "e:/nan/inclined_line.py", line 9, in <module> cv2.line(img,(200,158),(cx,cy),(33,322,122),3) typeerror: integer argument expected, got float
from error passing floating point value cv2.line. convert float integer so:
cv2.line(img,(200,158),(int(math.floor(cx)),int(math.floor(cy))),(33,322,122),3)
Comments
Post a Comment