// segmTh.cc - Classe Segmentation // nono - Programme du robot Efrei Robotique I1-I2 2004 // Copyright (C) 2004 Olivier Gaillard #include "segmTh.h" #include #include using namespace std; SegmTh::SegmTh(Img *img, OConfig *config) { SegmTh::img = img; SegmTh::config = config; nbOutput = config->nn_NbCouleurs; tabSegm = NULL; } SegmTh::~SegmTh() { } void SegmTh::CreateThresholds(char *filename, unsigned char *node) { int weight[nbOutput][3]; int seuil[nbOutput][3][2]; int tmp; if (!node) { cerr << "SegmTh::CreateThresholds : NN non initialisé\n"; return; } // Classement des seuils par ordre croissant for (int comp=0; comp<3; comp++) { // Tri par insertion pour les 3 composantes avec un tableau d'index for(int i=0; i0) && (node[weight[j][comp]*3+comp] < node[weight[j-1][comp]*3+comp])) { tmp = weight[j-1][comp]; weight[j-1][comp]=weight[j][comp]; weight[j][comp]=tmp; j--; } } } // Formation des seuils for (int comp=0; comp<3 ; comp++) { for (int i=0; icolor[i*6]; // On test pour savoir si la couleur correspond au seuils if (x[0] >= pColor[0] && x[0] <= pColor[1] && x[1] >= pColor[2] && x[1] <= pColor[3] && x[2] >= pColor[4] && x[2] <= pColor[5]) return i; } // Si aucune couleur ne correspond return nbOutput; } void SegmTh::Segm () { if (tabSegm) delete [] tabSegm; tabSegm = new unsigned char[img->nbPixels]; if (config->nbCouleurMax < nbOutput) { cerr << "SegmTh::Segm : Nb de couleurs dans le fichier threshold insuffisante\n"; return; } // Parcours de l'image et détermination de la couleur for (int i=0; i<(int)(img->nbPixels); i++) { tabSegm[i] = FindzoneTh(img->tabData+i*3); } }