繁体   English   中英

Python OpenCV 获取fitLine的角度方向

[英]Python OpenCV Get Angle Direction of fitLine

使用 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)

拟合线参考:

拟合线文档

打开简历教程

不确定在调试器中为斜率获取哪些项目

在此处输入图像描述

因为你已经有一个单位向量来定义你的线[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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM