summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/magnifier.cc
blob: c528444dc54406d99703151dc2f0e87cdea28ef2 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// magnifier.cc - Classe Magnifier
// robert - Programme du robot APBteam
// Copyright (C) 2005 Olivier Gaillard

/// @file magnifier.cc Filtre la liste d'objets trouv�es  

#include <iostream>

#include "magnifier.hh"
#include "skittle.hh"
    
/// Constructeur
Magnifier::Magnifier (Img *img, Segm *segm)
    : segm_ (segm), img_ (img)
{
    oconfig_ = OConfig::getInstance (); 
    itemList_ = new std::vector<Zone>[Group::nbZoneType];
}

/// Destructeur
Magnifier::~Magnifier (void)
{
    delete [] itemList_;
}


// XXX getdelta XXX
/// Retourne le delta utilis� pour la dissociation de 2 balles proches
/// @param type type du group � rechercher GOAL ou BALL
/// @param y coordonnees de la hauteur de la balle 
/*int 
Group::GetDelta (int type, int y)
{
    if (type == BALL)
	return (int)(25 + y*0.1);
    
    else return 3*(int)(25 + y*0.1);
}
*/

/// Analyse une liste de zones
/// @param zoneList liste des zones extraites par la classe group
void
Magnifier::analyse (std::vector<Zone> &zoneList) 
{
    // remise � z�ro de toutes les listes
    for (int i=0; i<Group::nbZoneType; ++i)
	itemList_[i].clear ();
    // parcours de toutes les zones extraites
    for(std::vector<Zone>::iterator iter = zoneList.begin (); iter != zoneList.end (); ++iter)
      {
	// on vire si trop petit
	// XXX test avec l'aire ? 
	//if (((iter->xmax - (iter->xmin)) * (iter->ymax - iter->ymin)) < oconfig_->
	if (((iter->xmax - iter->xmin) < oconfig_->minLengthZone)
	    || ((iter->ymax - iter->ymin) < oconfig_->minLengthZone))
	    continue;
	// V�rifie qu'il n'y a pas de doublon
	if (!checkIsUnique (*iter))
	    continue;
	switch (iter->id)
	  {
	  case Group::redSkittle:
	    if (isRedSkittle (*iter)) addItem (*iter);
	    break;
	  case Group::greenSkittle:
	    if (isGreenSkittle (*iter)) addItem (*iter);
	    break;
	  case Group::base:
	    if (isBase (*iter)) addItem (*iter);
	    break;
	  case Group::gap:
	    if (isGap (*iter)) addItem (*iter);
	    break;
	  case Group::border:
	    if (isBorder (*iter)) addItem (*iter);
	    break;
	  case Group::reflectBand:
	    addItem (*iter);
	    break;
	  }
      }
    if (itemList_[Group::redSkittle].size () != 0)
      {
	Zone &z = itemList_[Group::redSkittle][0];
	isSkittle (z);
      }
}


/// Test si l'object s'agit d'un doublon
bool
Magnifier::checkIsUnique (const Zone &zone)
{
    const int uniqueness = 200;
    for (std::vector<Zone>::iterator iter = itemList_[zone.id].begin ();
	 iter != itemList_[zone.id].end (); ++iter)
	if ((abs (zone.centerx - iter->centerx) < uniqueness)
	    || (abs (zone.centery - iter->centery) < uniqueness))
	  {
	    // on met a jour les donn�es de l'item d�j� trouv�
	    if (zone.xmin < iter->xmin) iter->xmin = zone.xmin;
	    if (zone.ymin < iter->ymin) iter->ymin = zone.ymin;
	    if (zone.xmax > iter->xmax) iter->xmax = zone.xmax;
	    if (zone.ymax > iter->ymax) iter->ymax = zone.ymax;
	    iter->centerx = (iter->xmax + iter->xmin) / 2;
	    iter->centery = (iter->ymax + iter->ymin) / 2;
	    return false;
	  }
    return true;
}

/// Test si l'objet est une quille    
bool 
Magnifier::isSkittle (Zone &zone)
{
    Skittle s (img_, segm_);
    s.analyse (zone, itemList_[Group::reflectBand]);
    s.show ();
    return true;
}

/// Test si l'objet est une quille rouge
bool 
Magnifier::isRedSkittle (const Zone &zone) const
{
    return true;
}

/// Test si l'objet est une bordure
bool 
Magnifier::isBorder (const Zone &zone) const
{
    // test si la zone touche au moins deux bords de l'image
    /// XXX pas tout � fait vrai pr�s du foss�
    unsigned count = 0;
    if (zone.xmin <= 0) ++count;
    if (zone.ymin <= 0) ++count;
    if (zone.xmax >= img_->width_) ++count;
    if (zone.ymax <= img_->height_) ++count;
    if (count < 2) return false;
    return true;
}


/// Test si l'objet est une quille verte
bool 
Magnifier::isGreenSkittle (const Zone &zone) const
{
    return true;
}

/// Test si l'objet est un socle
bool
Magnifier::isBase (const Zone &zone) const
{
    return true;
}

/// Test si l'objet est un foss�e
bool
Magnifier::isGap (const Zone &zone) const
{
    return true;
}

/// Ajout d'un objet

void
Magnifier::addItem (Zone &zone)
{
    // TODO remplir les flags : partial, ...
    zone.area = (zone.xmax - zone.xmin) * (zone.ymax - zone.ymin);    
    itemList_[zone.id].push_back (zone);
}


/// Affiche les zones trouvees apr�s analyse
void
Magnifier::showItems (const Group::ZoneType type) const
{
    std::cout << "Items :\n";
    for (std::vector<Zone>::const_iterator iter = itemList_[type].begin (); iter != itemList_[type].end (); ++iter)
	std::cout << (int)iter->id << " " << iter->xmin << " " << iter->xmax << " " 
	    << iter->ymin << " " << iter->ymax << "\n";
    std::cout << std::endl;
}