opencv detect dotted lines

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-07 23:31:20

问题


I have an image which consists of somehow dotted lines:

NOTE: Open the image, to enlage it and see all the small dots

How can I use openCV to detect and parametrize those lines?

This image are the values of a laser range scanner on a robot and I need to get all the lines as good a possible.


The HoughLinesP function should be ideal for this?

I thried the following code:

    //converts laser range readings to a binary image.
    cv::Mat binaryImg = laserRangesToBinaryImage();

    cv::Mat cdst;
    cvtColor(binaryImg, cdst, CV_GRAY2BGR);

    std::vector<cv::Vec4i> lines;
    HoughLinesP(binaryImg, lines, 2, 5.0*CV_PI/180.0, 1, 2, 20 );
    for( size_t i = 0; i < lines.size(); i++ )
    {
        cv::Vec4i l = lines[i];
        line( cdst, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0,0,255), 3, CV_AA);
    }

    cv::imshow("Hough output", cdst);

which results in about 50 to 60 lines (using openCV 2.8.3 on Ubuntu 14.04):

The biggest problem here is that there are multiple separated line segments where a full line should be detected. So the segments aren't correctly connected. Some of the lines are too short or not even detected.

The optimal result should look like this (manually created) with about 20 line segments:

How can I achieve this result?


回答1:


If you didn't already, have a look at this tutorial.

Basically, you should act on these three parameters (the last three parameters of the HoughLinesP function), until you reach the right length for the detected lines:

  1. threshold: The minimum number of intersections (in the Hough space) to “detect” a line.
  2. minLinLength: The minimum number of points that can form a line. Lines with less than this number of points are disregarded.
  3. maxLineGap: The maximum gap between two points to be considered in the same line.

Mathematical morphology (closing) could help too, as it was mentionned in the comments. However, the help will be limited: a small 3x3 kernel is recommended for such a task, so if some pixels on a line are too far from one another the gap won't be filled up anyway.



来源:https://stackoverflow.com/questions/29200472/opencv-detect-dotted-lines

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!