加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 一般的OpenCV线路检测

发布时间:2020-12-16 05:20:04 所属栏目:百科 来源:网络整理
导读:我是opencv的新手(在c中),我正在尝试实现线路检测. 我有一张有几行的图片,我正在尝试确定线条之间的距离.我知道有Hough,Canny等,但是如何获得不同线的坐标来计算线之间的距离?我应该使用opencv轮廓函数还是有更好的方法?我不需要完整的代码示例,但有人能告
我是opencv的新手(在c中),我正在尝试实现线路检测.

我有一张有几行的图片,我正在尝试确定线条之间的距离.我知道有Hough,Canny等,但是如何获得不同线的坐标来计算线之间的距离?我应该使用opencv轮廓函数还是有更好的方法?我不需要完整的代码示例,但有人能告诉我完成工作的最佳方法吗?

解决方法

线检测经常导致使用Hough变换,Canny边缘检测器和轮廓检测仅在需要时用作方便的预处理器.

如果您有平行线,请使用

void HoughLines(InputArray image,OutputArray lines,double rho,double theta,int threshold,double srn=0,double stn=0 )

用于检测第二个参数将包含检测的行:

lines – Output vector of lines. Each line is represented by a
two-element vector (ρ,θ) . ρ is the distance from the coordinate
origin (0,0) (top-left corner of the image). θ is the line rotation
angle in radians ( 0 ~ vertical line,π/2 ~ horizontal line ).
[opencv2refman.pdf]

这意味着两条线之间的距离应为abs(rho1-rho2),即距离是第一列线中像素值之间的绝对差值. (注意:方法应该是CV_HOUGH_STANDARD!)

对于非平行线,您必须定义您认为的距离,但OpenCV仍然可以为您提供每个检测到的线的端点坐标.
你只需要使用method = CV_HOUGH_PROBABILISTIC.

CV_HOUGH_PROBABILISTIC probabilistic Hough transform (more efficient
in case if the picture contains a few long linear segments). It
returns line segments rather than the whole line. Each segment is
represented by starting and ending points,and the matrix must be (the
created sequence will be) of the CV_32SC4 type.
[opencv2refman.pdf]

您还可以在已安装的OpenCV的文档中找到opencv_tutorials.pdf中的教程.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读