From 99b1c689eef2b459350189ebac9c2b3214d37ce9 Mon Sep 17 00:00:00 2001 From: gaillaro Date: Sat, 16 Apr 2005 00:09:28 +0000 Subject: --bug sur l'interface --- 2005/i/robert/src/ovision/see/Makefile.defs | 6 +- 2005/i/robert/src/ovision/see/img.cc | 2 +- 2005/i/robert/src/ovision/see/oconfig.cc | 10 +-- 2005/i/robert/src/ovision/see/skittle.cc | 20 ++--- 2005/i/robert/src/ovision/see/skittle.hh | 11 ++- 2005/i/robert/src/ovision/see/space.cc | 135 +++++++++++----------------- 2005/i/robert/src/ovision/see/space.hh | 83 ++++++----------- 2005/i/robert/src/ovision/ui/comm.cc | 44 ++++----- 2005/i/robert/src/ovision/ui/live.cc | 11 ++- 2005/i/robert/src/ovision/ui/live.hh | 4 +- 2005/i/robert/src/ovision/ui/liveView.cc | 101 ++++++++++++++------- 11 files changed, 206 insertions(+), 221 deletions(-) (limited to '2005') diff --git a/2005/i/robert/src/ovision/see/Makefile.defs b/2005/i/robert/src/ovision/see/Makefile.defs index 07430d3..c53d6b7 100644 --- a/2005/i/robert/src/ovision/see/Makefile.defs +++ b/2005/i/robert/src/ovision/see/Makefile.defs @@ -1,4 +1,4 @@ -PROGRAMS += test_ovision test_img test_group test_map test_ovisiontracker test_cam test_segm test_magnifier test_ovision test_colortable +PROGRAMS += test_ovision test_img test_group test_map test_ovisiontracker test_cam test_segm test_magnifier test_ovision test_colortable test_space LIBS += $(ovision_OBJECTS) ovision_OBJECTS = convertImg.o img.o oconfig.o segmTable.o hotelling.o segm.o imgInterface.o colorTable.o segmTable.o segmLearn.o group.o magnifier.o skittle.o #space.o map.o @@ -11,7 +11,7 @@ test_ovision_OBJECTS = test_ovision.cc $(ovision_OBJECTS) $(image_OBJECTS) $(vid test_ovisionogl_OBJECTS = test_ovisionogl.o $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) motor.o config.o serial.o test_ovisiontracker_OBJECTS = test_ovisiontracker.o $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) motor.o date.o serial.o utils.o logger.o config.o test_map_OBJECTS = test_map.o $(ovision_OBJECTS) $(image_OBJECTS) -test_dist_OBJECTS = test_dist.o $(ovision_OBJECTS) +test_space_OBJECTS = test_space.o space.o group.o oconfig.o image.o img.o segm.o test_colortable_OBJECTS = test_colortable.o oconfig.o segmTable.o imgInterface.o img.o segm.o segmLearn.o colorTable.o $(image_OBJECTS) test_group_OBJECTS = test_group.o group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o $(image_OBJECTS) test_magnifier_OBJECTS = test_magnifier.o hotelling.o magnifier.o group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o skittle.o $(image_OBJECTS) @@ -28,6 +28,6 @@ test_ovision: $(test_ovision_OBJECTS:%.o=%.o) test_ovisionogl: $(test_ovisionogl_OBJECTS:%.o=%.o) test_ovisiontracker: $(test_ovisiontracker_OBJECTS:%.o=%.o) test_map: $(test_map_OBJECTS:%.o=%.o) -test_dist: $(test_dist_OBJECTS:%.o=%.o) +test_space: $(test_space_OBJECTS:%.o=%.o) test_colortable: $(test_colortable_OBJECTS:%.o=%.o) $(CXX) $(LDFLAGS) -lz $^ -o $@ diff --git a/2005/i/robert/src/ovision/see/img.cc b/2005/i/robert/src/ovision/see/img.cc index 5dd4d28..52ce584 100644 --- a/2005/i/robert/src/ovision/see/img.cc +++ b/2005/i/robert/src/ovision/see/img.cc @@ -89,7 +89,7 @@ Img::load (ImageReader &loader) // Ouvre l'image Image image; image.read (loader); - image.getSize (width_, height_); + loader.getParam (width_, height_, colorMode_); nbPixels_ = width_ * height_; tabData_ = new unsigned char[image.getBufSize ()]; memcpy (tabData_, image.getBuf (), image.getBufSize ()); diff --git a/2005/i/robert/src/ovision/see/oconfig.cc b/2005/i/robert/src/ovision/see/oconfig.cc index fd96d12..77785a3 100644 --- a/2005/i/robert/src/ovision/see/oconfig.cc +++ b/2005/i/robert/src/ovision/see/oconfig.cc @@ -21,8 +21,8 @@ OConfig::OConfig(const char *filename) { instance = this; load (filename); - loadNNFile("rc/poids"); - loadDistFile("rc/dist"); + loadNNFile ("rc/poids"); + loadDistFile ("rc/dist"); } /// Destructor @@ -34,7 +34,7 @@ OConfig::~OConfig() /// @param *var nom de la variable a fixer /// @param *arg valeur de la variable void -OConfig::parse(const char *var, const char *arg) +OConfig::parse (const char *var, const char *arg) { if (!arg) return; std::string varName (var); @@ -167,7 +167,7 @@ OConfig::loadNNFile (const char *filePath) /// @param mode mode de l'espace de couleur /// @param nbOutput_ nombre de couleurs a detecter du reseau de neurones void -OConfig::createNNFile (const char *filename, const int nbOutput_) const +OConfig::createNNFile (const char *filename, const int nbOutput) const { if (!node) { @@ -181,7 +181,7 @@ OConfig::createNNFile (const char *filename, const int nbOutput_) const file << i->label << " " << i->color << "\n"; // Poids file << "#index\t#x1\tx2\tx3\n"; - for (int i=0; i 0) ? ymin : 0; - int ymax = (zone.ymax + grow); - ymax = (ymax < img_->height_) ? ymax : img_->height_; - int xmin = (zone.xmin - grow); - xmin = (xmin > 0) ? xmin : 0; - int xmax = (zone.xmax + grow); - xmax = (xmax < img_->width_) ? xmax : img_->width_; + int ymin = minWithBorder (zone.ymin - grow, 0); + int ymax = maxWithBorder (zone.ymax + grow, img_->height_); + int xmin = minWithBorder (zone.xmin - grow, 0); + int xmax = maxWithBorder (zone.xmax + grow, img_->width_); /// Initialisation du saut de point int jump = oconfig_->jumpPointDist/5; if (!jump) jump = 1; // Parcours d'une partie des pixels de l'image int tmpY; std::vector l; - for (int y = zone.ymin - grow; y < zone.ymax + grow; y += jump) + for (int y = ymin; y < ymax; y += jump) { tmpY = y*img_->width_; - for (int x=zone.xmin - grow; x < zone.xmax + grow; x += jump) + for (int x = xmin; x < xmax; x += jump) if (segm_->giveColor (img_->tabData_ + ((tmpY + x) * 3), true, true) == zone.color) { Hpoint h (x, y); @@ -88,8 +84,8 @@ Skittle::bend (Zone &zone) /// Point supérieur de la quille int upperPoint; /// Recherche du premier et du dernier point - int firstPoint = climb (zone.xmin + border, startY, zone.color); - int lastPoint = climb (zone.xmax - border, startY, zone.color); + int firstPoint = climb (maxWithBorder (zone.xmin + border, img_->width_), startY, zone.color); + int lastPoint = climb (minWithBorder (zone.xmax - border, 0), startY, zone.color); int limitPoint = firstPoint > lastPoint ? firstPoint : lastPoint; std::cout << firstPoint << " " << lastPoint << " " << limitPoint << std::endl; int above = 0; int below = 0; diff --git a/2005/i/robert/src/ovision/see/skittle.hh b/2005/i/robert/src/ovision/see/skittle.hh index 3ff458e..d2c5dbe 100644 --- a/2005/i/robert/src/ovision/see/skittle.hh +++ b/2005/i/robert/src/ovision/see/skittle.hh @@ -41,21 +41,26 @@ class Skittle Img *img_; public: + /// debout/couché/erreur + enum BendType {up, down, error}; /// Constructeur Skittle (Img *img, Segm *segm); /// Destructeur ~Skittle (void); /// Analyse d'une zone bool analyse (Zone &zone); + + private: /// Recherche de la composante principale void pca (Zone &zone); /// Recherche de du côté de la courbure - enum BendType {up, down, error}; BendType bend (Zone &zone); /// Utilisé pour la recherche de la courbure, cherche le point le plus haut int climb (const int startX, const int startY, const int color); - - private: + /// Renvoie le minimum en fonction d'une bordure + inline int minWithBorder (int n, int min) {return n > min ? n : min;} + /// Renvoie le maximum en fonction d'une bordure + inline int maxWithBorder (int n, int max) {return n < max ? n : max;} }; #endif // skittle_h diff --git a/2005/i/robert/src/ovision/see/space.cc b/2005/i/robert/src/ovision/see/space.cc index c77a6b2..dc618fc 100644 --- a/2005/i/robert/src/ovision/see/space.cc +++ b/2005/i/robert/src/ovision/see/space.cc @@ -4,184 +4,155 @@ /// @file space.cc Etalonnage des distances et localisation de la balle -#include "space.hh" +#include +#include +#include "space.hh" #include "group.hh" -#include "stdio.hh" -using namespace std; - /// Constructeur /// @param imgHeight hauteur de l'image /// @param imgWidth largeur de l'image -Space::Space (int imgWidth, int imgHeight) +Space::Space (const int imgWidth, const int imgHeight) + : imgHeight_ (imgHeight), imgWidth_ (imgWidth), tabX_ (0), tabY_ (0) { - Space::imgHeight = imgHeight; - Space::imgWidth = imgWidth; - - Space::oconfig = OConfig::GetInstance (); - - tabY = NULL; - tabX = NULL; + oconfig_ = OConfig::getInstance (); } - /// Destructeur Space::~Space () { + delete [] tabX_; + delete [] tabY_; } - /// Cree un fichier gnuplot avec la courbe des points donnés par la courbe x et y void -Space::CreateGnuPlotFile (int y) +Space::createGnuPlotFile (const int y) { - FILE *file; double locY, locX; - // Ouverture du fichier - file = fopen("dataY", "w+"); - + std::ofstream file ("dataY"); // Parcours pour tous les pixels verticaux de l'image - for (int i=0; i<296; i++) + 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]); - - cout << "Nombre de points loadé pour le calibrage de la distance: " << setupTab.size () << endl; + for (int i=0; ispaceNbDistPoint; i++) + addSetupPoint(oconfig_->spaceTabPoint[i*4+0], oconfig_->spaceTabPoint[i*4+1], + oconfig_->spaceTabPoint[i*4+2], oconfig_->spaceTabPoint[i*4+3]); + std::cout << "Nombre de points loadés pour le calibrage de la distance: " << setupTab.size () << std::endl; } - /// Donne les coefficients d'une ligne void -Space::FindCoeffLine (double x1, double y1, double x2, double y2, double &a, double &b) +Space::findCoeffLine (const double x1, const double y1, const double x2, double y2, + double &a, double &b) { a = (x2 - x1) / (y2 - y1); b = x1 - a * y1; } - /// Etalonnage des distances int -Space::Setup(double a, double b, double c) +Space::setup (const double a, const double b, const double c) { // Assignation des coefficients pour le calcul des y - aY = a; - bY = b; - cY = c; - + aY_ = a; bY_ = b; cY_ = c; + // Cherche les coefficients de 2 droites 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); - + findCoeffLine (65, 9, 118, 180, a1, b1); + findCoeffLine (198, 10, 192, 180, a2, b2); // Allocation de la mémoire - delete []tabY; - tabY = new double[imgHeight]; - - delete []tabX; - tabX = new double[imgHeight*imgWidth]; - + 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 "group.hh" #include "oconfig.hh" -//#define NB_NODES_X 5 -//#define NB_NODES_Y 3 - -//#define START_WEIGHT_MIN 0.1 -//#define START_WEIGHT_MAX 0.9 - - -struct SETUP_POINT -{ - int x, y; - int distx, disty; -}; - - /// Etalonnage des distances et localisation de la balle class Space { /// Classe config - OConfig *oconfig; - + OConfig *oconfig_; + /// hauteur de l'image + int imgHeight_; + /// largeur de l'image + int imgWidth_; /// tableau d'index des distances - double *tabX; - double *tabY; - + double *tabX_, *tabY_; /// liste des distances etalonnees - std::vector setupTab; - - /// hautdddeur de l'image - int imgHeight; - - /// largeur de l'image - int imgWidth; - - double aY, bY, cY; + struct SetupPoint; + std::vector setupTab; + double aY_, bY_, cY_; public: - - // Constructeur - Space (int width, int height); - - // Destructeur + /// Constructeur + Space (const int width, const int height); + /// Destructeur ~Space (); - /// Position d'un objet dans le referentiel du robot - void GetLoc(int locImgX, int locImgY, int &locX, int &locY); - void GetLoc(int locImgX, int locImgY, double &locX, double &locY); - + void getLoc (const int locImgX, const int locImgY, int &locX, int &locY_); + void getLoc (const int locImgX, const int locImgY, double &locX, double &locY_); /// Donne la position reelle sur la table de la balle - void GetPos(double locX, double locY, double posRobotX, double posRobotY, double angleRobot, double &posX, double &posY); - + void getPos (const double locX, const double locY_, const double posRobotX, + const double posRobotY, const double angleRobot, double &posX, double &posY); /// Ajoute un point pour l'etalonnage - void AddSetupPoint(int x, int y, int distx, int disty); - + void addSetupPoint (const int x, const int y, const int distx, const int disty); /// Chargement des points a partir d'un fichier - void LoadFromFile(); - + void loadFromFile (); /// Etalonnage des distances - int Setup(double aY, double bY, double cY); - - protected: - + int setup (const double aY_, const double bY_, const double cY_); + + private: + struct SetupPoint + { + int x, y; + int distx, disty; + }; /// Donne les coefficients d'une ligne - void FindCoeffLine (double x1, double y1, double x2, double y2, double &a, double &b); - + void findCoeffLine (const double x1, const double y1, const double x2, const double y2, double &a, double &b); /// Cree un fichier gnuplot avec la courbe des points donnés par la courbe x et y - void CreateGnuPlotFile (int y = 100); - + void createGnuPlotFile (const int y = 100); /// Cree un fichier avec l'erreur en fonction des itérations - void LogErrorPoint (FILE *f, int iter); + void logErrorPoint (FILE *f, const int iter); }; #endif // space_h diff --git a/2005/i/robert/src/ovision/ui/comm.cc b/2005/i/robert/src/ovision/ui/comm.cc index beb4be8..0d692a2 100644 --- a/2005/i/robert/src/ovision/ui/comm.cc +++ b/2005/i/robert/src/ovision/ui/comm.cc @@ -38,7 +38,7 @@ Comm::init () fclose(file); live_ = new Live (NBIMG); - live_->init (fname); + live_->init (Image::rgb, fname); } /// Destructeur @@ -111,31 +111,33 @@ Comm::executeUiCmds (const char *buffer) break; case 'm': // mélanger couleurs - int nbColorToMerge, numIndexColor; - - // Si on recoit une commande de remise a zero de l'index_ - ss >> nbColorToMerge; - if (nbColorToMerge == -1) - { - for (int i=0; ioconfig->nnNbColor; i++) - live_->segm->index_[i] = i; - } - // Sinon on mix les couleurs - else { - numIndexColor = live_->segm->index_[nbColorToMerge]; + int nbColorToMerge, numIndexColor = 0; - // On inscrit les changements dans l'index_ - int numColorToMerge; - for (int i=1; i> nbColorToMerge; + if (nbColorToMerge == -1) { - ss >> numColorToMerge; - live_->segm->index_[numColorToMerge] = numIndexColor; + for (int i=0; ioconfig->nnNbColor; i++) + live_->segm->index_[i] = i; } + // Sinon on mix les couleurs + else + { + numIndexColor = live_->segm->index_[nbColorToMerge]; + + // On inscrit les changements dans l'index_ + int numColorToMerge; + for (int i=1; i> numColorToMerge; + live_->segm->index_[numColorToMerge] = numIndexColor; + } + } + // On live_->segmente l'image puis on la stocke + live_->segmAndGroup(); + std::cout << nbColorToMerge << " colors merged to " << numIndexColor << std::endl; } - // On live_->segmente l'image puis on la stocke - live_->segmAndGroup(); - std::cout << nbColorToMerge << " colors merged to " << numIndexColor << std::endl; break; case 's': // isole une couleur diff --git a/2005/i/robert/src/ovision/ui/live.cc b/2005/i/robert/src/ovision/ui/live.cc index caa4e1b..c7b8b09 100644 --- a/2005/i/robert/src/ovision/ui/live.cc +++ b/2005/i/robert/src/ovision/ui/live.cc @@ -29,7 +29,7 @@ Live::Live (const unsigned nbImg, const ImageInput imgInput) /// Initialisation void -Live::init (const char *filename, const Image::PixelFormat pf, +Live::init (const Image::PixelFormat pf, const char *filename, const unsigned width, const unsigned height) { tex = new unsigned[nbImg_]; @@ -88,7 +88,7 @@ Live::init (const char *filename, const Image::PixelFormat pf, /// Mis à jour de l'image void -Live::updateImg (const char *filename, const Image::PixelFormat pf, +Live::updateImg (const Image::PixelFormat pf, const char *filename, const unsigned width, const unsigned height) { segm->setMode (pf); @@ -107,6 +107,9 @@ Live::updateImg (const char *filename, const Image::PixelFormat pf, } break; case cam: + { + std::cout << " Changement d'image caméra" << std::endl; + } case socket: break; } @@ -153,7 +156,7 @@ Live::segmAndGroup (const int numColorToShow) std::cout << numColorToShow << std::endl; // Création des groupes delete group; - group = new Group(img, segm); + group = new Group (img, segm); std::vector list; if (numColorToShow >= 0) { @@ -162,7 +165,7 @@ Live::segmAndGroup (const int numColorToShow) } else { - group->jumpPoints(oconfig->groupColor); + group->jumpPoints (oconfig->groupColor); mag->analyse (group->getZoneList ()); list = mag->getItemList ((Group::ZoneType)oconfig->uiGroupToDisplay); } diff --git a/2005/i/robert/src/ovision/ui/live.hh b/2005/i/robert/src/ovision/ui/live.hh index 1f9ad7c..7023428 100644 --- a/2005/i/robert/src/ovision/ui/live.hh +++ b/2005/i/robert/src/ovision/ui/live.hh @@ -64,7 +64,7 @@ class Live char fname[100]; /// Initialisation - void init (const char *filename, const Image::PixelFormat pf = Image::rgb, + void init (const Image::PixelFormat pf = Image::rgb, const char *filename = 0, const unsigned width=360, const unsigned height=296); /// Recharge le fichier de config void reloadConfig (const char *filename); @@ -73,7 +73,7 @@ class Live /// Fixe une image ségmentée et une image de groupe dans la partie centrale void rootPics (); /// Mis à jour de l'image - void updateImg (const char *filename, const Image::PixelFormat pf = Image::rgb, + void updateImg (const Image::PixelFormat pf = Image::rgb, const char *filename = 0, const unsigned width=360, const unsigned height=296); /// Accessors void setColorToFind (const int color) {colorToFind_ = color;} diff --git a/2005/i/robert/src/ovision/ui/liveView.cc b/2005/i/robert/src/ovision/ui/liveView.cc index 6aef4e1..39b7832 100644 --- a/2005/i/robert/src/ovision/ui/liveView.cc +++ b/2005/i/robert/src/ovision/ui/liveView.cc @@ -8,6 +8,7 @@ #include #include #include +#include #include "adjust.hh" #include "live.hh" @@ -28,6 +29,7 @@ unsigned iFileList; unsigned nnNbColor; Image::PixelFormat pf; int colorToFind; +int numSavedImg; /// Chargement d'une texture a partir de donnees RGB unsigned int @@ -141,56 +143,83 @@ keyPressed(unsigned char key, int x, int y) glutDestroyWindow(window); exit (0); } - else if (key == ' ') + if (ii == Live::file) { - if (iFileList < (fileList->size ()-1)) + if (key == ' ') { - ++iFileList; - live->updateImg ((*fileList)[iFileList].c_str (), pf); + if (iFileList < (fileList->size ()-1)) + { + ++iFileList; + live->updateImg (pf, (*fileList)[iFileList].c_str ()); + } } - } - else if (key == 8) - { - if (iFileList > 0) + else if (key == 8) { - --iFileList; - live->updateImg ((*fileList)[iFileList].c_str (), pf); + if (iFileList > 0) + { + --iFileList; + live->updateImg (pf, (*fileList)[iFileList].c_str ()); + } } - } - else if (key == 'b') - { - if (colorToFind > -1) + else if (key == 'b') + { + if (colorToFind > -1) + { + --colorToFind; + live->setColorToFind (colorToFind); + live->updateImg (pf, (*fileList)[iFileList].c_str ()); + std::cout << "Couleur sélectionnée " << colorToFind << std::endl; + } + } + else if (key == 'n') { - --colorToFind; - live->setColorToFind (colorToFind); - live->updateImg ((*fileList)[iFileList].c_str ()); - live->updateImg ((*fileList)[iFileList].c_str ()); - std::cout << "Couleur sélectionnée " << colorToFind << std::endl; + if (live->oconfig->nnNbColor > colorToFind) + { + ++colorToFind; + live->setColorToFind (colorToFind); + live->updateImg (pf, (*fileList)[iFileList].c_str ()); + std::cout << "Couleur sélectionnée " << colorToFind << std::endl; + } + } + else if (key == 13) + { + { + live->segm->setMode (pf); + live->segm->buildNN (nnNbColor, Segm::generate); + live->segm->trainNN (live->img); + live->updateImg (pf, (*fileList)[iFileList].c_str ()); + } } } - else if (key == 'n') + else if (ii == Live::cam) { - if (live->oconfig->nnNbColor > colorToFind) + if (key == ' ') + live->updateImg (); + else if (key == 13) + { + live->segm->setMode (pf); + live->segm->buildNN (nnNbColor, Segm::generate); + live->segm->trainNN (live->img); + live->updateImg (pf); + } + else if (key == 's') { - ++colorToFind; - live->setColorToFind (colorToFind); - live->updateImg ((*fileList)[iFileList].c_str ()); - std::cout << "Couleur sélectionnée " << colorToFind << std::endl; + std::string f; + std::ostringstream n; + n << numSavedImg++; + f = "cam" + n.str (); + if (pf == Image::rgb) f += ".rgb"; + else if (pf == Image::yuv) f+= ".yuv"; + live->img->writeRaw (f.c_str ()); + std::cout << "Image sauvée dans " << f << std::endl; } } - else if (key == 'r') + if (key == 'r') live->reloadConfig ("rc/vision.conf"); else if (key == 'm') std::cout << "Nombre de couleurs du prochain réseau de neurones : " << ++nnNbColor << std::endl; else if (key == 'l') std::cout << "Nombre de couleurs du prochain réseau de neurones : " << --nnNbColor << std::endl; - else if (key == 13) - { - live->segm->setMode (pf); - live->segm->buildNN (nnNbColor, Segm::generate); - live->segm->trainNN (live->img); - live->updateImg ((*fileList)[iFileList].c_str ()); - } drawGLScene (); } @@ -255,9 +284,13 @@ main(int argc, char **argv) iFileList = 0; nnNbColor = 6; colorToFind = -1; + numSavedImg = 0; live = new Live (nbImg, ii); - live->init ((*fileList)[0].c_str (), pf); + if (ii == Live::file) + live->init (pf, (*fileList)[0].c_str ()); + else + live->init (pf); // Boucle principale glutMainLoop(); -- cgit v1.2.3