Python OpenCV获取fitLine的角度方向

2024-06-02 05:30:27 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Python OpenCv,如何通过元素找到fitLine的角度? 我正在尝试使用调试器并查找,因为我在文档中没有看到它

rows,cols = img.shape[:2]
[vx,vy,x,y] = cv2.fitLine(cnt, cv2.DIST_L2,0,0.01,0.01)
lefty = int((-x*vy/vx) + y)
righty = int(((cols-x)*vy/vx)+y)
img = cv2.line(img,(cols-1,righty),(0,lefty),(0,255,0),2)

Fitline参考资料:

Fitline Documentation

Open CV Tutorial

不确定要为调试器中的坡度获取哪些项

enter image description here


Tags: 文档元素imgcv2opencv调试器int角度
1条回答
网友
1楼 · 发布于 2024-06-02 05:30:27

因为已经有一个单位向量定义了线的方向[vx, vy]

[vx,vy,x,y] = cv2.fitLine(cnt, cv2.DIST_L2,0,0.01,0.01)

然后,如果您正在查找您的装配线与;在x轴上,可以使用点积获得角度

import numpy as np

x_axis      = np.array([1, 0])    # unit vector in the same direction as the x axis
your_line   = np.array([vx, vy])  # unit vector in the same direction as your line
dot_product = np.dot(x_axis, your_line)
angle_2_x   = np.arccos(dot_product)

相关问题 更多 >