python - 在OpenCV中获得两点之间的直线方程
问题描述
我在图像中有两个点,比如说 (30, 220) 和 (1385, 1050)。我想找到通过这两点的方程。我可以在 python 中与 OpenCV 的库划清界限。
cv.line(frame, (30, 220), (1385, 1050), (0, 255, 0), thickness=3, lineType=8)
PS。 我的最终目标是计算一个点和那条线之间的最短距离。
解决方案
在这里我如何找到它:
from numpy import ones,vstack
from numpy.linalg import lstsq
import math
points = [(30, 220),(1385, 1050)]
x_coords, y_coords = zip(*points)
A = vstack([x_coords,ones(len(x_coords))]).T
m, c = lstsq(A, y_coords)[0]
print("Line Solution is y = {m}x + {c}".format(m=m,c=c))
推荐阅读
- c# - Response.TransmitFile 在 mvc 5 中不起作用
- ios - 获取 naturalSize 和列表分辨率视频 m3u8
- javascript - 单击汉堡包图标时,粘性导航栏没有完全响应
- artificial-intelligence - 为什么使用非复杂算法
- javascript - html5画布比例与增加画布尺寸以进行缩放有什么区别?
- html - 在窗口重新调整大小时居中重叠图像
- hl7-fhir - 无法从批量 API 调用中获取数据
- scala - 如何在 Windows 的 spark-shell 中导入 play 框架 jar?
- java - Java Gas Station 项目编码烦恼
- c# - ASP.NET Web Api 2 在异常时自动添加标头