PacktPublishing/Learn-Robotics-Programming

Problem with color_track_behavior.py

Closed this issue · 6 comments

Hello again, Danny

I hope you are well.

My apologies for bothering you again. I'm sure you have better things to do. However, I've come across a bit of a road block while working through this section of your book.

This is the error message being outputted into the console:

color_tracking

Again, resorting to copying the code directly from github, the only edit I have made to the original is this:
"contours = cv2.findContours(contour_image, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[0]"
Suggested by you to a fellow reader on the raspberrypi forum.

I'm completely stumped.

Kind regards,
Onydus

Hello, first - it doesn't bother me to have book queries and inquiries. It's all good material to create an FAQ or improve things in follow-up books.

The callback set to none warning is unrelated to this- this is the cleanup code.

So I'm assuming this is the visual processing area. The OpenCV API has changed between the version I'd installed in the original book and now.

This code seems to work with a current version of OpenCV:

  contours = cv2.findContours(masked, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)[0]
  circles = [cv2.minEnclosingCircle(cnt) for cnt in contours]

Some questions so I can try to reproduce this:

  • Which version of Python are you running?
  • How did you install OpenCV for python?
  • What OpenCV packages do you get when you type pip freeze or pip3 freeze?
  • What do you get if you add print(repr(contours) before the circles line?

Hello Onydus,

Did you manage to get the updated code to work on the robot? Have you done any robotics projects since?
I hope things have settled a bit more now! It was a strange year or so for us all!

Danny

Hi Onydus,
That sounds interesting indeed - any links or photos of it? I didn't get the attachment there. 3D printers are such an awesome addition to making robots - I use mine a lot, although not for book robots, as the concern there is how much of the audience have access to them. I want to make a book focusing on 3D printable robot projects one day though. Hexapods, arms, heads, hands and so on.

Robotics degree course! Amazing!

I am working on a 3rd book - this time a Raspberry Pi Pico robotics book and trying for a faster-paced style. Just hope it won't make it harder to follow, although it's aimed at a reader who has done a little more than the first book. I'll be putting in a chapter skimming FreeCAD design, which is turning out to be quite tricky (and may need more than one chapter) - just to kickstart CAD thinking in a reader. Also, there will be scratch building chassis and using Monte-Carlo simulation to estimate a robot's position in a known space.

Anyway, thanks for getting back to me - always excited to see what people have been building.

Danny