summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/group.cc
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/ovision/see/group.cc')
-rw-r--r--2005/i/robert/src/ovision/see/group.cc140
1 files changed, 140 insertions, 0 deletions
diff --git a/2005/i/robert/src/ovision/see/group.cc b/2005/i/robert/src/ovision/see/group.cc
new file mode 100644
index 0000000..56aaa55
--- /dev/null
+++ b/2005/i/robert/src/ovision/see/group.cc
@@ -0,0 +1,140 @@
+// group.cc - Classe G
+// robert - Programme du robot APBteam
+// Copyright (C) 2005 Olivier Gaillard
+
+/// @file group.cc Cree une liste chainee de zones correspondant aux balles
+#include <iostream>
+#include <stdlib.h>
+#include <math.h>
+
+#include "group.hh"
+
+/// Constructeur
+/// @param *img classe image
+/// @param *segm classe segm
+Group::Group (Img *img, Segm *segm)
+ : segm_ (segm), img_ (img)
+{
+ oconfig_ = OConfig::getInstance ();
+}
+
+/// Ajoute une balle ou un poteau à la liste de groupes
+/// @param idColor numéro de la couleur du group
+/// @param xmin,xmax,ymin,ymax borne du group
+/// @param centerx, centery centre du group
+void
+Group::addZone (const int idColor, const int xmin, const int xmax, const int ymin, const int ymax)
+{
+ Zone zone;
+ zone.xmin = xmin; zone.xmax = xmax;
+ zone.ymin = ymin; zone.ymax = ymax;
+ zone.centerx = (xmax+xmin)/2;
+ zone.centery = (ymax+ymin)/2;
+
+ for (std::vector<ObjectColor>::iterator iter = oconfig_->groupColor.begin ();
+ iter != oconfig_->groupColor.end (); ++iter)
+ if (idColor == iter->color)
+ {
+ if (iter->label == "redSkittle") zone.id = redSkittle;
+ else if (iter->label == "greenSkittle") zone.id = greenSkittle;
+ else if (iter->label == "border") zone.id = border;
+ else if (iter->label == "base") zone.id = base;
+ else if (iter->label == "gap") zone.id = gap;
+ break;
+ }
+
+ zoneList_.push_back (zone);
+}
+
+/// 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 (const unsigned char numColor, const int x, const int y)
+{
+ int xmax = x; int xmin = x;
+ int ymax = y; int ymin = y;
+
+ // TODO ajouter une inertie ?
+
+ int tmpY = y*img_->width_;
+ // Parcours de l'objet trouve de haut en bas et de gauche à droite
+ while ((xmax < img_->width_-1)&& (segm_->giveColor(img_->tabData_ + ((++xmax)+tmpY)*3, true, true) == numColor)) {}
+ while ((xmin > 0) && (segm_->giveColor(img_->tabData_ + ((--xmin)+tmpY)*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)) {}
+
+ // Ajout de la zone
+ addZone (numColor, xmin, xmax, ymin, ymax);
+}
+
+/// Affiche les zones trouvees
+void
+Group::showZones () const
+{
+ std::cout << "Groupes :\n";
+
+ if (!zoneList_.size ())
+ return;
+
+ for (std::vector<Zone>::const_iterator iter = zoneList_.begin (); iter != zoneList_.end (); ++iter)
+ std::cout << (int)iter->id << " " << iter->xmin << " " << iter->xmax << " "
+ << iter->ymin << " " << iter->ymax << "\n";
+ std::cout << std::endl;
+}
+
+
+/// Selectionne les points a tester dans l'image
+/// @param numColor numero de la couleur a trouver
+void Group::jumpPoints (int color)
+{
+ std::vector<ObjectColor> list;
+ ObjectColor obj;
+ obj.label = "undefined";
+ obj.color = color;
+ list.push_back (obj);
+ jumpPoints (list);
+}
+
+void Group::jumpPoints (const std::vector<ObjectColor> &colorList)
+{
+ zoneList_.clear ();
+ segm_->clearLum ();
+ segm_->setMode (img_->colorMode_);
+
+ int tmpY;
+ unsigned char curColor;
+ std::vector<ObjectColor>::const_iterator iter;
+ // Parcours d'une partie des pixels de l'image
+ for (int y=0; y<img_->height_; y+=oconfig_->jumpPointDist)
+ {
+ tmpY = y*img_->width_;
+ for (int x=0; x<img_->width_; x+=oconfig_->jumpPointDist)
+ {
+ curColor = segm_->giveColor (img_->tabData_ + ((tmpY + x) * 3), true, true);
+
+ for (iter = colorList.begin (); iter != colorList.end (); ++iter)
+ if ((iter->color >= 0) && (iter->color == curColor))
+ {
+ plague(curColor, x, y);
+ break;
+ }
+ }
+ }
+ std::cout << "<Group::jumpPoints> Luminosité : " << segm_->getLum () << std::endl;
+}
+
+/// Convertit le label de couleur en nombre
+std::string
+Group::translateToColorName (const int color)
+{
+ std::string label;
+ if (color == Group::redSkittle) label = "redSkittle";
+ else if (color == Group::greenSkittle) label = "greenSkittle";
+ else if (color == Group::gap) label = "gap";
+ else if (color == Group::border) label = "border";
+ else if (color == Group::base) label = "base";
+ else label = "undefined";
+ return label;
+}
+