/// @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.h" #include /// tableau de couleur utlisation pour la creation de l'image segmentee unsigned char 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}}; /// Constructor ImgInterface ImgInterface::ImgInterface (void) : Img () { } /// Destructor ImgInterface ImgInterface::~ImgInterface (void) { } /// 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 (unsigned char *tabIn, unsigned char *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 des contours autour d'une balle void ImgInterface::DrawBox (unsigned char *tab, ZONE *pCur) { unsigned char *pTabMin, *pTabMax; // Parcours de la liste des groupes while (pCur) { // Affiche les coutours horizontaux pTabMin = &tab[pCur->ymin*width+pCur->xmin]; pTabMax = &tab[pCur->ymax*width+pCur->xmin]; for (int x=pCur->xmin; xxmax; x++) { *pTabMin = 1; *pTabMax = 1; ++pTabMin; ++pTabMax; } // Affiche les courtours verticaux pTabMin = &tab[pCur->ymin*width+pCur->xmin]; pTabMax = &tab[pCur->ymin*width+pCur->xmax]; for (int x=pCur->ymin; xymax; x++) { *pTabMin = 1; *pTabMax = 1; pTabMin += width; pTabMax += width; } // Affiche une croix au centre pTabMin = &tab[pCur->centery*width+pCur->centerx-5]; pTabMax = &tab[(pCur->centery-5)*width+pCur->centerx]; for (int x=0; x<10; x++) { *pTabMin = 1; *pTabMax = 1; ++pTabMin; pTabMax += width; } pCur = pCur->next; } } /// Ajoute des coutours autour des balles trouvées void ImgInterface::AddGroupToDisplay (unsigned char *tab, Group *group) { if (!tab) { std::cerr << "ImgInterface::AddGroupToDisplay tab empty" << std::endl; return; } DrawBox (tab, group->zoneListBall); DrawBox (tab, group->zoneListGoal); }