summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/ovision/segmTable.cc
diff options
context:
space:
mode:
Diffstat (limited to '2004/i/nono/src/ovision/segmTable.cc')
-rw-r--r--2004/i/nono/src/ovision/segmTable.cc109
1 files changed, 109 insertions, 0 deletions
diff --git a/2004/i/nono/src/ovision/segmTable.cc b/2004/i/nono/src/ovision/segmTable.cc
new file mode 100644
index 0000000..e4b4b9e
--- /dev/null
+++ b/2004/i/nono/src/ovision/segmTable.cc
@@ -0,0 +1,109 @@
+// segmTable.cc - Classe Segmentation
+// nono - Programme du robot Efrei Robotique I1-I2 2004
+// Copyright (C) 2004 Olivier Gaillard
+
+/// @file segmTable.cc Segmente l'image et cree un tableau contenant des valeurs segmentees, creation du reseau de neurones
+#include "segmTable.h"
+#include <fstream>
+#include <iostream>
+
+static const int COLOR_TAB_SIZE = 256;
+static const int COLOR_TAB_SIZE_2 = COLOR_TAB_SIZE*COLOR_TAB_SIZE;
+static const int COLOR_TAB_SIZE_TOTAL = COLOR_TAB_SIZE_2*COLOR_TAB_SIZE;
+
+/// Constructor SegmTable
+
+/// @param img classe img permettant d'acceder au donnees de l'image a traiter
+/// @param oconfig classe oconfig permettant d'acceder aux variables de oconfiguration
+SegmTable::SegmTable (Img *img, bool loadFromFile) : SegmNN (img)
+{
+ if (loadFromFile)
+ LoadColorTableFile ();
+ else
+ colorTable = NULL;
+}
+
+
+/// Destructor SegmTable
+SegmTable::~SegmTable ()
+{
+ delete [] colorTable;
+}
+
+
+/// Cree un tableau des couleurs segmentées pour ne plus faire de calcul
+/// et augmenter la rapidité
+/// @param testOutputMax choix de l'utilisation d'un sueil maxi pour la sortie pour éviter qu'une couleur trop différente soit attribuer à une autre couleur
+void
+SegmTable::DoColorTable (bool testOutputMax)
+{
+ unsigned char x[3];
+
+ delete [] colorTable;
+ colorTable = new unsigned char[COLOR_TAB_SIZE_TOTAL];
+
+ // Parcours de toutes les valeurs possibles
+ for (int i=0; i<COLOR_TAB_SIZE; i++)
+ for (int j=0; j<COLOR_TAB_SIZE; j++)
+ for (int k=0; k<COLOR_TAB_SIZE; k++)
+ {
+ // Remplissage de la table
+ x[0]=i; x[1]=j; x[2]=k;
+ colorTable[ i*COLOR_TAB_SIZE_2 + j*COLOR_TAB_SIZE +k ] = FindColorNN (x , testOutputMax);
+ }
+}
+
+
+/// Donne la couleur à partir du tableau
+/// @param *x pointeur vers un tableau contenant une valeur RGB
+unsigned char
+SegmTable::GiveColor (unsigned char *x, bool testOutputMax, bool indexProcess)
+{
+// if (indexProcess)
+ return index [colorTable[ x[0]*COLOR_TAB_SIZE_2 + x[1]*COLOR_TAB_SIZE + x[2] ]];
+// else
+// return colorTable[ x[0]*COLOR_TAB_SIZE_2 + x[1]*COLOR_TAB_SIZE + x[2] ];
+}
+
+
+/// Cree un fichier de ColorTable
+void
+SegmTable::CreateColorTableFile (char *filename)
+{
+ std::ofstream file;
+
+ file.open (filename);
+
+ if (file)
+ file.write ((char*)colorTable, COLOR_TAB_SIZE_TOTAL);
+ else
+ std::cerr << "SegmTable::CreateColorTableFile Erreur d'ouverture de fichier" << std::endl;
+
+ file.close ();
+}
+
+
+
+
+/// Charge un fichier de ColorTable
+bool
+SegmTable::LoadColorTableFile (char *filename)
+{
+ delete [] colorTable;
+ colorTable = new unsigned char[COLOR_TAB_SIZE_TOTAL];
+
+ std::ifstream file;
+ file.open (filename);
+
+ if (file)
+ file.read ((char*)colorTable, COLOR_TAB_SIZE_TOTAL);
+ else
+ {
+ std::cerr << "SegmTable::LoadColorTableFile Erreur d'ouverture de fichier" << std::endl;
+ return 0;
+ }
+
+ file.close ();
+ return 1;
+}
+