summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/ovision/imgInterface.cc
blob: c947404f30ab300b0d585b6f7795aa347a54326d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/// @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 <iostream>

/// 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; x<pCur->xmax; 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; x<pCur->ymax; 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);
}