From 97b69507c877a4644c0caac4f61e052e188f9d8e Mon Sep 17 00:00:00 2001 From: gaillaro Date: Tue, 5 Apr 2005 18:26:18 +0000 Subject: 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 --- 2005/i/robert/src/ovision/see/imgInterface.cc | 160 ++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 2005/i/robert/src/ovision/see/imgInterface.cc (limited to '2005/i/robert/src/ovision/see/imgInterface.cc') diff --git a/2005/i/robert/src/ovision/see/imgInterface.cc b/2005/i/robert/src/ovision/see/imgInterface.cc new file mode 100644 index 0000000..bafe0b3 --- /dev/null +++ b/2005/i/robert/src/ovision/see/imgInterface.cc @@ -0,0 +1,160 @@ + +/// @file imgInterface.cc Chargement des images, conversion en YUV, HSI, detection des contours, transformation d'une image segmentee en RGB, ecriture de l'image sur le disque + +#include "imgInterface.hh" +#include +#include + +const unsigned char ImgInterface::tabCol_[9][3] = + {{0, 0, 0}, {255, 255, 255},{0, 0, 255}, + {0,255,0}, {255, 0, 0}, {0, 150, 60}, + {150,60,0}, {0, 150, 60}, {20, 50, 120}}; + +/// Constructeur +ImgInterface::ImgInterface () + : tabOut_ (0) +{} + +/// Cree un tableau en RGB pour l'affichage a partir d'une image segmentee +/// @param *tabIn pointeur vers un tableau de donnees segmentees +/// @param *tabOut_ pointeur vers un tableau de donnees RGB +void +ImgInterface::doImg (const unsigned char *tabIn) +{ + /// Initialise les données + if (!tabIn) tabIn = tabSegm_; + delete [] tabOut_; + tabOut_ = new unsigned char [nbPixels_ * 3]; + /// Remplissage de tabOut + if (tabIn) + { + // Change les couleurs segmentees en valeurs RGB pour l'affichage + for (int i=0; i<(int)(nbPixels_);i++) + { + tabOut_[i*3] = tabCol_[tabIn[i]][0]; + tabOut_[i*3+1] = tabCol_[tabIn[i]][1]; + tabOut_[i*3+2] = tabCol_[tabIn[i]][2]; + } + } + else + { + // Si la table donnee est vide on renvoie des couleurs noires + for (int i=0; i<(int)(nbPixels_);i++) + { + tabOut_[i*3] = 0; + tabOut_[i*3+1] = 0; + tabOut_[i*3+2] = 0; + } + } +} + + +/// Dessine les contours autour d'un objet +void +ImgInterface::drawBox (unsigned char *tab, const std::vector &list) +{ + unsigned char *pTabMin, *pTabMax; + // Parcours de la liste des groupes + for (std::vector::const_iterator iter = list.begin (); iter != list.end (); ++iter) + { + // Affiche les coutours horizontaux + pTabMin = &tab[iter->ymin*width_+iter->xmin]; + pTabMax = &tab[iter->ymax*width_+iter->xmin]; + for (int x=iter->xmin; xxmax; x++) + { + *pTabMin = 1; + *pTabMax = 1; + ++pTabMin; + ++pTabMax; + } + // Affiche les courtours verticaux + pTabMin = &tab[iter->ymin*width_+iter->xmin]; + pTabMax = &tab[iter->ymin*width_+iter->xmax]; + for (int x=iter->ymin; xymax; x++) + { + *pTabMin = 1; + *pTabMax = 1; + pTabMin += width_; + pTabMax += width_; + } + + // Affiche une croix au centre + pTabMin = &tab[iter->centery*width_+iter->centerx-5]; + pTabMax = &tab[(iter->centery-5)*width_+iter->centerx]; + for (int x=0; x<10; x++) + { + *pTabMin = 1; + *pTabMax = 1; + ++pTabMin; + pTabMax += width_; + } + } +} + +/// Ajoute des coutours autour des objets trouvées +void +ImgInterface::addGroupToDisplay (unsigned char *tab, const std::vector &list) +{ + if (!tab) + { + std::cerr << "ImgInterface::AddGroupToDisplay tab empty" << std::endl; + return; + } + drawBox (tab, list); +} + + +/// Mirroir l'image +void +ImgInterface::mirror () +{ + const int totalWidth = width_*3; + unsigned char buf[totalWidth]; + /// Inverse l'image + for (int i=0; i &zoneList, bool init) +{ + // On verifie que des groupes ont ete trouve + if (zoneList.empty ()) { + std::cerr << "ImgInterface::doGroupImg: No group defined" << std::endl; + delete [] tabSegm_; + tabSegm_ = 0; + return; + } + if (init) + { + // Allocation de la memoire + delete [] tabSegm_; + tabSegm_ = new unsigned char[nbPixels_]; + // On initialise le tableau pour une image noire + for (unsigned int i=0; i::const_iterator iter = zoneList.begin (); + iter < zoneList.end (); ++iter) + // Remplissage de la zone avec une couleur + for(int i=iter->xmin; ixmax; i++) + for (int j=iter->ymin; jymax; j++) + tabSegm_[j*width_+i] = iter->id+1; + std::cout << std::endl; +} -- cgit v1.2.3