U Color Detection
LATEST VERSION 2.0 (10.02.2012)
Description:
Another example how to use OpenCV library to detect colors on the image.
This module works with UCamera module
http://www.urbiforge.org/index.php/Modules/UCamera
and provide some additional functionality. It returns position of central moment of detected region. You can also display image with selected detected region.
Requirement:
Urbi SDK 2.7.1 or higher
OpenCV 2.3.1
MS Visual Studio 2008 or higher for compilation from sources
How to set color to detect?
1. Run detector with default parameters.
2. Show image in console 'Cam.image;' then do the screenshot (PrtSc key).
3. Paste image from clipboard to Pain (GIMP or another image program).
4. Use 'Color Picker' tool to chose the color and open the color selection palette.
5. Save HSV values and use SetColor(H_min, H_max, S_min, S_max, V_min, V_max) function

You can set the color offline. HSV means Hue-Saturation-Value, where the Hue is the color. And since color is not an easy thing to separate or compare, Hue is often represented as a circular
angle (between 0 to 360 when stored as 0-239). Being a circular value meansthat 255 is the same as 0. For example, a Hue of 0 is red, a Hue of 63 would be green, a Hue of 127 is blue, a Hue of 191 is pink. Saturation is the greyness, so that a Saturation value (0-255 also) near 0 means it is dull or grey looking whereas
as a Saturation value of 200 might be a very strong color (eg: red if Hue is 0). And Value (0-255 also) is the brightness of the pixel, so 0 is black and 255 is white.
(For a lot more info about HSV and other color spaces, go to HSL and HSV on Wikipedia http://en.wikipedia.org/wiki/HSL_and_HSV).
Module functions:
UColorDetection.new(&image); - initialize with image source
UColorDetection.mode; - set detector mode
mode 0 - you have to get image then call detector function manually, you can use also this option to OFF detector (see example 1)
mode 1 - get image manually in a loop (see example 2)
mode 2 - use input port data-flow
UColorDetection.image; - access to UImage variable, you can see image in Urbi console also
UColorDetection.width; - image width (determined by scale)
UColorDetection.height; - image height (determined by scale)
UColorDetection.scale; - set image scale for processing
UColorDetection.visible; - 1 if object detected
UColorDetection.x;
UColorDetection.y; - object position
UColorDetection.time; - processing time
UColorDetection.fps; - algorithm performance
UColorDetection.input; - object input (use in mode 3 only)
UColorDetection.SetImage(image); - use this function to detect object manually, you can run this function in background
UColorDetection.SetColor(H_min, H_max, S_min, S_max, V_min, V_max); - set color to detect (in HSV color space)
H - hue varies from 0 (~0°red) to 255 (~360°red again)
S - saturation from 0 to 255
V - value from 0 to 255
Example 1:
loadModule("UCamera");
var Global.Cam=UCamera.new(0);
loadModule("UColorDetection");
var Global.Det=UColorDetection.new(Global.Cam.&image);
Global.Det.SetColor(0,20,100,255,0,110);
t: loop {
Global.Cam.GetImage();
Global.Det.SetImage(Global.Cam.image),
},
Example 2:
loadModule("UCamera");
var Global.Cam=UCamera.new(0);
loadModule("UColorDetection");
var Global.Det=UColorDetection.new(Global.Cam.&image);
Global.Det.mode=1;
Global.Det.SetColor(0,20,100,255,0,110);
t: loop {
Global.Cam.GetImage();
},
Example 3:
loadModule("UCamera");
var Global.Cam=UCamera.new(0);
Global.Cam.notify=1;
loadModule("UColorDetection");
var Global.Det=UColorDetection.new(Global.Cam.&image);
Global.Det.mode=2;
Global.Det.SetColor(0,20,100,255,0,110);
var Conn = Global.Cam.&image >> Global.Det.&input;
//Conn.asynchronous=true;
Download here:
Version 2.0
http://lirec.ict.pwr.wroc.pl/~jkedzier/urbi/ucolordetection20_for_opencv231.zip
You can download OpenCV2.3.1 compiled with Intel TBB libraries.
http://lirec.ict.pwr.wroc.pl/~jkedzier/urbi/OpenCV2.3.1.zip
WRUT