Simple enough vision for beginners?

Hi! I’m the lead programmer from Grizzly Robotics. I primarily developed the vision tracking code during my Sophomore year (last year) and I am wondering if my code is simple enough for beginners knowledgeable in basic python? If it is not, could you offer suggestions on how to make it better?

Link to Code:

I didn’t have much trouble understanding it, at least line-by-line. However, it’s difficult to figure out how you wrote it.

I suggest adding some longer comments before sections of code describing the input and output. For example, input = color image output = b&w image with only objects within color range shown. Then go into detail on how you do this.

Avoid using words like “contour” without defining them first - I would use something like “outline”.

Use more descriptive variable names. “xg”, “yg”, “wg”, etc. aren’t very helpful - I would use something like “green_pos_x” or “green_width”. Longer variable names may take a bit longer to type, but they seriously help readability.

I don’t know python and I have only the WPI documentation page on robot vision, but I was able to get the gist of it. This seems like a really nice piece of sample code. Our team is using C++ and arduinos for our vision, but I’ll show it to the programmers anyway.

Looks pretty good to me! Seems like you’ve put a good chunk of time into it, and should be proud!

If you’re looking for suggestions, I always like comments that explain why the code has to be a certain way, or what assumptions you’re making. The lines of code itself can explain the “what”.

Have you considered any intro documentation you’d give to a new person? Perhaps a “guided tour” sort of thing, that would lead a new program through what the program is attempting to accomplish, what order things happen in, and what order to look through the code? I’ve always found it’s easier to talk through/understand what the code is intended to do first, then dig into the actual implementation.

Thanks for the advice everyone! I plan to make changes based on the suggestions you guys have given!