summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/ovision/group.cc
diff options
context:
space:
mode:
Diffstat (limited to '2004/i/nono/src/ovision/group.cc')
-rw-r--r--2004/i/nono/src/ovision/group.cc249
1 files changed, 142 insertions, 107 deletions
diff --git a/2004/i/nono/src/ovision/group.cc b/2004/i/nono/src/ovision/group.cc
index 9c9c158..c998c5e 100644
--- a/2004/i/nono/src/ovision/group.cc
+++ b/2004/i/nono/src/ovision/group.cc
@@ -17,15 +17,13 @@ using namespace std;
/// @param *img classe image
/// @param *segm classe segmNN
-Group::Group(Img *img, SegmNN *segm) {
+Group::Group (Img *img, SegmNN *segm)
+{
// Sauvegarde des pointeurs
Group::img = img;
Group::segm = segm;
oconfig = OConfig::GetInstance ();
- width = img->width;
- height = img->height;
-
tabOut = NULL;
zoneListBall = NULL;
zoneListGoal = NULL;
@@ -33,12 +31,16 @@ Group::Group(Img *img, SegmNN *segm) {
/// Destructeur
-Group::~Group() {
+Group::~Group ()
+{
+ FreeGroups ();
}
/// Supprime la liste des groupes
-void Group::FreeGroups () {
+void
+Group::FreeGroups ()
+{
ZONE *pCur = zoneListBall;
ZONE *pPrev;
@@ -64,38 +66,103 @@ void Group::FreeGroups () {
}
+/// Ajoute une balle ou un poteau à la liste de groupes
+
+/// @param type type du group à rechercher GOAL ou BALL
+/// @param numColor numéro de la couleur du group
+/// @param xmin,xmax,ymin,ymax borne du group
+/// @param centerx, centery centre du group
+/// @param dernier élément de la liste où empiler
+void
+Group::AddGroup (int type, int numColor, int xmin, int xmax, int ymin, int ymax, int centerx, int centery, ZONE *pLast)
+{
+ if (!pLast)
+ {
+ if (type == BALL)
+ {
+ zoneListBall = new ZONE;
+ pLast = zoneListBall;
+ }
+ else if (type == GOAL)
+ {
+ zoneListGoal = new ZONE;
+ pLast = zoneListGoal;
+ }
+ }
+ else
+ {
+ pLast->next = new ZONE;
+ pLast = pLast->next;
+ }
+
+ pLast->xmin = xmin;
+ pLast->xmax = xmax;
+ pLast->ymin = ymin;
+ pLast->ymax = ymax;
+
+ pLast->centerx = centerx;
+ pLast->centery = centery;
+ pLast->idColor = numColor;
+
+ // test si la balle est vu partiellement ou completement
+ if (pLast->ymax >= img->height - BORD)
+ {
+ pLast->bottom = true;
+ if ((pLast->xmin <= 0) || (pLast->xmax >= img->width) || (pLast->ymin <= 0))
+ pLast->partial = true;
+ else pLast->partial = false;
+ }
+ else
+ {
+ pLast->bottom = false;
+ pLast->partial = false;
+ }
+
+ pLast->next = NULL;
+}
+
+
/// Construit la table des distances
-void Group::DoDeltaTable ()
+void
+Group::DoDeltaTable ()
{
}
/// Retourne le delta utilisé pour la dissociation de 2 balles proches
-int Group::GetDelta (int type, int y)
+/// @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)
{
- // return 50;
-
if (type == BALL)
return (int)(25 + y*0.1);
+
else return 3*(int)(25 + y*0.1);
}
/// Test si la zone trouvé est valide
-bool Group::IsValidZone (int type, int xmin, int xmax, int ymin, int ymax) {
-
-
- // test si la zone trouve un trop petite -> parasite
- if ( (abs(xmin - xmax) < oconfig->minLengthZone) || (abs(ymin - ymax) < oconfig->minLengthZone) )
- return 0;
+/// @param type type du group à rechercher GOAL ou BALL
+/// @param xmin,xmax,ymin,ymax borne du group à valider
+bool
+Group::IsValidZone (int type, int xmin, int xmax, int ymin, int ymax)
+{
if (type == BALL)
{
+ // test si la zone trouve un trop petite -> parasite
+ if ( (abs(xmin - xmax) < oconfig->minLengthZone) || (abs(ymin - ymax) < oconfig->minLengthZone) )
+ return 0;
}
else if (type == GOAL)
{
+ // test si la zone trouve un trop petite -> parasite
+ if ( (abs(xmin - xmax) * (abs(ymin - ymax) < oconfig->minLengthZone*oconfig->minLengthZone/10)))
+ return 0;
+
// test si la zone trouve touche le haut de l'image
if (ymin > 0) return 0;
}
@@ -107,9 +174,11 @@ bool Group::IsValidZone (int type, int xmin, int xmax, int ymin, int ymax) {
/// Cherche l'objet complet a partir d'un pixel donne
+/// @param type type du group à rechercher GOAL ou BALL
/// @param numColor numero de la couleur a chercher
/// @param x,y coordonnees de depart pour la recherche
-void Group::Plague(int type, unsigned char numColor, int x, int y) {
+void Group::Plague (int type, unsigned char numColor, int x, int y)
+{
int xmax = x;
int xmin = x;
int ymax = y;
@@ -117,12 +186,12 @@ void Group::Plague(int type, unsigned char numColor, int x, int y) {
// TODO ajouter une inertie ?
- // Parcours de l'objet trouve de haut en bas
- while ((xmax < img->width-1)&& (segm->FindColorNN(img->tabData + ((++xmax)+y* img->width)*3, 1) == numColor)) {}
- while ((xmin > 0) && (segm->FindColorNN(img->tabData + ((--xmin)+y* img->width)*3, 1) == numColor)) {}
- while ((ymax < img->height-1) && (segm->FindColorNN(img->tabData + (x+(++ymax)* img->width)*3, 1) == numColor)) {}
- while ((ymin > 0) && (segm->FindColorNN(img->tabData + (x+(--ymin)* img->width)*3, 1) == numColor)) {}
-
+ // Parcours de l'objet trouve de haut en bas et de gauche à droite
+ while ((xmax < img->width-1)&& (segm->GiveColor(img->tabData + ((++xmax)+y* img->width)*3, true, true) == numColor)) {}
+ while ((xmin > 0) && (segm->GiveColor(img->tabData + ((--xmin)+y* img->width)*3, true, true) == numColor)) {}
+ while ((ymax < img->height-1) && (segm->GiveColor(img->tabData + (x+(++ymax)* img->width)*3, true, true) == numColor)) {}
+ while ((ymin > 0) && (segm->GiveColor(img->tabData + (x+(--ymin)* img->width)*3, true, true) == numColor)) {}
+
// test si la zone trouve est une zone valide
if (!IsValidZone (type, xmin, xmax, ymin, ymax))
return;
@@ -133,6 +202,7 @@ void Group::Plague(int type, unsigned char numColor, int x, int y) {
pCur = zoneListBall;
else if (type == GOAL)
pCur = zoneListGoal;
+
// Calcul du centre de l'image
int centerx, centery;
@@ -142,10 +212,15 @@ void Group::Plague(int type, unsigned char numColor, int x, int y) {
ZONE *pLast=NULL;
int imgY;
+ int delta;
while (pCur) {
imgY = (pCur->centery + centery) / 2;
+ delta = GetDelta(type, imgY);
+
// si on a deja ce groupe on actualise les donnees du groupe
- if ((numColor == pCur->idColor) && (abs(pCur->centerx - centerx) <= GetDelta(type, imgY)) && (abs(pCur->centery - centery) <= GetDelta(type, imgY))) {
+ if ((numColor == pCur->idColor) && (abs(pCur->centerx - centerx) <= delta)
+ && (abs(pCur->centery - centery) <= delta))
+ {
if (xmin < pCur->xmin) pCur->xmin = xmin;
if (xmax > pCur->xmax) pCur->xmax = xmax;
if (ymin < pCur->ymin) pCur->ymin = ymin;
@@ -163,57 +238,15 @@ void Group::Plague(int type, unsigned char numColor, int x, int y) {
// Si il n'est pas presente on l'ajoute
- if (!pCur) {
- if (!pLast)
- {
- if (type == BALL)
- {
- zoneListBall = new ZONE;
- pLast = zoneListBall;
- }
- else if (type == GOAL)
- {
- zoneListGoal = new ZONE;
- pLast = zoneListGoal;
- }
- }
- else
- {
- pLast->next = new ZONE;
- pLast = pLast->next;
- }
-
- pLast->xmin = xmin;
- pLast->xmax = xmax;
- pLast->ymin = ymin;
- pLast->ymax = ymax;
-
- pLast->centerx = centerx;
- pLast->centery = centery;
- pLast->idColor = numColor;
-
- // test si la balle est vu partiellement ou completement
- if (pLast->ymax >= img->height - BORD)
- {
- pLast->bottom = 1;
- if ((pLast->xmin <= 0) || (pLast->xmax >= img->width) || (pLast->ymin <= 0))
- pLast->partial = 1;
- else pLast->partial = 0;
- }
- else
- {
- pLast->bottom = 0;
- pLast->partial = 0;
- }
-
- pLast->next = NULL;
- }
+ if (!pCur)
+ AddGroup (type, numColor, xmin, xmax, ymin, ymax, centerx, centery, pLast);
}
/// Affiche les zones trouvees
-void Group::ShowZones() {
-
+void
+Group::ShowZones ()
+{
ZONE *pCur = zoneListBall;
cout << "Groupes balles:" << endl;
while(pCur) {
@@ -232,51 +265,41 @@ void Group::ShowZones() {
/// Selectionne les points a tester dans l'image
/// @param numColor numero de la couleur a trouver
-void Group::JumpPoints(unsigned char numColorBall, unsigned char numColorGoal) {
-
+void Group::JumpPoints (unsigned char numColorBall, unsigned char numColorGoal)
+{
FreeGroups ();
// Initialisation de la couleur a chercher
numColorBall = segm->index[numColorBall];
- if (numColorGoal != 255)
+ if (numColorGoal != IS_SET)
numColorGoal = segm->index[numColorGoal];
int curColor;
// Parcours d'une partie des pixels de l'image
- for (int x=0; x<img->width; x+=10) {
- for (int y=0; y<img->height; y+=10) {
- // if (tabSegm[y*img->width+x] == numColor)
-
- curColor = segm->FindColorNN(img->tabData + ((y*img->width+x) * 3));
+ for (int x=0; x<img->width; x+=oconfig->jumpPointDist)
+ for (int y=0; y<img->height; y+=oconfig->jumpPointDist)
+ {
+ curColor = segm->GiveColor (img->tabData + ((y*img->width+x) * 3), true, true);
+
if (curColor == numColorBall)
Plague(BALL, numColorBall, x, y);
else if (curColor == numColorGoal)
Plague(GOAL, numColorGoal, x, y);
}
- }
-
- ZONE *pCur;
- for (int k=0; k<2; k++)
- {
- if (k == 0) pCur = zoneListBall;
- else if (k == 1) pCur = zoneListGoal;
-
- while (pCur)
- {
- pCur->ymax = img->height - pCur->ymax;
- pCur = pCur->next;
- }
- }
-
-
}
/// Creation du tableau de RGB pour faire une image
-void Group::TabOut() {
- ZONE *pCur = zoneListBall;
+void
+Group::TabOut (int type, bool init)
+{
+ ZONE *pCur;
+ if (type == BALL)
+ pCur = zoneListBall;
+ else
+ pCur = zoneListGoal;
// On verifie que des groupes ont ete trouve
if (!pCur) {
@@ -284,17 +307,27 @@ void Group::TabOut() {
if (tabOut) delete [] tabOut;
return;
}
-
- // Allocation de la memoire
- if (tabOut) delete [] tabOut;
- tabOut = new unsigned char[img->nbPixels];
-
- // On initialise le tableau pour une image noire
- for (unsigned int i=0; i<img->nbPixels; i++)
- tabOut[i] = 0;
-
+
+ if (init)
+ {
+ // Allocation de la memoire
+ if (tabOut) delete [] tabOut;
+ tabOut = new unsigned char[img->nbPixels];
+
+ // On initialise le tableau pour une image noire
+ for (unsigned int i=0; i<img->nbPixels; i++)
+ tabOut[i] = 0;
+ }
+ else
+ {
+ // Allocation de la memoire
+ if (!tabOut)
+ tabOut = new unsigned char[img->nbPixels];
+ }
+
// Parcours de la liste des zones trouvees
- while (pCur) {
+ while (pCur)
+ {
// Remplissage de la zone avec une couleur
for(int i=pCur->xmin; i<pCur->xmax; i++)
for (int j=pCur->ymin; j<pCur->ymax; j++)
@@ -302,6 +335,8 @@ void Group::TabOut() {
pCur = pCur->next;
}
+
+ cout << endl;
}