summaryrefslogtreecommitdiff
path: root/2005
diff options
context:
space:
mode:
Diffstat (limited to '2005')
-rw-r--r--2005/i/robert/src/ovision/see/Makefile.defs6
-rw-r--r--2005/i/robert/src/ovision/see/img.cc2
-rw-r--r--2005/i/robert/src/ovision/see/oconfig.cc10
-rw-r--r--2005/i/robert/src/ovision/see/skittle.cc20
-rw-r--r--2005/i/robert/src/ovision/see/skittle.hh11
-rw-r--r--2005/i/robert/src/ovision/see/space.cc135
-rw-r--r--2005/i/robert/src/ovision/see/space.hh83
-rw-r--r--2005/i/robert/src/ovision/ui/comm.cc44
-rw-r--r--2005/i/robert/src/ovision/ui/live.cc11
-rw-r--r--2005/i/robert/src/ovision/ui/live.hh4
-rw-r--r--2005/i/robert/src/ovision/ui/liveView.cc101
11 files changed, 206 insertions, 221 deletions
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<nbOutput_; i++)
+ for (int i=0; i<nbOutput; i++)
{
file << index[i] << "\t";
for (int j=0; j<3; j++)
diff --git a/2005/i/robert/src/ovision/see/skittle.cc b/2005/i/robert/src/ovision/see/skittle.cc
index 45462c1..a1b4bfd 100644
--- a/2005/i/robert/src/ovision/see/skittle.cc
+++ b/2005/i/robert/src/ovision/see/skittle.cc
@@ -27,24 +27,20 @@ Skittle::pca (Zone &zone)
{
// Agrandissement de la zone de recherche
const int grow = 30;
- int ymin = (zone.ymin - grow);
- ymin = (ymin > 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<Hpoint> 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 <iostream>
+#include <fstream>
+#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; i<imgHeight_; i++)
{
- GetLoc(0, i, locX, locY);
- fprintf(file, "%i\t%f\n", i, locY);
+ getLoc (0, i, locX, locY);
+ file << i << "\t" << locY << "\n";
}
// Fermeture du fichier
- fclose(file);
-
+ file.close ();
// Ouverture du fichier
- file = fopen("dataX", "w+");
-
+ std::ofstream file2 ("dataX");
// Parcours de tous les pixels horizontaux
- for (int i=0; i<352; i++)
+ for (int i=0; i<imgWidth_; i++)
{
- GetLoc(0, y, locX, locY);
- fprintf(file, "%i\t%f\n", i, locX);
+ getLoc (0, y, locX, locY);
+ file2 << i << "\t" << locY << "\n";
}
// Fermeture du fichier
- fclose(file);
-
+ file2.close ();
}
-
/// Ajoute un point pour l'etalonnage
void
-Space::AddSetupPoint(int x, int y, int distx, int disty)
+Space::addSetupPoint (const int x, const int y, const int distx, const int disty)
{
- SETUP_POINT setupPoint;
-
+ /// Ajout d'un point à la liste
+ SetupPoint setupPoint;
setupPoint.x = x;
setupPoint.y = y;
setupPoint.distx = distx;
setupPoint.disty = disty;
-
- setupTab.push_back(setupPoint);
+ setupTab.push_back (setupPoint);
}
-
/// Chargement des points a partir d'un fichier
void
-Space::LoadFromFile()
+Space::loadFromFile ()
{
// Parcours de tous les points du fichier dist
- for (int i=0; i<oconfig->nbDistPoint; 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; i<oconfig_->spaceNbDistPoint; 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<imgHeight; y++)
+ for (int y=0; y<imgHeight_; y++)
{
// Calcul de la "longeur réelle" d'un pixel
diffPix = (a2*y+b2) - (a1*y+b1);
unitPix = 100.0f / diffPix;
- tabY[y] = unitPix;
+ tabY_[y] = unitPix;
// Calcul du centre du robot sur l'image en fonction du y
center = a2*y + b2;
-// cout << y << "\t" << tabY[y] << endl;
+ // cout << y << "\t" << tabY[y] << endl;
// Parcours de tous les x de la ligne et calcul de la distance correspondante
- for (int x=0; x<imgWidth; x++)
- tabX[y*imgWidth + x] = unitPix *(x - center);
+ for (int x=0; x<imgWidth_; x++)
+ tabX_[y*imgWidth_ + x] = unitPix *(x - center);
}
-
return 1;
}
-
/// Position d'un objet dans le referentiel du robot
void
-Space::GetLoc(int locImgX, int locImgY, double &locX, double &locY)
+Space::getLoc (const int locImgX, const int locImgY, double &locX, double &locY)
{
// Calcul de locX
- locX = tabX[locImgY*imgWidth + locImgX];
-
+ locX = tabX_[locImgY*imgWidth_ + locImgX];
// Calcul de locY
- locY = aY*locImgY*locImgY + bY*locImgY + cY;
+ locY = aY_*locImgY*locImgY + bY_*locImgY + cY_;
}
-
-
/// Position d'un objet dans le referentiel du robot
void
-Space::GetLoc(int locImgX, int locImgY, int &locX, int &locY)
+Space::getLoc (const int locImgX, const int locImgY, int &locX, int &locY)
{
double x,y;
- GetLoc(locImgX, locImgY, x, y);
+ getLoc (locImgX, locImgY, x, y);
locX = (int)x;
locY = (int)y;
}
-
/// Donne la position reelle sur la table de la balle
/// @param locX, locY : position de la balle dans le rÃfÃrentiel du robot
/// @param posRobotX, posRobotY, angleRobot : position du robot sur la table
/// @param posX, posY : variable de retour pour la position de la balle sur la table
void
-Space::GetPos(double locX, double locY, double posRobotX, double posRobotY, double angleRobot, double &posX, double &posY)
+Space::getPos (const double locX, const double locY, const double posRobotX, const double posRobotY,
+ const double angleRobot, double &posX, double &posY)
{
- double sinus = sin(angleRobot);
- double cosinus = cos(angleRobot);
-
+ double sinus = sin (angleRobot);
+ double cosinus = cos (angleRobot);
// Calcul des coordonnes avec le changement de repere
posX = posRobotX + locX*cosinus - locY*sinus;
posY = posRobotY + locX*sinus + locY*cosinus;
diff --git a/2005/i/robert/src/ovision/see/space.hh b/2005/i/robert/src/ovision/see/space.hh
index 0a3b224..1adaed8 100644
--- a/2005/i/robert/src/ovision/see/space.hh
+++ b/2005/i/robert/src/ovision/see/space.hh
@@ -24,81 +24,56 @@
#define space_h
#include <vector>
-#include <iostream>
-#include <stdio.h>
#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<SETUP_POINT> setupTab;
-
- /// hautdddeur de l'image
- int imgHeight;
-
- /// largeur de l'image
- int imgWidth;
-
- double aY, bY, cY;
+ struct SetupPoint;
+ std::vector<SetupPoint> 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; i<live_->oconfig->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; i++)
+ // Si on recoit une commande de remise a zero de l'index_
+ ss >> nbColorToMerge;
+ if (nbColorToMerge == -1)
{
- ss >> numColorToMerge;
- live_->segm->index_[numColorToMerge] = numIndexColor;
+ for (int i=0; i<live_->oconfig->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<nbColorToMerge; i++)
+ {
+ ss >> 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 << "<Live::updateImg> 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<Zone> 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 <signal.h>
#include <vector>
#include <string>
+#include <sstream>
#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();