summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/oconfig.cc
diff options
context:
space:
mode:
authorgaillaro2005-04-05 18:26:18 +0000
committergaillaro2005-04-05 18:26:18 +0000
commit97b69507c877a4644c0caac4f61e052e188f9d8e (patch)
tree1a81f341ab6577003fa60ca3fb135e7b4baeecba /2005/i/robert/src/ovision/see/oconfig.cc
parent0062520c9cc87eeeb8828361bbb33033a6f07b7e (diff)
Renaissance de la vision :
- code standard robot - presque du C++ - apprentissage du RN sur plusieurs images - tableau de données couleurs compressé - reconnaissance de plusieurs objets possibles
Diffstat (limited to '2005/i/robert/src/ovision/see/oconfig.cc')
-rw-r--r--2005/i/robert/src/ovision/see/oconfig.cc238
1 files changed, 238 insertions, 0 deletions
diff --git a/2005/i/robert/src/ovision/see/oconfig.cc b/2005/i/robert/src/ovision/see/oconfig.cc
new file mode 100644
index 0000000..784d031
--- /dev/null
+++ b/2005/i/robert/src/ovision/see/oconfig.cc
@@ -0,0 +1,238 @@
+// config.cc - Classe OConfig
+// robert - Programme du robot APBteam
+// Copyright (C) 2005 Olivier Gaillard
+
+/// @file config.cc Charge le fichier config et distribue les variables
+
+#include <iostream>
+#include <fstream>
+#include <stdlib.h>
+#include <stdio.h>
+#include <sstream>
+
+#include "oconfig.hh"
+
+OConfig *OConfig::instance = 0;
+
+/// Constructor
+/// @param *filename nom du fichier de config
+OConfig::OConfig(const char *filename)
+ : node (0), color (0), index (0)
+{
+ instance = this;
+ load (filename);
+ loadNNFile("rc/poids");
+ loadDistFile("rc/dist");
+}
+
+/// Destructor
+OConfig::~OConfig()
+{
+}
+
+/// Parse une ligne du fichier de config
+/// @param *var nom de la variable a fixer
+/// @param *arg valeur de la variable
+void
+OConfig::parse(const char *var, const char *arg)
+{
+ if (!arg) throw "OConfig::parse : Error during config file parsing";
+ std::string varName (var);
+ if (varName == "Cam_color")
+ {
+ std::string argName (arg);
+ if (argName == "RGB") inputColor = Image::rgb;
+ else if (argName == "BGR") inputColor = Image::bgr;
+ else if (argName == "YUV") inputColor = Image::yuv;
+ else if (argName == "HSI") inputColor = Image::hsi;
+ return;
+ }
+ // Affecte la valeur de arg a la variable varName
+ if (varName == "NN_step_learning") nnSl = atof(arg);
+ else if (varName == "NN_neighborhood_learning") nnNl = atof(arg);
+ else if (varName == "NN_number_of_iteration_learning") nnNil = atol(arg);
+ else if (varName == "NN_number_of_color_to_segment") nnNbColor = atoi(arg);
+ else if (varName == "NN_threshold_output") nnThresholdOutput = atoi(arg);
+ else if (varName == "NN_lum_inosity_influence") nnInfluLum = atof(arg);
+ else if (varName == "UI_img_path ") strcpy(imgPath, arg);
+ else if (varName == "NN_lazy_threshold") nnLazyThreshold = atoi(arg);
+// else if (varName == "Map_error") mapError = atoi(arg);
+// else if (varName == "Map_error_part") mapErrorPart = atoi(arg);
+// else if (varName == "Map_angle_ball_weight") angleBallWeight= atoi(arg);
+// else if (varName == "Map_distance_ball_robot_weight") distanceBallRobotWeight = atoi(arg);
+// else if (varName == "Map_distance_ball_goal_weight") distanceBallGoalWeight = atoi(arg);
+// else if (varName == "Map_ball_density_weight") ballDensityWeight = atoi(arg);
+// else if (varName == "Map_ennemy_presence_weight") ennemyPresenceWeight = atoi(arg);
+// else if (varName == "Map_ball_precision_weight") ballPrecisionWeight = atoi(arg);
+// else if (varName == "Map_skepticism_weight") skepticismWeight = atoi(arg);
+// else if (varName == "Map_skepticism_max") skepticismMax = atoi(arg);
+// else if (varName == "Map_ball_lost_weight") ballLostWeight = atoi(arg);
+// else if (varName == "Map_ball_bottom_time_out") ballBottomTimeOut = atoi(arg);
+ else if (varName == "Group_minimum_length_zone") minLengthZone = atoi(arg);
+ else if (varName == "Group_jump_point_distance") jumpPointDist = atoi(arg);
+ else if (varName == "UI_group_to_display") uiGroupToDisplay = atoi(arg);
+}
+
+/// Charge les variables du fichier de configuration (par défaut rc/vision.conf)
+void
+OConfig::load (const char *filename)
+{
+ const int NBARG = 3;
+ char *cut[NBARG] = {0};
+ FILE *file;
+ char ligne[50];
+ int i;
+ // Ouverture du fichier de conf
+ file = fopen(filename, "r");
+ if (!file) throw "OConfig::OConfig : Error during config file opening";
+ else std::cout << "Lecture du ficher de configuration" << std::endl;
+ // Parcours des lignes et analyse
+ while(fgets(ligne, 50, file))
+ {
+ if (ligne[0] == '#') continue;
+ // Division du string
+ cut[0] = strtok(ligne, " \n");
+ if (!cut[0]) continue;
+ i=0;
+ while ((cut[i] != 0) && (i<(NBARG-1)))
+ {
+ i++;
+ cut[i] = strtok( 0, " \t\n");
+ }
+ parse(cut[0], cut[2]);
+ }
+}
+
+/// Chargement des poids d'un reseau de neurones
+/// @param *filePath nom du fichier de poids a charger
+void
+OConfig::loadNNFile (const char *filePath)
+{
+ const int maxChar = 50;
+ // Ouverture du fichier de conf
+ std::ifstream file (filePath);
+ if (!file)
+ {
+ throw "OConfig::LoadNNFile : Error during poids file opening";
+ return;
+ }
+ // Chargement des couleurs
+ char buf [maxChar];
+ while (!file.eof ())
+ {
+ file.getline (buf, maxChar);
+ std::string line (buf);
+ if (line.find("#index") != std::string::npos)
+ break;
+ if (buf[0] == '\0' || buf[0] == ' ' || buf[0] == '\n'
+ || buf[0] == '\t' || buf[0] == '#') continue;
+ std::istringstream iss (buf);
+ ObjectColor tmp;
+ iss >> tmp.label >> tmp.color;
+ groupColor.push_back (tmp);
+ }
+ // Chargement des poids
+ std::vector<int> tmpNode, tmpIndex;
+ int tmp;
+ while (!file.eof ())
+ {
+ file.getline (buf, maxChar);
+ std::istringstream iss (buf);
+ if (buf[0] == '\0' || buf[0] == ' ' || buf[0] == '\n'
+ || buf[0] == '\t' || buf[0] == '#') continue;
+ iss >> tmp;
+ tmpIndex.push_back (tmp);
+ for (int i=0; i<3; i++)
+ {
+ iss >> tmp;
+ tmpNode.push_back (tmp);
+ }
+ }
+ file.close ();
+ // Recopie dans des tableaux
+ delete [] node;
+ node = new unsigned char[tmpNode.size ()];
+ for (unsigned int i=0; i<tmpNode.size (); ++i)
+ node[i] = (unsigned char)tmpNode[i];
+ delete [] index;
+ index = new int[tmpIndex.size ()];
+ for (unsigned int i=0; i<tmpIndex.size (); ++i)
+ index[i] = (unsigned char)tmpIndex[i];
+ nnNbNodeMax = tmpIndex.size ();
+}
+
+/// Creation d'un fichier de poids pour le reseau de neurones
+/// @param *filename nom du fichier a creer
+/// @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
+{
+ if (!node)
+ {
+ throw "OConfig::CreateNNFile : NN non initialisé";
+ return;
+ }
+ // Ecriture dans un fichier
+ std::ofstream file (filename);
+ // Couleurs
+ for (std::vector<ObjectColor>::const_iterator i = groupColor.begin (); i < groupColor.end (); ++i)
+ file << i->label << " " << i->color << "\n";
+ // Poids
+ file << "#index\t#x1\tx2\tx3\n";
+ for (int i=0; i<nbOutput_; i++)
+ {
+ file << index[i] << "\t";
+ for (int j=0; j<3; j++)
+ file << node[i*3+j] << "\t";
+ file << "\n";
+ }
+ file.close ();
+}
+
+/// Chargement de la liste des points pour les distances
+void
+OConfig::loadDistFile (const char *filename)
+{
+ // Ouverture du fichier de distance
+ std::ifstream file (filename);
+ if (!file) {
+ throw "OConfig::LoadDistFile : Error during poids file opening";
+ return;
+ }
+ // Parcours des lignes et analyse
+ char buf[50];
+ int point[4];
+ while (!file.eof () && file.getline (buf, 50))
+ if ((buf[0] >= '0') && (buf[0] <= '9'))
+ {
+ sscanf(buf, "%i\t%i\t%i\t%i\n", &point[0], &point[1], &point[2], &point[3]);
+ spaceTabPoint.push_back(point[0]);
+ spaceTabPoint.push_back(point[1]);
+ spaceTabPoint.push_back(point[2]);
+ spaceTabPoint.push_back(point[3]);
+ }
+ file.close ();
+ // Nombre de points venant d'être chargés
+ spaceNbDistPoint = spaceTabPoint.size () / 4;
+}
+
+/// Creation d'un fichier pour la liste des points pour les distances
+void
+OConfig::createDistFile (const char *filename, const int numPoint) const
+{
+ if (spaceTabPoint.size () == 0)
+ {
+ throw "OConfig::CreateDistFile : spaceTabPoint vide";
+ return;
+ }
+ // Ecriture dans un fichier
+ std::ofstream file (filename);
+ // Remplissage du fichier
+ file << "#imgX\timgY\tdistX\tdistY\n";
+ for (int i=0; i<numPoint; i++)
+ file << spaceTabPoint[i*4+0] << "\t" << spaceTabPoint[i*4+1] << "\t"
+ << spaceTabPoint[i*4+2] << "\t" << spaceTabPoint[i*4+3] << "\n";
+ file.close ();
+}
+