We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Best way to track a certain color on webcam
Page Index Toggle Pages: 1
Best way to track a certain color on webcam? (Read 1448 times)
Best way to track a certain color on webcam?
Jan 5th, 2010, 2:48pm
 
In my project, I'm using a webcam to track a red and a green led. As it is, I'm using the method described in the brightness tracking example, except finding the pixels that return the highest values from red() or green().
This creates a problem though, in that other lights in the room (being white) will sometimes have a higher value in the red or green colorspace, even though they are farther away from what we perceive as red.
One possible solution would be to use vectors and find the pixel with the least distance between (255,0,0) and (pix.red,pix.green.pix.blue) in a theoretical 3d space. That would work I think, but I'm thinking it could cause slowdown computing that 614,400 times per frame.
Any thoughts?
Re: Best way to track a certain color on webcam?
Reply #1 - Jan 5th, 2010, 3:13pm
 
That vector thing I'm sure I tried and found too slow. First of all, I would make sure that all the auto settings like gain, exposure and white balance are turned off for the camera to get consistent results. Second, I would define a "red" as red is say twice as intense as green and blue, while green and blue are no more than twice of each other. Then, I would find all such points and calculate a center of red intensity for all red points. If you don't know what a center of red points is, you should read a physics book/wiki about center of mass. The formula is simple enough since you're able to theorize RGB into a vector you should be able to use the formula with ease. I should be able to help if you need some help.
Just curious, what are you trying to accomplish and what video library are you using? JMyron JMC JStreamer or?
Re: Best way to track a certain color on webcam?
Reply #2 - Jan 5th, 2010, 5:17pm
 
Thanks, I think I understand what your saying.
Go figure though, I was unable to find anything related to my question while searching the forums before I posted this, but just now while searching for 'center of mass' I found a very similar topic (that you had responded to).
Question though, from what I saw from wiki, the mass of the particles plays a role in the average. Should I take this into account somehow [mass=amount of red], or just ignore it and average the positions like you suggested to M1KES
My application for this is a kind of virtual theremin (red height=pitch, green height=volume). The leds was just the first thing I thought of after looking at some of the video examples. Ideally I might try for something like http://www.youtube.com/watch?v=sF_S2OVXqS8, but I'm just trying to get this working for now. Tongue
Not sure about library, isn't JMyron the default for Processing
Re: Best way to track a certain color on webcam?
Reply #3 - Jan 5th, 2010, 5:37pm
 
I would go without considering the intensity of red so every red point has equal weight. This requires a minimal brightness. I do this, first check the point is red enough say red>2green and red>2blue. Second I will make sure the red>minimal brightness say 80, otherwise some black points get counted. Again counting intensity of red in will likely get you a better center but it costs you time with multiplying operation for each red point.

Right, I did help out once but not a lot of people are doing what I do.
Re: Best way to track a certain color on webcam?
Reply #4 - Jan 5th, 2010, 7:55pm
 
Well, I've actually decided to move straight on to measuring against lines like in the posted video, and have already had some small success with it.

I thank you for your explanation of color tracking; I'm sure I'll be trying it in some webcam controlled game experiment soon. Smiley
Page Index Toggle Pages: 1