This is part of a Processing project I’m currently working on. This sketch allows the user to select colours from webcam input. The input is then analysed and a rectangle is drawn around all pixels close to the chosen colour. Up to 2 colours can be used for this sketch. This is similar to the getColorBoundsRect() method in the BitmapData class in Flash.
Click here to see the video on Vimeo
You can download the source code below:
colour_detection.pde, CoordsCalc.pde
Be aware though that in order to use it you should be in a well lit room with a good quality webcam. You might also need to fine tune your webcam settings. To select a colour, place your object in the red box in the bottom right hand corner of the frame and press 1 or 2.
Keys:
p to view the rectangles
1 to select the first colour
2 to select the second colour
0 to reset colours













Brilliant as usual. Love it.
I love it. Imagine a photo app where you can “swim” through your photos. Or going to NYT.com and being able to flip through articles, sorted and “stacked” by their importance and categories.
A bit like this – http://uk.youtube.com/watch?v=7CoJGrtVs4c – you mean. It would be fun to have it as an option although I imagine you arms would suffer as a result
Using colour isn’t the way to achieve this though as environmental differences (lighting/colour) would cause problems. Infrared is the way forward if considering this sort of interaction. Hopefully I should be looking into this area using a Wiimote at some stage.
What is the license for this code?
Been looking for something like this, thanks
Feel free to use it at your leisure Mike. Credit would be nice but don’t feel pressured
I’d be interested to see what you make with it
beautifull
hey how to build the source ??
thnks
Thanks kvnxp. You need to use Processing – http://processing.org/download/
Hi !
Great job ! Your code is so cool !
However, I can’t find where to define the location of the “pixel color detector” if you know what I mean ?
Because in this version, the program detects the color of the extreme bottom right pixel… I would like it to detect the color in the middle of the screen for example…
Can you help me ?
Thank you
Hi Remi
If I were you I’d search for an alternative colour tracking library. My version isn’t the best as it draws a rectangle around all pixels within a certain colour range. This means that you need have a controlled environment.
Good luck
Hi- i’m interested in using this script for robot vision- (i’m making a tennis ball fetching robot, im too lazy to get the balls myself =D)
Anyway, i was wondering if you knew of any ways to apply filters to video in processing, like equalization and so on to make the object tracking more reliable- for the looks the results obtained with this method could be overlayed onto the plain video to get the same, but better effect for colours existing elsewhere in the image.
Sorry if this is confusing, and if this is irrelevant- sue me.
Looking back at this code, there are some issues. The main one being that the rectangle covers all the tracked colour from the picture. This means that one pixel can ruin the effect. Have you looked at OpenCV? There should be a solution somewhere in this lib.
Sent from my iPhone
Hey there James,
Is it possible to use the source code for commercial use, with adaptations etc…?
This is brilliant,and just what I am looking for…
regards
Hi Wesley
I’d be interested to find out more about the project. Can you email me – contact details here – http://jamesalliban.wordpress.com/contact
hola, fascinante, yo debo hacer que identifique el color y que me muestre una animacion referente al clor , por ejemplo si muestro el color rojo entonces me muestre una manzana (obviamente la animacion ya va a estar cargada.
me puedes ayudar con esto???
hola, fascinante, yo debo hacer que identifique el color y que me muestre una animacion referente al color , por ejemplo si muestro el color rojo entonces me muestre una manzana (obviamente la animacion ya va a estar cargada)
me puedes ayudar con esto???
Hello, fascinating, I must do to identify the color and animation to show me a reference to color, for example if I show the color red then show me an apple (obviously the animation and will be charged)
can you help me with this??
Hello James,
It’s fascinating what you did!
I’ve try by myself but its don’t work, don’t know if i need change the “webcam settings”. but i found that Mac’s webcam settings is impossible to change ,i’ve tried the Photobooth with a webcam exterior,still the same….Could you tell more about that if you see my messages.
Thanks so much !
Thanks , i’ve found someone helped me .
This is a verry cool project. I’m making a sorting machine for my school project. I have 1 problem. When a color is detected i need to send a signal to an output. For example : When red is detected, a pin pushes an object a side. How can i send the signal from detecting outside my computer to a PLC ? Thanks
great job men!! i aplied to a path traking control robots modifing to obtain orientation !!! i send u the code when l finish excellent code !!!
I needed to add video.start(); worked great otherwise
Probably due to Processing update