Reputation: 55
I am working on school project in which i have to detect horizon in image. We have to use openCV. I got to the point where i can successfully detect horiton in image by using canny edge detector and Probabilistic Hough Transform. Here is my result:
As you can see line which is showing location of horizon is composed from multiple lines. My teacher is fine with accuracy of horizon detection, but he wants me to merge this multi-line into one curve.
Is there easy way to do it??
I am kinda new in programing so every help would be greatly appreciated.
And I want to apologise for my bad english.
Edit 1. : This is how i am creating lines:
vector<Vec4i> lines;
HoughLinesP(dst, lines, 1, CV_PI/180, 1, 1, 200 );
for( size_t i = 0; i < lines.size(); i++ )
{
Vec4i l = lines[i];
line( src, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
}
Upvotes: 2
Views: 4473
Reputation: 1905
The Hough-transform you mention usually returns all lines found in a picture (above a given threshold). They do not need to be continuous and can be in completely different locations and directions.
In your case they surprisingly follow the horizon pretty well. You could proceed by collecting all starting and/or end points, sorting them by x-coordinate and drawing with e.g. polylines.
However, considering the example image given, I would also try some different approaches altogether. For instance Canny edge detection with a big Gaussian and high threshold, active contours or just the strongest vertical-gradient (Sobel) in each image-column.
Upvotes: 2