Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Configuracion/SRC/configuracionHSV.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Configuracion/SRC/configuracionHSV.cpp')
-rw-r--r--Configuracion/SRC/configuracionHSV.cpp303
1 files changed, 0 insertions, 303 deletions
diff --git a/Configuracion/SRC/configuracionHSV.cpp b/Configuracion/SRC/configuracionHSV.cpp
deleted file mode 100644
index bbe0160..0000000
--- a/Configuracion/SRC/configuracionHSV.cpp
+++ /dev/null
@@ -1,303 +0,0 @@
-/*
- * configuracionHSV.cpp
- *
- * Created on: 16/06/2010
- * Author: seba
- *
- *
- * Ss el mismo programa de configuracion solamente que convierte para la deteccion de los
- * colores primero convierte la imagen usando opencv y luego invoca a arLabelingHSB3 el
- * cual ya espera la imagen convertida. Por ultimo los valores H,S,V que maneja y guarda en el
- * archivo de configuracion son del rango de opencv, es decir 0-180, 0-255, 0-255 respectivamente.
- */
-
-#ifdef _WIN32
-# include <windows.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#ifndef __APPLE__
-# include <GL/glut.h>
-#else
-# include <GLUT/glut.h>
-#endif
-#include <AR/gsub.h>
-#include <AR/ar.h>
-#include <AR/video.h>
-#include <opencv/cv.h>
-#include "highgui.h"
-#include <formatopixel.h>
-#include "cvUtilities.h"
-#define MIN_H 0
-#define MAX_H 0
-#define MIN_S 0
-#define MAX_S 0
-#define MIN_B 0
-#define MAX_B 0
-#define UMBRAL 5
-int xsize, ysize;
-int thresh = 100;
-int count = 0;
-int minH = MIN_H, maxH = MAX_H, minS = MIN_S, maxS = MAX_S, minB = MIN_B,
- maxB = MAX_B, umbral = UMBRAL;
-int invert = 0;
-ARUint8 *dataPtr;
-/* set video capture configuration */
-#ifdef _WIN32
-char *vconf = "flipV,showDlg"; // see video.h for a list of supported parameters
-#else
-char vconf[256];
-#endif
-char *cparam_name = "Data/camera_para.dat";
-ARParam cparam;
-int armarImagenesDebug =0;
-static void init(void);
-static void cleanup(void);
-static void keyEvent( unsigned char key, int x, int y);
-static void mouseEvent(int button, int state, int x, int y);
-static void mainLoop(void);
-static int guardarEnFichero(void);
-static int cargarDeFichero(void);
-
-
-IplImage* img =NULL;
-IplImage* img2 =NULL;
-cvUtilities* util;
-ARUint8 *data1 = NULL;
-int main(int argc, char** args)
-{
- util = new cvUtilities();
- //initialize applications
- printf("\nEste programa sirve para entrenar al sistema a reconocer el objetivo a seguir:");
- printf("\n\n\n\t1.Situe el objetivo delante de la camara.");
- printf("\n\n\t2.Cuando vea su objetivo en la pantalla, haga click sobre el\n\tcon el boton derecho del raton.");
- printf("\n\n\t3.Realice varios clicks sobre la superficie del objetivo a seguir\n\tcon el boton izquierdo del raton, hasta que la superficie de este\n\taparezca totalmente bordeada.");
- printf("\n\n\t4.Tambiï¿1⁄2 puede ajustar manualmente los rangos de H, S y V que\n\tse detectaran,pulsando respectivamente las teclas 'h', 's' y 'b'.");
- printf("\n\n\t5.Puede ajustar un umbral pulsando 'u'. Cuanto mayor sea el umbral,\n\tmayor sera la desviacion permitida respecto de las componentes\n\tHSV elegidas.");
- printf("\n\n\t6.Cuando termine pulse 'g' para guardar la configuracion en el\n\tfichero conf.con.\n\n\n");
-
- glutInit(&argc, args);
- init();
- //start video capture
- arVideoCapStart();
- //start the main event loop
- argMainLoop( mouseEvent, keyEvent, mainLoop );
- return 0;
-}
-static void keyEvent( unsigned char key, int x, int y)
-{ char resp;
-/* quit if the ESC key is pressed */
-if( key == 0x1b ) {
- cleanup();
- exit(0);
-}
-if( key == 'h' ) {
- printf("\nminH = %d, maxH = %d\n",minH,maxH);
- printf("\nIntroduce el valor minimo de H(tono):\n");
- scanf("%d",&minH);
- printf("\nIntroduce el valor maximo de H(tono):\n");
- scanf("%d",&maxH);
-}
-if( key == 'b' ) {
- printf("\nminB = %d, maxB = %d\n",minB,maxB);
- printf("\nIntroduce el valor minimo de B(brillo):\n");
- scanf("%d",&minB);
- printf("\nIntroduce el valor maximo de B(brillo):\n");
- scanf("%d",&maxB);
-}
-if( key == 's' ) {
- printf("\nminS = %d, maxS = %d\n",minS,maxS);
- printf("\nIntroduce el valor minimo de S(Saturacion):\n");
- scanf("%d",&minS);
- printf("\nIntroduce el valor maximo de S(Saturacion):\n");
- scanf("%d",&maxS);
-}
-if( key == 'i' ) {
- if(invert) invert = 0;
- else invert = 1;
- printf("\nInversion realizada\n");
-}
-if( key == 'u' ) {
- printf("\nIntroduce el umbral:\n");
- scanf("%d",&umbral);
-}
-if( key == 'g' ) {
- printf("\nValores actuales: \nH: [%d-%d]\nS: [%d-%d]\nB: [%d-%d] \n",minH,maxH,minS,maxS,minB,maxB);
- printf("\nDesea guardar los datos de configuracion de la sesion actual? (s/n)\n");
- scanf("%c",&resp);
- if(resp=='s') {
- if(guardarEnFichero()) printf("\nConfiguracion guardada en fichero.\n");
- else {printf("\nError!. No se pudo guardar la configuracion en el fichero.\n");}
- }
-}
-}
-static void mouseEvent(int button, int state, int x, int y) {
- double H, S, V;
- ARUint8 *pnt;
- //x=x/2;
- //y=y/2;
- //varios clicks para autoajustar los valores H, S y V
- if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
- pnt = (dataPtr+(arImXsize*VALORES_POR_PIXEL*(y-1))+(x*VALORES_POR_PIXEL));
- RGBtoHSV(R_COMP, G_COMP, B_COMP, &H, &S, &V);
- //Convierto a escala openCV H:0-180 S:0-255 V:0-255
- util->HSVtoHSVcvUdouble(&H,&S,&V);
- if(H>=(maxH-umbral)) {maxH=(H+umbral);}
- if(H<=(minH+umbral)) {minH=(H-umbral);}
- if(S>=(maxS-umbral)) {maxS=(S+umbral);}
- if(S<=(minS+umbral)) {minS=(S+umbral);}
- if(V>=(maxB-umbral)) {maxB=(V+umbral);}
- if(V<=(minB+umbral)) {minB=(V-umbral);}
- printf("\nValores del pixel (RGB):\n%f %f %f\n",(double)R_COMP, (double)G_COMP, (double)B_COMP);
- printf("\nValores del pixel (HSVcv):\n%f %f %f\n",H, S, V);
- printf("\nNuevos rangos: \nH: [%d-%d]\nS: [%d-%d]\nB: [%d-%d] \n",minH,maxH,minS,maxS,minB,maxB);
- }
- //para declarar el punto inicial del objetivo
- if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) {
- pnt = (dataPtr+(arImXsize*VALORES_POR_PIXEL*(y-1))+(x*VALORES_POR_PIXEL));
- RGBtoHSV(R_COMP, G_COMP, B_COMP, &H, &S, &V);
- printf("\nValores del pixel HSV:\n%f %f %f\n",H, S, V);
- //Convierto a escala openCV H:0-180 S:0-255 V:0-255
- util->HSVtoHSVcvUdouble(&H,&S,&V);
- minH=H-umbral;
- maxH=H+umbral;
- minS=S-umbral;
- maxS=S+umbral;
- minB=V-umbral;
- maxB=V+umbral;
- printf("\nValores del pixel (RGB):\n%f %f %f\n",(double)R_COMP, (double)G_COMP, (double)B_COMP);
- printf("\nValores del pixel HSVcv:\n%f %f %f\n",H, S, V);
- /*printf("\nValores del pixel HSV funcion memoria:\n%f %f %f\n",H, S, V);
- uchar Hs,Ss,Vs;
- util->convertShervineRGBtoHSV(R_COMP,G_COMP,B_COMP,&Hs,&Ss,&Vs);
- printf("\nValores del pixel HSV funcion shervine:\n%d %d %d\n",Hs, Ss, Vs);*/
- }
-}
-/* main loop */
-static void mainLoop(void)
-{
- // ARMarkerInfo *marker_info;
- ARMarkerInfo2 *marker2;
- int marker_num2;
- //int marker_num;
- int i,j;
- ARInt16 *limage;
- int label_num;
- int *area, *clip, *label_ref;
- double *pos;
- marker_num2 = 0;
- /* grab a video frame */
- if( (dataPtr = (ARUint8 *)arVideoGetImage()) == NULL ) {
- arUtilSleep(2);
- return;
- }
- if( count == 0 ) arUtilTimerReset();
- count++;
- /*draw the video*/
- argDrawMode2D();
- argDispImage( dataPtr, 0,0 );
- /* capture the next video frame */
- arVideoCapNext();
- glColor3f( 1.0, 0.0, 0.0 );
- glLineWidth(6.0);
-
- if(img==NULL){
- printf("---------------->CREO LA IMAGEN OPENCV PORQUE ERA NULL 111\n\n\n");
- img = util->crearImagenCv2(dataPtr,xsize,ysize);
- }
- cvSetImageData( img, dataPtr, img->width* img->nChannels );
- if(data1==NULL){
- data1= new uchar[img->width* img->nChannels *img->height];
- }
-
- memcpy(data1,(uchar*)dataPtr,img->width* img->nChannels*img->height );
- cvSetImageData( img, data1, img->width* img->nChannels );
- cvCvtColor(img,img,CV_RGB2HSV);
-
- limage = arLabelingHSB2((ARUint8*)img->imageData, thresh, &label_num, &area, &pos, &clip, &label_ref, 1, minH, maxH, minS, maxS, minB,maxB, invert);
- if( limage == 0 ) {
- cleanup();
- exit(0);
- }
- marker2 = arDetectMarker3( limage, label_num, label_ref,area, pos, clip, AR_AREA_MAX, AR_AREA_MIN, &marker_num2);
- if( marker2 == 0 ) {
- cleanup();
- exit(0);
- }
- argDrawMode2D();
- glColor3f( 1.0, 0.0, 0.0 );
- for( i = 0; i < marker_num2; i++ ) {
- for(j=0; j<marker2[i].coord_num-1; j++) {
- argLineSeg( marker2[i].x_coord[j] , marker2[i].y_coord[j], marker2[i].x_coord
- [j+1], marker2[i].y_coord[j+1], 0, 0);
- }
- }
- /*swap the graphics buffers*/
- argSwapBuffers();
-}
-static void init( void )
-{
- ARParam wparam;
- cargarDeFichero();
- /* open the video path */
- if( arVideoOpen( vconf ) < 0 ) exit(0);
- /* find the size of the window */
- if( arVideoInqSize(&xsize, &ysize) < 0 ) exit(0);
- printf("Image size (x,y) = (%d,%d)\n", xsize, ysize);
- /* set the initial camera parameters */
- if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
- printf("Camera parameter load error !!\n");
- exit(0);
- }
- arParamChangeSize( &wparam, xsize, ysize, &cparam );
- arInitCparam( &cparam );
- printf("*** Camera Parameter ***\n");
- arParamDisp( &cparam );
- /* open the graphics window */
- argInit( &cparam, 1.0, 0, 2, 1, 0 );
- //argInit( &cparam, 2.0, 0, 0, 0, 0 );
-}
-/* cleanup function called when program exits */
-static void cleanup(void)
-{
- arVideoCapStop();
- arVideoClose();
- argCleanup();
-}
-/* draw the the AR objects */
-static int cargarDeFichero(void) {
- FILE *fich;
- char c;
- fich=fopen("conf.con","r");
- if(fich != NULL) {
- fscanf(fich,"%d",&umbral);
- fscanf(fich," %c",&c);
- if(c=='#'){ //si el separador es correcto y no es fin de fichero carga valores;
- fscanf(fich,"%d",&minH);
- fscanf(fich,"%d",&maxH);
- fscanf(fich,"%d",&minS);
- fscanf(fich,"%d",&maxS);
- fscanf(fich,"%d",&minB);
- fscanf(fich,"%d",&maxB);
- }
- fclose(fich);
- printf("Configuracion HSV cargada:\n");
- printf("minH = %d , maxH = %d\n",minH,maxH);
- printf("minS = %d , maxS = %d\n",minS,maxS);
- printf("minB = %d , maxB = %d\n",minB,maxB);
- return 1;
- }
- return 0;
-}
-static int guardarEnFichero(void) {
- FILE *fich;
- fich=fopen("conf.con","w");
- if(fich != NULL) {
- fprintf(fich,"%d\n#\n%d %d\n%d %d\n%d %d\n-\n",umbral,minH,maxH,minS,maxS,minB,maxB);
- fclose(fich);
- return 1;
- }
- return 0;
-}