LATEST VERSION 2.0 (10.02.2012)

Description

Another module uses OpenCV library to detect colors on the image. This module works with any UImage variable and provide some additional functionality. It returns position of central moment of detected region. You can also display image with selected detected region.

colorDet1colorDet2

HSV space

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).

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 color detected
UColorDetection.x; - object position
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

How to use in urbiscript

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;

Download

LINK

 

 

 

EMYS and FLASH are Open Source and distributed according to the GPL v2.0 © Rev. 0.8.0, 27.04.2016

FLASH Documentation