OpenCV 中 2 点之间的直线的斜率和长度
Slope and Length of a line between 2 points in OpenCV
我需要比较 2 张图片才能找到其中相似的线条。在这两张照片中,我都使用LSD(线段检测器)方法,然后我找到线,我知道每条线的起点和终点的坐标。
我的问题是:OpenCV中是否有任何功能可以找到每条线的斜率和长度,以便我可以轻松比较它们?
我的环境是:OpenCV 3.1,C++和Visual Studio 2015
嗯
,这是一个数学问题。
假设您有两点:p1(x1,y1)
和 p2(x2,y2)
。让我们p1
称为线段的"起点",p2
线段的"终点",就像您所说的点一样。
斜率 = (y 2 - y 1)/(x2 - x1)长度 = 标准(P2 - p1)
示例代码:
cv::Point p1 = cv::Point(5,0); // "start"
cv::Point p2 = cv::Point(10,0); // "end"
// we know this is a horizontal line, then it should have
// slope = 0 and length = 5. Let's see...
// take care with division by zero caused by vertical lines
double slope = (p2.y - p1.y) / (double)(p2.x - p1.x);
// (0 - 0) / (10 - 5) -> 0/5 -> slope = 0 (that's correct, right?)
double length = cv::norm(p2 - p1);
// p_2 - p_1 = (5, 0)
// norm((0,5)) = sqrt(5^2 + 0^2) = sqrt(25) -> length = 5 (that's correct, right?)
相关文章:
- C++中std::resize(n)和std::shrink_to_fit之间的区别
- int(c) 和 c-'0' 之间的区别。C++
- 在cuda线程之间共享大量常量数据
- 在c代码之间共享数据的最佳方式
- Mix_Init和Mix_OpenAudio SDL之间的区别是什么
- C++ 使用 assign 函数的字符串与直接使用 '=' 更改值的字符串之间的区别
- VSOMEIP-2个设备之间的通信(TCP/UDP)不工作
- std::atomic和std::condition_variable wait,notify_*方法之间的区别
- 大小相等但成员数量不同的结构之间的性能差异
- 类与私有变量的其他类之间的线程安全性
- 如何在cpp文件之间切换窗口?在Qt中
- 线程之间的布尔停止信号
- 我是C++编程的新手,这些代码之间有什么区别,我应该使用哪一个
- 在 const 函数中通过引用和指针返回之间的区别
- 我想知道长双倍和双倍之间的区别
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 在两台机器之间进行时间戳的最佳c++chrono函数是什么
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 构造函数和转换运算符之间的重载解析
- OpenCV 中 2 点之间的直线的斜率和长度