O'Reilly logo

Raspberry Pi Robotic Blueprints by Richard Grimmett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Color finding with OpenCV

Now you'll want to use OpenCV and your webcam to track your puck. OpenCV makes this amazingly simple by providing some high level libraries that can help you. To start with, you'll want to create a basic file that allows you to establish a threshold and then display the pixels as white that exceeds this threshold. To accomplish this, you'll edit a file to look something similar to what is shown in the following screenshot:

Color finding with OpenCV

Let's look specifically at the code that makes it possible to isolate the colored puck:

  • hue_img = cv.cvtColor(frame, cv.COLOR_BGR2HSV): This line creates a new image and stores it as per the values of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required