After my first OpenCV project which dealt with object tracking, I decided to do something a little more challenging and complex, but also more fun. I went for M&M sorting. You might have already seen this idea being realized somewhere online, I know I’ve seen a ton of different examples. However, everyone seems to have a different approach to doing it, so I figured I’ll give it a shot myself.
For those of you that want to jump straight into the action or just want to watch the pretty M&Ms fly about, you can go directly to my video showing the program execution:
If you’re interested in some more details on how the sub-parts of the project function, take a look at this video explaining things a bit better:
Finally, for those of you more into reading, and those looking for the specifics let me present the fine details of the project:
I recently started playing around with the OpenCV library and one of the first tutorials I did dealt with tracking a ball with the camera. I expanded on that concept a bit by having the camera rotate and continue tracking the ball even if it goes off screen. I did this by connecting the camera to a small servo controlled by an Arduino Uno, which receives commands from my PC via a serial connection.
The base project I used can be found here. I decided not to reinvent the wheel and used that code as a starting point so props to the author. However I did modify the code slightly and also added some more things to make it work for my project. The modification refers to changing the color model from RGB to HSV as I found out that it’s much easier to specify a tracking color by using the Hue value rather then finding a good RGB value. The additions refer to the code for serial connectivity and the Arduino instructions send via the serial connection itself.
You can see how the project ended up looking and working in this short YouTube video I made: