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?
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:
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.