Tracking RGB objects

Hey All,

I’ve made a little app that will track coloured objects in video. It’s really my first stab at both openFrameworks and C++ so it’s very much a work in progress.

You can see a windows screen-shot here:

And if you want to have a play I’ve uploaded a zip with a mac binary in it. I’ve also included the SRC folder for you to take a look at the source. This was based on the movieGrabberExample app that comes with OF so if you make a copy of that and replace the src folder with this one it should build.

The binary was compiled with XCode 2.4.1 on a Macbook. OF 0.02

The keys are as follows:

  1. Press any number between 1 and 9 on your keyboard

  2. Hold either a Red, Green or Blue object up in front of the camera and position it within the square in the centre.

  3. Press C. It should now start tracking the object as you move it around the screen.

Repeat these steps for each object you want to track. Realistically it’s limited to three, one Green, one Red and one Blue because it will confuse objects of the same colour.

Other Keys:

P Turns on a pen so it leaves a trail
Q Clears this trail

U Increase the search area
D decrease the search area

F Flip the screen to make it more mirror like.

This is really my first proper stab at C++ and I’ve got tonnes more to learn so I’d love to hear any feedback or suggestions about other things I could try or how I could improve it. I’m a bit lost for potential applications for this because it was largely just to try and develop my C++ skills and have a go at tracking objects. Any suggestions for potential directions to take this in would be much appreciated.

Thanks again for OF guys it made it so much easier starting out coding.


Wow - thats an awesome example!

Very nice - are you doing the color tracking in HSV space or RGB?
For the laser tag project we used HSV which has the advantage that you can sort of specify how tolerant the tracking is of other similar hues (as well as saturation and brightness).

This sounds like what I am looking for, unfortunately the source code is no longer available. Does anyone out there have it?

As stated above files arent there anymore. It would be great if anyone can shae them. Thanks!

You guys might want to check out this thread:

Zach posted some code there that probably does what you’re looking for.

  • Mike