微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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中的教程.

原文地址:https://www.jb51.cc/c/114997.html

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

相关推荐