summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/imgInterface.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/imgInterface.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/imgInterface.cc')
-rw-r--r--2005/i/robert/src/ovision/see/imgInterface.cc160
1 files changed, 160 insertions, 0 deletions
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 <iostream>
+#include <vector>
+
+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<Zone> &list)
+{
+ unsigned char *pTabMin, *pTabMax;
+ // Parcours de la liste des groupes
+ for (std::vector<Zone>::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; x<iter->xmax; 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; x<iter->ymax; 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<Zone> &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<height_; ++i)
+ {
+ memcpy (buf, &tabData_[i*totalWidth], totalWidth);
+ for (int j=0; j<width_; ++j)
+ {
+ tabData_[i*totalWidth+j*3+2] = buf[totalWidth-j*3+2];
+ tabData_[i*totalWidth+j*3+1] = buf[totalWidth-j*3+1];
+ tabData_[i*totalWidth+j*3] = buf[totalWidth-j*3];
+ }
+ }
+}
+
+/// Creation du tableau de RGB pour faire une image
+void
+ImgInterface::doGroupImg (const std::vector<Zone> &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<nbPixels_; i++)
+ tabSegm_[i] = 0;
+ }
+ else
+ {
+ // Allocation de la memoire
+ if (!tabSegm_)
+ tabSegm_ = new unsigned char[nbPixels_];
+ }
+ // Parcours de la liste des zones trouvees
+ for (std::vector<Zone>::const_iterator iter = zoneList.begin ();
+ iter < zoneList.end (); ++iter)
+ // Remplissage de la zone avec une couleur
+ for(int i=iter->xmin; i<iter->xmax; i++)
+ for (int j=iter->ymin; j<iter->ymax; j++)
+ tabSegm_[j*width_+i] = iter->id+1;
+ std::cout << std::endl;
+}