In this article by Richard Grimmet, the author of the book, Raspberry Pi Robotics Essentials, we’ll look at how to detect the Color and motion of an object.
(For more resources related to this topic, see here.)
OpenCV and your webcam can also track colored objects. This will be useful if you want your biped to follow a colored object. OpenCV makes this amazingly simple by providing some high-level libraries that can help us with this task. To accomplish this, you’ll edit a file to look something like what is shown in the following screenshot:
Let’s look specifically at the code that makes it possible to isolate the colored ball:
Run the program. If you see a single black image, move this window, and you will expose the original image window as well. Now, take your target (in this case, an orange ping-pong ball) and move it into the frame. You should see something like what is shown in the following screenshot:
Notice the white pixels in our threshold image showing where the ball is located. You can add more OpenCV code that gives the actual location of the ball. In our original image file of the ball’s location, you can actually draw a rectangle around the ball as an indicator. Edit the file to look as follows:
The added lines look like the following:
Now that the code is ready, you can run it. You should see something that looks like the following screenshot:
You can now track your object. You can modify the color by changing the low_range and high_range n-tuples. You also have the location of your object, so you can use the location to do path planning for your robot.
Your biped robot can walk, use sensors to avoid barriers, plans its path, and even see barriers or target.
Further resources on this subject:
I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…
Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…
Once we learn how to deploy an Ubuntu server, how to manage users, and how…
Key-takeaways: Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…
While developing a web application, or setting dynamic pages and meta tags we need to deal with…
Software architecture is one of the most discussed topics in the software industry today, and…