From 0d23e95e643ffffd7e2f3788449c34de200e9ff9 Mon Sep 17 00:00:00 2001 From: gaillaro Date: Tue, 11 May 2004 17:59:02 +0000 Subject: precision degressif optimisation findcolorNN debut de poteaux --- 2004/i/nono/src/ovision/group.cc | 77 +++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 20 deletions(-) (limited to '2004/i/nono/src/ovision/group.cc') diff --git a/2004/i/nono/src/ovision/group.cc b/2004/i/nono/src/ovision/group.cc index 3b07e3b..5ffc246 100644 --- a/2004/i/nono/src/ovision/group.cc +++ b/2004/i/nono/src/ovision/group.cc @@ -35,6 +35,11 @@ Group::Group(Img *img, SegmNN *segm) { /// Destructeur Group::~Group() { +} + + +/// Supprime la liste des groupes +void Group::FreeGroups () { ZONE *pCur = zoneListBall; ZONE *pPrev; @@ -54,6 +59,25 @@ Group::~Group() { free(pPrev); } + + zoneListBall = NULL; + zoneListGoal = NULL; +} + + + +/// Construit la table des distances +void Group::DoDeltaTable () +{ + +} + + +/// Retourne le delta utilisé pour la dissociation de 2 balles proches +int Group::GetDelta (int y) +{ +// return 50; + return (int)(20 + y*0.1); } @@ -70,11 +94,17 @@ 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)&& (tabSegm[(++xmax)+y* img->width] == numColor)) {} - while ((xmin > 0) && (tabSegm[(--xmin)+y* img->width] == numColor)) {} - while ((ymax < img->height-1) && (tabSegm[x+(++ymax)* img->width] == numColor)) {} - while ((ymin > 0) && (tabSegm[x+(--ymin)* img->width] == numColor)) {} - + while ((xmax < img->width-1)&& (segm->FindColorNN(img->tabData + ((++xmax)+y* img->width)*3) == numColor)) {} + while ((xmin > 0) && (segm->FindColorNN(img->tabData + ((--xmin)+y* img->width)*3) == numColor)) {} + while ((ymax < img->height-1) && (segm->FindColorNN(img->tabData + (x+(++ymax)* img->width)*3) == numColor)) {} + while ((ymin > 0) && (segm->FindColorNN(img->tabData + (x+(--ymin)* img->width)*3) == numColor)) {} + +/*while ((xmax < img->width-1)&& (tabSegm[(++xmax)+y* img->width] == numColor)) {} +while ((xmin > 0) && (tabSegm[(--xmin)+y* img->width] == numColor)) {} +while ((ymax < img->height-1) && (tabSegm[x+(++ymax)* img->width] == numColor)) {} +while ((ymin > 0) && (tabSegm[x+(--ymin)* img->width] == numColor)) {} +*/ + // Verification la validite des entrees /* if ((xmin < 0) || (xmin > img->width)) xmin = 0; @@ -92,19 +122,23 @@ void Group::Plague(int type, unsigned char numColor, int x, int y) { ZONE *pCur; - if (type == BALL) + if (type == BALL) + { pCur = zoneListBall; + } else if (type == GOAL) { - if (!((pCur->ymin <= 0) && (pCur->ymax >= img->width))) - return; +// if (!((pCur->ymin <= 0) && (pCur->ymax >= img->width))) +// return; pCur = zoneListGoal; } ZONE *pLast=NULL; + int imgY; while (pCur) { + imgY = (pCur->centery + centery) / 2; // si on a deja ce groupe on actualise les donnees du groupe - if ((numColor == pCur->idColor) && (abs(pCur->centerx - centerx) <= PRECISION) && (abs(pCur->centery - centery) <= PRECISION)) { + if ((numColor == pCur->idColor) && (abs(pCur->centerx - centerx) <= GetDelta(imgY)) && (abs(pCur->centery - centery) <= GetDelta(imgY))) { if (xmin < pCur->xmin) pCur->xmin = xmin; if (xmax > pCur->xmax) pCur->xmax = xmax; if (ymin < pCur->ymin) pCur->ymin = ymin; @@ -155,9 +189,6 @@ void Group::Plague(int type, unsigned char numColor, int x, int y) { if ((pLast->xmin <= 0) || (pLast->ymin <= 0) || (pLast->xmax >= img->width) || (pLast->ymax >= img->height)) pLast->partial = 1; else pLast->partial = 0; - - - pLast->next = NULL; } @@ -185,21 +216,27 @@ void Group::ShowZones() { /// Selectionne les points a tester dans l'image /// @param numColor numero de la couleur a trouver -void Group::JumpPoints(unsigned char numColor) { +void Group::JumpPoints(unsigned char numColorBall, unsigned char numColorGoal) { - zoneListBall = NULL; - tabSegm = segm->tabSegm; + FreeGroups (); // Initialisation de la couleur a chercher - numColor = segm->index[numColor]; + numColorBall = segm->index[numColorBall]; + if (numColorGoal != 255) + numColorGoal = segm->index[numColorGoal]; + + int curColor; // Parcours d'une partie des pixels de l'image for (int x=0; xwidth; x+=10) { for (int y=0; yheight; y+=10) { - if (tabSegm[y*img->width+x] == numColor) - { - Plague(BALL, numColor, x, y); - } + // if (tabSegm[y*img->width+x] == numColor) + + curColor = segm->FindColorNN(img->tabData + ((y*img->width+x) * 3)); + if (curColor == numColorBall) + Plague(BALL, numColorBall, x, y); + else if (curColor == numColorGoal) + Plague(GOAL, numColorGoal, x, y); } } -- cgit v1.2.3