cv::fitLine用法
cv::fitLine用法
- 定义
- 代码示例
- y = x + 1直线
- y = -x + 1直线
定义
在opencv官方文档定义如下:
void cv::fitLine(InputArray points,
OutputArray line,
int distType,
double param,
double reps,
double aeps
)#include <opencv2/imgproc.hpp>
Fits a line to a 2D or 3D point set.Parameters
points Input vector of 2D or 3D points, stored in std::vector<> or Mat.
line Output line parameters. In case of 2D fitting, it should be a vector of 4 elements (like Vec4f) - (vx, vy, x0, y0), where (vx, vy) is a normalized vector collinear to the line and (x0, y0) is a point on the line. In case of 3D fitting, it should be a vector of 6 elements (like Vec6f) - (vx, vy, vz, x0, y0, z0), where (vx, vy, vz) is a normalized vector collinear to the line and (x0, y0, z0) is a point on the line.
distType Distance used by the M-estimator, see DistanceTypes
param Numerical parameter ( C ) for some types of distances. If it is 0, an optimal value is chosen.
reps Sufficient accuracy for the radius (distance between the coordinate origin and the line).
aeps Sufficient accuracy for the angle. 0.01 would be a good default value for reps and aeps.
代码示例
简而言之,就是利用已有的点拟合直线,本篇只针对使用做简单示例,基于opencv3.4.5, C++;
主要介绍输出参数,
- OutputArray line:在二维下为四个元素,前两个为向量(x, y),后两个为拟合直线上的一个点
- distType,参考如下:
//! @see distanceTransform, fitLine enum DistanceTypes {DIST_USER = -1, //!< User defined distanceDIST_L1 = 1, //!< distance = |x1-x2| + |y1-y2|DIST_L2 = 2, //!< the simple euclidean distanceDIST_C = 3, //!< distance = max(|x1-x2|,|y1-y2|)DIST_L12 = 4, //!< L1-L2 metric: distance = 2(sqrt(1+x*x/2) - 1))DIST_FAIR = 5, //!< distance = c^2(|x|/c-log(1+|x|/c)), c = 1.3998DIST_WELSCH = 6, //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846DIST_HUBER = 7 //!< distance = |x|<c ? x^2/2 : c(|x|-c/2), c=1.345 };
- param: 默认0,opencv自动优化
- reps:0.01精度即可
- aeps:建议0.01,0.01 would be a good default value…
y = x + 1直线
向量(0.707107,0.707107)如图下
设直线为 y = ax + b, a = 1 , b = 1
则 y = x + 1,部分代码:
std::vector<cv::Point2f> input_pts;input_pts.emplace_back(1, 2);input_pts.emplace_back(2, 3);cv::Vec4f calc_line;cv::fitLine(input_pts, calc_line, cv::DIST_L2, 0, 0.01, 0.01);std::cout << "calc_line[0]=" << calc_line[0]<< "\ncalc_line[0]=" << calc_line[1]<< "\ncalc_line[0]=" << calc_line[2]<< "\ncalc_line[0]=" << calc_line[3] << std::endl;
控制台输出
calc_line[0]=0.707107
calc_line[0]=0.707107
calc_line[0]=1.5
calc_line[0]=2.5
y = -x + 1直线
向量(0.707107,-0.707107)
设直线为 y = ax + b, a = -1 , b = 1
则 y = -x + 1,部分代码:
std::vector<cv::Point2f> input_pts;input_pts.emplace_back(1, 2);input_pts.emplace_back(2, 1);cv::Vec4f calc_line;cv::fitLine(input_pts, calc_line, cv::DIST_L2, 0, 0.01, 0.01);std::cout << "calc_line[0]=" << calc_line[0]<< "\ncalc_line[0]=" << calc_line[1]<< "\ncalc_line[0]=" << calc_line[2]<< "\ncalc_line[0]=" << calc_line[3] << std::endl;
calc_line[0]=0.707107
calc_line[0]=-0.707107
calc_line[0]=1.5
calc_line[0]=1.5
Enjoy~
cv::fitLine用法相关推荐
- 【OpenCV3】直线拟合——cv::fitLine()详解
在图像处理中,通常会遇到根据给定的点集(比如轮廓)拟合出一条直线的情形.opencv2和opencv3中提供了一个专门用于直线拟合的函数--cv::fitLine(). 下面对该函数作一详细的介绍. ...
- OpenCV cv::split用法的实例(附完整代码)
OpenCV cv::split用法的实例 OpenCV cv::split用法的实例 OpenCV cv::split用法的实例 #include <iostream> #include ...
- OpenCV cv::reduce用法的实例(附完整代码)
OpenCV cv::reduce用法的实例 OpenCV cv::reduce用法的实例 OpenCV cv::reduce用法的实例 #include <iostream> #incl ...
- OpenCV cv::merge用法的实例(附完整代码)
OpenCV cv::merge用法的实例 OpenCV cv::merge用法的实例 OpenCV cv::merge用法的实例 #include <iostream> #include ...
- opencv-python 中直线拟合函数cv.fitLine()的2D直线拟合(适合小白观看)
在提取指静脉的过程中,我们需要提取有用的ROI区域.而这时候,我们会采取将手指两边中点拟合成一条直线,求得这个直线的直线方程,然后得到旋转的角度,以便对原来的图像进行旋转操作.当我们知道如何取得手指的 ...
- 慎用cv::fitLine
cv::Point2f p1(-1,-1); cv::Point2f p2(-2,-2); vector<Point2f> vec; vec.push_back(p1); vec.push ...
- opencv直线拟合cv::fitLine()
通过2D或者2D点集拟合直线 void fitLine( InputArray points, OutputArray line, int distType,double param, double ...
- cv.bitwise_and用法
cv.bitwise_and 是 OpenCV 中的一个函数,它的作用是对两幅图像进行逐位与操作. 使用方法如下: cv.bitwise_and(src1, src2[, dst[, mask]]) ...
- 直线拟合fitLine函数的用法
在霍夫检测直线的时候,一条直线会被检测出许多条,可以根据给定的点集拟合出一条直线的情形. void cv::fitLine(cv::InputArray points, // 二维点的数组或vecto ...
最新文章
- detectmultiscale函数参数含义_OpenCV detectMultiScale函数
- 德国虚拟主机 linux,细说Linux虚拟主机的搭建及配置
- 源码解析:解析掌阅X2C 框架
- 【转】C++ 关键字——friend
- python 字符串转函数名_Python 使用函数名(字符串)调用函数(4种方法)
- JavaScript的对象观
- 洛谷P5300 与或和(全1子矩阵/单调栈)
- Unity怎么变中文
- 程序人生--hello‘s P2P(From Program to Process)
- 翻译:浏览器内部的工作原理
- python在每个字符后加上逗号_Python将逗号添加到数字字符串中
- 长安“战疫“网络安全赛Writeup
- html 源码_HTML实例之搜索栏(附源码)
- 基于ssm java健身俱乐部网站
- java 反编译工具=_JAVA反编译工具精选
- oracle----存储过程
- python读取excel绘图_python3读取excel绘图-女性时尚流行美容健康娱乐mv-ida网
- MySql 获取表的字段名
- 4.2android系统刷机
- 数据湖(九):Iceberg特点详述和数据类型