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?