Line Detection. [closed]
After increasing the minLineLength and decreasing maxLineGap program is still showing number of lines and also the gap is also visible. Can someone tell me the problem in the program? Image is:- Code is-:
include "stdafx.h"
include <cv.h>
include <highgui.h>
include <math.h>
using namespace cv;
int main(int argc, char** argv)
{
Mat src, dst, color_dst;
src = imread("line2.jpg", 0);
Canny(src, dst, 50, 200, 3);
cvtColor(dst, color_dst, CV_GRAY2BGR);
vector<Vec4i> lines;
HoughLinesP(dst,lines,1,CV_PI/180,80,600,300);
for (size_t i = 0; i < lines.size(); i++)
{
line(color_dst, Point(lines[i][0], lines[i][1]),
Point(lines[i][2], lines[i][3]), Scalar(0, 0, 255), 3, 8);
}
namedWindow("Source", 1);
imshow("Source", src);
namedWindow("Detected Lines", 1);
imshow("Detected Lines", color_dst);
waitKey(0);
return(0);
}
IT is due to the fact you are using a canny filter. Offcourse this will generate double edges if you increase the line thickness. Why not apply dilate and erode operations. First dilate enough to merge them, then erode the same amount and only a single line will remain.
ya it's good to use morphological operations but HoughP transform already have parameters to do this. Can you tell me the working and use of last 2 parameters in which i have given 600 and 300 value?
Just go for the manual erosion dilation which gives you way more control than the embedded options. That is what I prefer in my software.
Actually if I will use morphological operations, the edges on which I have to work will be lost! Since they are of same thickness.
I think that you are using the opposite operation, try the other way (open <-> close, dilate <-> erode, top hat <-> black hat)
Since all the edges are of same thickness it doesn't matter what I should use first opening or closing. I want to use the parameters in Hough P Transform to eliminate redundant lines.
I do not know more than the docs, but you can test it and verify what is happening when changing the parameters. Do this one by one, so you do not change more than one parameter at once.
@Vivek Goel : that is not correct! If you apply dilate first then reduce, then lines will NOT dissappear! Only the thickest line will be a bit thicker...
Will canny give edges of different thickness? Since if the canny output give edges of different thickness then it will be correct solution but if the detected edges are of same thickness then the morphological operations will be much hard to calibrate and I will to design a much good and sophisticated structuring element.
At first all edges are equal, but at a certain moment the two closest edges merge with dilation into a single element. Applying the same amount of erosion elements then will not remove the others NOR will it return to 2 edges. I do not see the problem. I think you are missing something.