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 ++++++----------- 7 files changed, 107 insertions(+), 160 deletions(-) (limited to '2005/i/robert/src/ovision/see') 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 -- cgit v1.2.3