Sistema de Visión: HSV

30/05/2009 at 6:26 pm (Robot Nao)

Una vez representada la imagen en RGB nos pusimos a probar con diferentes formatos de imagen, en este caso usaremos el HSV.

Obtendremos la imagen de la cámara del robot como antes en formato RGB, una vez la tengamos la convertimos a su correspondiente en HSV.

    float max = r;
    float min = r;

    if (max < g) max = g;
    if (min > g) min = g;
    if (max < b) max = b;
    if (min > b) min = b;

    if (max == min){
    h = 0.0;

    if (max == r ){
            h = 60 * ((g – b) / (max – min));
            if (g < b){
                    h += 360;
            }
    }
    if (max == g){
            h = (60 * ((b – r) / (max – min))) + 120;
    }
    if (max == b){
            h = (60 * ((r – g) / (max – min))) + 240;
    }
    if (max == 0){
            s = 0.0;
    }else{
            s = 1 – (min / max);
    }
    v = max;

Una vez hecho esto mostraremos las 3 imagenes en el interfaz (la de H , S, V). Y volveremos a convertir la imagen a rgb.

    float h_aux, f, p, q, t, v_aux;

    h_aux = ((int)fabs(H/60.0)) % 6;
    f = (H/60.0) – h_aux;

    v_aux = V;
    p = v_aux * (1-S);
    q = v_aux * (1 – f*S);
    t = v_aux * (1 – (1-f)*S);

    if (((int)h_aux) == 0){
            r = v_aux; g=t; b=p;
    }
    else if (((int)h_aux == 1)){
            r = q; g=v_aux; b=p;
    }
    else if (((int)h_aux == 2)){
            r = p; g=v_aux; b=t;
    }
    else if (((int)h_aux == 3)){
            r = p; g=q; b=v_aux;
    }
    else if (((int)h_aux == 4)){
            r = t; g=p; b=v_aux;
    }
    else if (((int)h_aux == 5)){
            r = v_aux; g=p; b=q;
    }

Tuvimos algún problema en las conversiones, perdiamos algo de información y no nos dimos cuenta de los rangos en los que estaba HSV, pero pudimos arreglarlo sin ningún problema.

    image1->SetRGB(x/2, y/2, (h * 255/360), 0, 0);
    image2->SetRGB(x/2, y/2, 0, (s * 255), 0);
    image3->SetRGB(x/2, y/2, 0, 0, v);

hsv

hsv2

Advertisement

Deja un comentario

Fill in your details below or click an icon to log in:

Logo de WordPress.com

You are commenting using your WordPress.com account. Log Out / Cambiar )

Twitter picture

You are commenting using your Twitter account. Log Out / Cambiar )

Facebook photo

You are commenting using your Facebook account. Log Out / Cambiar )

Connecting to %s

Seguir

Get every new post delivered to your Inbox.