lines.py not working as expected

Cool!

So made some optimizations to Canny, it should run faster now (went from 10FPS to 15FPS @QQVGA)

Great, I’ll compile and try it out


Sean

@kwagyeman ETA on posting the new code? We’ve got a race on Sat and I’ll need a day to test. Possibly by EOD Thurs?

Working on the code right now. I’ve finished find_lines up. Now working on find line segments. You want to use the first one. I can post that by the end of the day. A firmware image and example script that is.

:smiley:

Okay, here it is (attached).

Try playing with the settings to get the best FPS. Grayscale goes really fast. Also, disable the frame buffer (top right hand corner of the IDE) to see the speed on the go.

You should be able to hit 30 FPS in grayscale.

Demo scripts are attached in there too. Note that the firmware is only for the M7. However, these functions fit on the M4 and will run at about half the speed on it. Again, the attached firmware does not work for the M4. But, this feature will be available at half speed on the M4 once we release it.
openmv.zip (1.6 MB)

Just playing with this now. Amazing!

I tried this code this weekend at the DIY Robocars race, but couldn’t get it to recognize the painted lines (either white or color) as lines. I don’t see where to tune the example code for color or grayscale thresholds (the “threshold” in this means something else: “img.find_line_segments(threshold = 1000, theta_margin = 15, rho_margin = 15, segment_threshold = 100”).

What’s the best way to optimize this for certain colors or white lines?

Threshold is the parameter you need to change. In particular, you have to lower its value if nothing is detected.

The threshold value is a limit check on the sum of sobel filter magnitude responses for each pixel on a line. If the edge isn’t very strong then you need a lower threshold. Note that the find lines function expects the edge to be only about 3 pixels wide… If the line softly changes into the background then find lines with fail to see the line edge.

Anyway, just lower the threshold value until a line is seen.

The segment threshold argument is a threshold on the sobel magnitude response on each pixel under a line. Again, just lower it if you don’t see anything.

I suggest calling the find lines method and not the find line segments method. You can call the find lines method on different rois of the image like in the line following script… Then determine the angle the line turns I’m each roi. Note that you’ll want to lower the threshold value if the line you expect to detect is shorter.

Find lines is a lot faster than find line segments.

Great, I’ll try that.

Is there any way to have the find lines make a color preference? Or even to flag the color of the lines that find lines found?

(I suppose I could do a blob detection with ROIs defined by the lines and then sort the lines by that, but I’m wondering if color choice is built into the function)

Find lines just cares about edges, not color. If you want to add color preferences then you should binary() the image by what color you are looking for. This will also have the affect of GREATLY increasing the edge magnitude for a line. Note that since your running find lines on the ouput of binary you don’t have to worry about too much extra junk being seen if your thresholds aren’t very tight.

Binary is a single pass algorithm so it runs really fast and will barely affect your frame rate.

This works great by adding

red_threshold = (0,100, 0,127, 0,127) # L A B
green_threshold = (0,100, -128,0, 10,127) # L A B
blue_threshold = (0,100, -128,127, -128,0) # L A B

img = sensor.snapshot()
img.binary([green_threshold])

I had to really crank up the thresholds to get a single line, however:

for l in img.find_lines(threshold = 4000, theta_margin = 125, rho_margin = 175):

Hope that’s okay!