I want to do a car park lot detection program for my school assignment but I am rookie on openCV and image process.
What i plan to do is using houghLine to detect the white line on the car park lot and draw a box. However, the line of the car park lot is not a complete rectangle.
Example ::
The output i need ::
I able to use houghLine to draw the vertical line ( Red Line ) but i have no idea how to join the line ( green line ) to form a box since houghLine detect multiple point of the line, it will not detect the start point and end point of the straight line. I also try the convex hull method but i didnot manage to do it. Any opencv function can overcome this porlbem ??
I really have no idea and hope anyone can give me some idea to solve the problem. Thank you.
Have you checked out the example in the OpenCV doc? If you use the function HoughLinesP
you get the 4 coordinates of the lines, so that drawing the lines is quite easy. I copy the example from the doc:
vector<Vec4i> lines;
HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
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 );
}
In vector lines
you get the coordinates of all the lines in the image. Once you have selected the two lines of the parking lot, you just need to use their coordinates to draw the new lines. For example, if you first line is in index k1
and the second one in k2
, the code will probably be something like this:
line( color_dst, Point(lines[k1][0], lines[k1][1]),
Point(lines[k2][0], lines[k2][1]), Scalar(0,0,255), 3, 8 );
line( color_dst, Point(lines[k1][2], lines[k1][3]),
Point(lines[k2][2], lines[k2][3]), Scalar(0,0,255), 3, 8 );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With