Colour tracking with Web-cam

Hello,

I’m bit stuck with a small project that I’m working on. As I simply cannot figure out how to make my web-cam track different colours on a piece of paper that I hold in front of my web-cam.

All I’ve managed so far is to make the webcam work (I know it’s not a lot, but I’m also very new to programming and I’m not particularity good at it) but I could really use some help/assistance with how to make my web-cam track fairly simple (pure?) colours like red, green and blue.

PS. I’ve been trying to find a solution on google for quite awhile now and all I can find is some pretty advanced stuff that I don’t really understand. And sometimes they use OpenCV or Aforge, which I’ve zero experience with.

Thanks in advance.

You’ve got two problems here. The first is filtering the image for the color you want. If it is red/green/blue, then you can simply select only that channel and extract it to operate on. If it is more subtle, like “all shades of yellow between ochre and canary,” then you’d need to come up with a filter expression to give you that.

The second problem is what you mean by “track.” Do you mean “only track blobs of a certain size, no smaller” or do you mean “track every single instance of every single pixel and/or group of pixels?” Either way, OpenCV has contouring and area-detection routines that can help you here, and you can pass the OpenCV results through filters that can eliminate small or spurious responses.

OpenCV can do the first color filter step too, and it is pretty amazing all around. There’s a plugin in the Unity Asset Store that pretty much makes integration as painless as possible.

BUT… I warn you, OpenCV is itself a very low-level nuts-and-bolts library, and it will take some time to get the hang of the OpenCV “Mat” data blob interface, but it really works well. It is not for the faint-hearted. You will spend a LOT of time googling how to do stuff with it, but it probably can do what you want. You will need a week or more just learning OpenCV and getting comfortable with how it marshals things around, if you are to use it effectively. It’s not a trivial thing.

Well, I just wanted to make my web-cam able to detect a red, green and blue orb that I’ve printed out on a white A4. And then detect the colours, e.g. if I move the paper then it should still keep track of the colours. I want to use it for a interactive game with physical objects that I’m planing to colour in order to tell the game what is what.
I’m experimenting with either colour VS shape for detecting my physical objects for my game. I thought colours would be easier than shapes (edge detection or such) but maybe I’m mistaken?

But isn’t there a “simple” way to do it (without the use of OpenCV maybe)? I’m a bit scared of OpenCV as it seems a bit… yeah as you call it “low-level” and I’m not really “pro”/“experienced” enough to work with something that is very complex :confused:

I was also looking at something called Aforge, maybe that would be easier to work with than OpenCV? I’m a bit at a lose here :confused:

Imho there is no “easy” or “simple” way when it comes to image recognition.
opencv unity - Search has some solutions.
And there are several wrappers for openvc out there.

Well, I was looking at something like this http://servetulas.com/blog/playground_library/tutorials/color-tracking/ it doesn’t seem to work all that well, but I don’t really understand how that code works… it doesn’t seem to work on its own.

Hello
Maybe you already have found a solution for your issue, due this forum is about one year ago. But if you are still interested we just published an asset that perfectly fit to your needs and comes with several examples. Check it out at

Don´t forget to tell us if it was useful for you in case you decide to use it.