前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cv2.fitline_pr自动抽帧

cv2.fitline_pr自动抽帧

作者头像
全栈程序员站长
发布2022-11-15 11:44:34
5240
发布2022-11-15 11:44:34
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

cv::fitLine用法

定义

在opencv官方文档定义如下:

代码语言:javascript
复制
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.

Jetbrains全家桶1年46,售后保障稳定

代码示例

简而言之,就是利用已有的点拟合直线,本篇只针对使用做简单示例,基于opencv3.4.5, C++; 主要介绍输出参数,

OutputArray line:在二维下为四个元素,前两个为向量(x, y),后两个为拟合直线上的一个点

distType,参考如下:

代码语言:javascript
复制
//! @see distanceTransform, fitLine
enum DistanceTypes { 

DIST_USER    = -1,  //!< User defined distance
DIST_L1      = 1,   //!< distance = |x1-x2| + |y1-y2|
DIST_L2      = 2,   //!< the simple euclidean distance
DIST_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.3998
DIST_WELSCH  = 6,   //!< distance = c^2/2(1-exp(-(x/c)^2)), c = 2.9846
DIST_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)如图下

cv2.fitline_pr自动抽帧
cv2.fitline_pr自动抽帧

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;

控制台输出

代码语言:javascript
复制
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)

cv2.fitline_pr自动抽帧
cv2.fitline_pr自动抽帧

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;

代码语言:javascript
复制
calc_line[0]=0.707107
calc_line[0]=-0.707107
calc_line[0]=1.5
calc_line[0]=1.5

Enjoy~

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/234392.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年11月2日 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • cv::fitLine用法
  • 定义
  • 代码示例
    • y = x + 1直线
      • y = -x + 1直线
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档