From 898ad781a2efab3b47f25e228549fad2d44dc655 Mon Sep 17 00:00:00 2001 From: gaillaro Date: Wed, 19 May 2004 23:15:59 +0000 Subject: tset_ovision_ogl.cc --- 2004/i/nono/src/ovision/optim.cc | 87 +++++++++++++ 2004/i/nono/src/ovision/space.cc | 19 ++- 2004/i/nono/src/ovision/test_ovision_ogl.cc | 190 ++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 2004/i/nono/src/ovision/optim.cc create mode 100644 2004/i/nono/src/ovision/test_ovision_ogl.cc diff --git a/2004/i/nono/src/ovision/optim.cc b/2004/i/nono/src/ovision/optim.cc new file mode 100644 index 0000000..cef97b5 --- /dev/null +++ b/2004/i/nono/src/ovision/optim.cc @@ -0,0 +1,87 @@ + +#include "image/raw_loader.h" +#include "map.h" +#include "oconfig.h" +#include "group.h" +#include "space.h" + + +#include +#include +#include +#include +static struct timeval _tstart, _tend; +static struct timezone tz; + +void tstart(void) +{ + gettimeofday(&_tstart, &tz); +} +void tend(void) +{ + gettimeofday(&_tend,&tz); +} + +double tval() +{ + double t1, t2; + t1 = (double)_tstart.tv_sec + (double)_tstart.tv_usec/(1000*1000); + t2 = (double)_tend.tv_sec + (double)_tend.tv_usec/(1000*1000); + return t2-t1; +} + + + +int +main() +{ + ///////////////////////////////////////////////////////////////////////////////////////// + /// Initialisation des classes + OConfig oconfig("rc/vision.conf"); + + Img img; + RawLoader rawLoader("../src/ovision/test.rgb", 360, 296, ImageLoader::rgb); + img.load(rawLoader); + + Space space(img.width, img.height); + space.AddSetupPoint (356, 23, 300, 300); + space.AddSetupPoint (283, 171, 600, 600); + space.AddSetupPoint (253, 234, 1000, 900); + space.Setup (); + + SegmNN segmNN(&img); + segmNN.BuildNN(oconfig.nn_NbCouleurs, LOAD_FROM_FILE); + + Group group(&img, &segmNN); + + Map map(&space); + ///////////////////////////////////////////////////////////////////////////////////////// + + + ///////////////////////////////////////////////////////////////////////////////////////// + /// Prends une image a partir de la camera et l'analyse + + tstart (); + //segmNN.Segm(); + tend (); + std::cout << "Segmentation:\t" << tval () << std::endl; + + tstart (); + group.JumpPoints(oconfig.groupColor); + tend (); + std::cout << "Find Group:\t" << tval () << std::endl; + + tstart (); + if (group.zoneListBall) + { + int x,y; + x = group.zoneListBall->centerx; + y = img.height - group.zoneListBall->centery; + space.GetLoc(x, y, x, y); + tend (); + std::cout << "Map:\t\t" << tval () << std::endl; + + } + ///////////////////////////////////////////////////////////////////////////////////////// +} + diff --git a/2004/i/nono/src/ovision/space.cc b/2004/i/nono/src/ovision/space.cc index 8f04ebd..705dd0c 100644 --- a/2004/i/nono/src/ovision/space.cc +++ b/2004/i/nono/src/ovision/space.cc @@ -38,20 +38,28 @@ void Space::CreateGnuPlotFile (int y) FILE *file; double locY, locX; + // Ouverture du fichier file = fopen("dataY", "w+"); + + // Parcours pour tous les pixels verticaux de l'image for (int i=0; i<296; i++) { GetLoc(0, i, locX, locY); fprintf(file, "%i\t%lf\n", i, locY); } + // Fermeture du fichier fclose(file); + // Ouverture du fichier file = fopen("dataX", "w+"); + + // Parcours de tous les pixels horizontaux for (int i=0; i<352; i++) { GetLoc(0, y, locX, locY); fprintf(file, "%i\t%lf\n", i, locX); } + // Fermeture du fichier fclose(file); } @@ -76,6 +84,7 @@ Space::AddSetupPoint(int x, int y, int distx, int disty) void Space::LoadFromFile() { + // Parcours de tous les points du fichier dist for (int i=0; inbDistPoint; i++) AddSetupPoint(oconfig->tabPoint[i*4+0], oconfig->tabPoint[i*4+1], oconfig->tabPoint[i*4+2], oconfig->tabPoint[i*4+3]); @@ -96,34 +105,42 @@ Space::FindCoeffLine (double x1, double y1, double x2, double y2, double &a, dou int Space::Setup(double a, double b, double c) { + // Assignation des coefficients pour le calcul des y aY = a; bY = b; cY = c; double a1, b1, a2, b2; - + + // Cherche les coordonnées de 2 droites FindCoeffLine (65, 9, 118, 180, a1, b1); FindCoeffLine (198, 10, 192, 180, a2, b2); cout << a1 << " " << b1 << " " << a2 << " " << b2 << endl; + // Allocation de la mémoire delete []tabY; tabY = new double[imgHeight]; delete []tabX; tabX = new double[imgHeight*imgWidth]; + // Création du tableau de correspondance pour les x double diffPix; double unitPix; double center; for (int y=0; y +#include +#include +#include + +#include + +int fifo; +long pid; + +void +endSleep(int numSignal) +{ + // Reassignement du signal handler + signal(SIGUSR1, endSleep); +} + + +void +init () +{ + signal(SIGUSR1, endSleep); + + // Suppression de l'ancien fifo + system("rm -f uicmds"); + + // Creation du fifo + if (mknod("uicmds", S_IFIFO | 0666, 0) != 0 && errno != EEXIST) + { + std::cerr << " : Error during fifo creation"; + return; + } + + // Ouverture du fifo + fifo = open("uicmds", O_RDWR); + if (fifo < 0) + { + std::cerr << " : Error during fifo opening"; + return; + } + + // On choppe le pid du prog adjust situé dans le fichier adjust.PID + FILE *file; + file = fopen("adjust.PID", "r"); + if (!file) + { + std::cerr << "UI:UI : PID file not found" << std::endl; + exit(1); + } + char buf[10]; + fgets(buf, 10, file); + pid = atol(buf); + fclose(file); + + // Ecriture du PID dans un fichier + long uiPid = getpid(); + file = fopen("ui.PID", "w+"); + if (!file) + { + std::cerr << "Error during file opening" << std::endl; + return; + } + fprintf(file, "%li\n", uiPid); + fclose(file); + + // Ouverture du fifo + kill(pid, SIGUSR2); +} + +void +SendSignal(char *cmd) +{ + // Ecrit dans le fifo + write(fifo, cmd, 50); + + // Envoie un signal USR1 au prog adjust + kill(pid, SIGUSR1); +} + + + +void +end () +{ + close(fifo); + + system("rm -f adjust.PID ui.PID"); +} + +int +main () +{ + ///////////////////////////////////////////////////////////////////////////////////////// + /// Initialisation des classes + OConfig oconfig("rc/vision.conf"); + + Img img; + Video4Linux::ColorSpace cs; + cs = Video4Linux::rgb; + Video4Linux v4l("/dev/video", cs, 60000); + v4l.calibrate (); + + // Prendre une image pour que la taille de l'image soit configuré + img.load (v4l); + + Space space(img.width, img.height); + space.LoadFromFile (); + space.Setup (0.00603759, 0.593767, 291.474); + + + std::cout << "ok" << std::endl; + + SegmNN segmNN(&img); + segmNN.BuildNN(oconfig.nn_NbCouleurs, LOAD_FROM_FILE); + + Group group(&img, &segmNN); + + Map map(&space); + ///////////////////////////////////////////////////////////////////////////////////////// + init (); + + + + ///////////////////////////////////////////////////////////////////////////////////////// + /// Prends une image a partir de la camera et l'analyse + char filename[30]; + char buf[40]; + int i = 0; + while (1) + { + std::cout << "-----------------------------------------------------------------" << std::endl; + std::cout << "image n°" << i << std::endl; + img.load(v4l); + img.load(v4l); + sprintf(filename, "test%i.rgb", i); + img.WriteRGB(filename); + sprintf(buf, "n %s\n", filename); + SendSignal(buf); + + group.JumpPoints(oconfig.groupColor, oconfig.goalColor); + group.ShowZones(); + std::cout << "-------------\n" << std::endl; + +/* ZONE *pCur = group.zoneListBall; + int j=0; + while (pCur) + { + int x,y; + x = pCur->centerx; + y = img.height - pCur->centery; + space.GetLoc(x, y, x, y); + std::cout << j << ":" << x << " " << y << std::endl; + pCur = pCur->next; + j++; + } +*/ + + std::cout << "-------------\n" << std::endl; + std::cout << "Map:\n" << std::endl; + map.AddBallsToMap (&group); + map.ShowBalls (); + + double balX, balY; + if (map.GetCurBallPos (balX, balY)) + std::cout << "Balle Courante: " << balX << " " << balY << std::endl; + + + if (map.IsTree ()) + { + double treeX, treeY; + map.GetTreePos (treeX, treeY); + std::cout << "Tree: " << treeX << " " << treeY << std::endl; + } + + +// sleep(1); + getchar(); + i++; + } + ///////////////////////////////////////////////////////////////////////////////////////// + end (); +} + -- cgit v1.2.3