【发布时间】:2015-01-25 14:55:38
【问题描述】:
我有一个线段的两个端点,我想延长线。 我通过这个网站找到了以下算法
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;
但是我在我的程序上实现它时无法获得输出。我需要 int 值,但 cx 和 cy 是浮点数。
![ a(x,y)=(200,140) , b(x,y)=(232,146) ][1]
import numpy as 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()
我的 o/p 屏幕:
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
【问题讨论】:
标签: python c++ algorithm python-2.7 opencv