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: