Okay, I see.
So, fine_line_segments does just what you need:
And it returns a list of these things:
You just need to setup your thresholds and merge settings and you’ll basically get two lines on either side of the nozel that start and end on either side of the stream until they hit the nozel or bottom of the image.
Anyway, there’s a find_line_segments example script for this… start with it.
Also, since you know what openCV does to find lines, here’s what we do: https://github.com/openmv/openmv/blob/master/src/omv/img/hough.c
Basically, we sobel filter the image and use the gradient and mag output from each pixel to feed a hough accumulator array. By doing this we skip the canny process and doing the 0-180 degree hough line iteration on each pixel. This method is a little more noisy but an order of magnitude faster. After which, we look for hough peaks above your given threshold and we also make sure to only return true peaks (i.e. peaks with no value near them that are greater than them). Next we merge all hough lines which have similar rho and pheta values. We do this because the raw output of the hough transform produces a ton of lines. By merging lines you get cleaner output. Finally, we compute the start and end points of each infinite line.
Find line segments uses the above code and then walks each infinite line while running the sobel algorithm on the pixels underneath to determine the start and end points of line segments on that infinite line. A better method would have been to keep track of what points contributed to the infinite line when we ran the above algorithm but we don’t have memory for that. Anyway, to make walking the infinite line work better I actually 3 three lines in parallel to each infinite line to deal with slight curves. Then finally, the real magic happens during merging. So, walking lines with the above approach produces a lot of small unconnected lines right next to each other. Our merge algorithm then joins all these small line segments into one line segment that’s returned to you.
Anyway, the point of both these methods is to get you the output you want without having to deal with all the details between.