c – 一般的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中的教程.

相关文章

本程序的编译和运行环境如下(如果有运行方面的问题欢迎在评...
水了一学期的院选修,万万没想到期末考试还有比较硬核的编程...
补充一下,先前文章末尾给出的下载链接的完整代码含有部分C&...
思路如标题所说采用模N取余法,难点是这个除法过程如何实现。...
本篇博客有更新!!!更新后效果图如下: 文章末尾的完整代码...
刚开始学习模块化程序设计时,估计大家都被形参和实参搞迷糊...