From 03757ce89faca704969118b6a229ad4963c55a19 Mon Sep 17 00:00:00 2001 From: gaillaro Date: Sun, 1 May 2005 11:18:21 +0000 Subject: * reglage de l'influence du yuv * integration de la nouvelle camera --- 2005/i/robert/src/ovision/see/group.cc | 19 +++++++++++++------ 2005/i/robert/src/ovision/see/group.hh | 2 ++ 2005/i/robert/src/ovision/see/img.cc | 22 ++++++++++++++++++++-- 2005/i/robert/src/ovision/see/img.hh | 9 ++++++++- 2005/i/robert/src/ovision/see/magnifier.cc | 12 ++++++------ 2005/i/robert/src/ovision/see/map.cc | 4 ++-- 2005/i/robert/src/ovision/see/n2ml.cc | 2 +- 2005/i/robert/src/ovision/see/oconfig.cc | 8 +++++--- 2005/i/robert/src/ovision/see/oconfig.hh | 2 ++ 2005/i/robert/src/ovision/see/ovision.cc | 4 ++-- 2005/i/robert/src/ovision/see/segmLearn.cc | 6 +++--- 2005/i/robert/src/ovision/see/skittle.cc | 16 ++++++++++------ 2005/i/robert/src/ovision/see/skittle.hh | 2 ++ 2005/i/robert/src/ovision/see/test_colortable.cc | 2 +- 2005/i/robert/src/ovision/see/test_group.cc | 2 +- 2005/i/robert/src/ovision/see/test_img.cc | 2 +- 2005/i/robert/src/ovision/see/test_magnifier.cc | 2 +- 2005/i/robert/src/ovision/see/test_segm.cc | 2 +- 18 files changed, 81 insertions(+), 37 deletions(-) (limited to '2005') diff --git a/2005/i/robert/src/ovision/see/group.cc b/2005/i/robert/src/ovision/see/group.cc index 0fd8670..eee05bb 100644 --- a/2005/i/robert/src/ovision/see/group.cc +++ b/2005/i/robert/src/ovision/see/group.cc @@ -1,4 +1,4 @@ -// group.cc - Classe G +// group.cc - Classe Group // robert - Programme du robot APBteam // Copyright (C) 2005 Olivier Gaillard @@ -30,7 +30,13 @@ Group::addZone (const int idColor, const int xmin, const int xmax, const int ymi zone.ymin = ymin; zone.ymax = ymax; zone.centerx = (xmax+xmin)/2; zone.centery = (ymax+ymin)/2; + // XXX test avec l'aire ? + // test si la zone est assez grande + if (((xmax - xmin) < oconfig_->minLengthZone) + || ((ymax - ymin) < oconfig_->minLengthZone)) + return; zone.color = idColor; + zone.circleUp = false; for (std::vector::iterator iter = oconfig_->groupColor.begin (); iter != oconfig_->groupColor.end (); ++iter) if (idColor == iter->color) @@ -57,12 +63,13 @@ void Group::plague (const unsigned char numColor, const int x, const int y) // TODO ajouter une inertie ? - int tmpY = y*img_->width_; + int tmpY = img_->tabY_[y]; // 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)) {} + const int j = 2; + while ((xmax < img_->width_-1)&& (segm_->giveColor(img_->tabData_ + ((xmax)+tmpY)*3, true, true) == numColor)) {xmax += j;} + while ((xmin > 0) && (segm_->giveColor(img_->tabData_ + ((xmin)+tmpY)*3, true, true) == numColor)) {xmin -= j;} + while ((ymax < img_->height_-1) && (segm_->giveColor(img_->tabData_ + (img_->tabY_[ymax] + x)*3, true, true) == numColor)) {ymax +=j;} + while ((ymin > 0) && (segm_->giveColor(img_->tabData_ + (img_->tabY_[ymin]+x)*3, true, true) == numColor)) {ymin -= j;} // Ajout de la zone addZone (numColor, xmin, xmax, ymin, ymax); diff --git a/2005/i/robert/src/ovision/see/group.hh b/2005/i/robert/src/ovision/see/group.hh index d84328b..6cd62d8 100644 --- a/2005/i/robert/src/ovision/see/group.hh +++ b/2005/i/robert/src/ovision/see/group.hh @@ -59,6 +59,8 @@ struct Zone double pcX, pcY; /// density double density; + /// autre critère de verticalité + bool circleUp; }; /// Cree une liste chainee de zones correspondant aux balles diff --git a/2005/i/robert/src/ovision/see/img.cc b/2005/i/robert/src/ovision/see/img.cc index 52ce584..fa38e4a 100644 --- a/2005/i/robert/src/ovision/see/img.cc +++ b/2005/i/robert/src/ovision/see/img.cc @@ -11,7 +11,7 @@ /// Constructeur Img::Img (void) - : tabData_ (0), tabSegm_ (0) + : tabY_ (0), tabData_ (0), tabSegm_ (0) { } @@ -20,6 +20,7 @@ Img::~Img (void) { delete [] tabData_; delete [] tabSegm_; + delete [] tabY_; } /// Ecrit les valeurs RGB dans un fichier @@ -35,6 +36,16 @@ Img::writeRaw (const char *filename, unsigned char *tab) const file.close (); } +/// Crée le tableau Y +void +Img::doTabY () +{ + delete [] tabY_; + tabY_ = new int[height_]; + for (int i=0; iwidth_ = width_; this->height_ = height_; nbPixels_ = width_ * height_; + doTabY (); this->colorMode_ = colorMode_; // Initialise tabData_ delete[] tabData_; @@ -64,16 +76,21 @@ Img::loadMultipeRaw (const std::vector &imgList, const Image::Pixel this->width_ = width_; this->height_ = height_ * imgList.size (); nbPixels_ = width_ * height_; + doTabY (); this->colorMode_ = colorMode_; // Initialise tabData_ delete[] tabData_; tabData_ = new unsigned char[nbPixels_*3]; + unsigned char *t = tabData_; // Ouvre les images et stocke les données dans tabData_ for (std::vector::const_iterator iter=imgList.begin(); iter != imgList.end(); iter++) { std::ifstream file (iter->c_str (), std::ios::in); if (file) - file.read ((char *)tabData_, nbPixels_*3); + { + file.read ((char *)t, nbPixels_*3); + t += nbPixels_*3; + } else std::cerr << "Img::loadRaw Erreur d'ouverture de fichier " << *iter << std::endl; file.close (); @@ -90,6 +107,7 @@ Img::load (ImageReader &loader) Image image; image.read (loader); loader.getParam (width_, height_, colorMode_); + doTabY (); nbPixels_ = width_ * height_; tabData_ = new unsigned char[image.getBufSize ()]; memcpy (tabData_, image.getBuf (), image.getBufSize ()); diff --git a/2005/i/robert/src/ovision/see/img.hh b/2005/i/robert/src/ovision/see/img.hh index 43c6c76..5033bbf 100644 --- a/2005/i/robert/src/ovision/see/img.hh +++ b/2005/i/robert/src/ovision/see/img.hh @@ -43,6 +43,9 @@ class Img friend class Skittle; friend class OVision; + /// premier pixel de chaque ligne Y + int *tabY_; + public: /// Constructeur Img (void); @@ -60,7 +63,11 @@ class Img inline int minWithBorder (int n, int min) {return n > min ? n : min;} /// Renvoie le maximum en fonction d'une bordure inline int maxWithBorder (int n, int max) {return n < max ? n : max;} - + + private: + /// Crée le tableau Y + void doTabY (); + protected: /// tableau des couleurs bruts unsigned char *tabData_; diff --git a/2005/i/robert/src/ovision/see/magnifier.cc b/2005/i/robert/src/ovision/see/magnifier.cc index e819437..5811328 100644 --- a/2005/i/robert/src/ovision/see/magnifier.cc +++ b/2005/i/robert/src/ovision/see/magnifier.cc @@ -49,12 +49,6 @@ Magnifier::analyse (std::vector &zoneList) // parcours de toutes les zones extraites for(std::vector::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, itemList_)) continue; @@ -106,6 +100,7 @@ Magnifier::scan () { if ((iter->ymax + dist > jter->ymin) && (abs(iter->xmin - jter->xmin) < 40) && (abs(iter->xmax - jter->xmax) < 40)) { + jter->circleUp = true; find = true; break; } @@ -253,6 +248,10 @@ Magnifier::addItem (Zone &zone, std::vector *list) { // TODO remplir les flags : partial, ... zone.area = (zone.xmax - zone.xmin) * (zone.ymax - zone.ymin); + if ((zone.xmax == img_->width_) || (zone.xmin == 0) + || (zone.ymax == img_->height_) || (zone.ymin == 0)) + zone.partial = true; + else zone.partial = false; list[zone.id].push_back (zone); } @@ -322,6 +321,7 @@ Magnifier::showZone (const Zone &z) const std::cout << " position : " << z.xmin << ", " << z.xmax << ", " << z.ymin << ", " << z.ymax << "\n"; std::cout << " alone : " << z.alone << "\n"; std::cout << " density: " << z.density << "\n"; + std::cout << " circleUp: " << z.circleUp << "\n"; std::cout << " ratio/vertical: " << z.ratio << " " << (z.vertical?"vertical":"") << "\n"; // std::cout << " orientation : " << z.pcX_ << ", " << z.pcY_ << "\n"; std::cout << " partial : " << z.partial << "\n"; diff --git a/2005/i/robert/src/ovision/see/map.cc b/2005/i/robert/src/ovision/see/map.cc index a05563a..ffe6a14 100644 --- a/2005/i/robert/src/ovision/see/map.cc +++ b/2005/i/robert/src/ovision/see/map.cc @@ -16,7 +16,7 @@ using namespace std; /// Constructeurs. Map::Map (Space *space) - : lock = 0; treeFound (0), checkCurBall (0) + : lock (0); treeFound (0), checkCurBall (0) // : motor (Motor::getInstance ()), tracker (motor.getTracker ()) { @@ -189,7 +189,7 @@ Map::AddBallsToMap(Group *group) while (pCur) { //XXX a enlever XXX - pCur->centery = 296 - pCur->centery; + pCur->centery = oconfig->height - pCur->centery; // On choppe la position par rapport au robot space->GetLoc (pCur->centerx, pCur->centery, pos[0], pos[1]); diff --git a/2005/i/robert/src/ovision/see/n2ml.cc b/2005/i/robert/src/ovision/see/n2ml.cc index 730d05e..4b61852 100644 --- a/2005/i/robert/src/ovision/see/n2ml.cc +++ b/2005/i/robert/src/ovision/see/n2ml.cc @@ -35,7 +35,7 @@ int main(int argc, char **argv) // Initialisation des classes OConfig oconfig; Img img; - img.loadMultipeRaw (list, pf, 360, 296); + img.loadMultipeRaw (list, pf, oconfig.width, oconfig.height); SegmLearn segm; segm.buildNN (nbOutput, Segm::generate); segm.trainNN (&img); diff --git a/2005/i/robert/src/ovision/see/oconfig.cc b/2005/i/robert/src/ovision/see/oconfig.cc index 804a125..430e4e6 100644 --- a/2005/i/robert/src/ovision/see/oconfig.cc +++ b/2005/i/robert/src/ovision/see/oconfig.cc @@ -16,7 +16,7 @@ OConfig *OConfig::instance = 0; /// Constructor /// @param *filename nom du fichier de config -OConfig::OConfig(const char *filename) +OConfig::OConfig (const char *filename) : node (0), color (0), index (0) { instance = this; @@ -26,7 +26,7 @@ OConfig::OConfig(const char *filename) } /// Destructor -OConfig::~OConfig() +OConfig::~OConfig () { } @@ -52,7 +52,7 @@ OConfig::parse (const char *var, const char *arg) else if (varName == "NN_neighborhood_learning") nnNl = atof (arg); else if (varName == "NN_number_of_iteration_learning") nnNil = atol(arg); else if (varName == "NN_threshold_output") nnThresholdOutput = atoi (arg); - else if (varName == "NN_lum_inosity_influence") nnInfluLum = atof (arg); + else if (varName == "NN_luminosity_influence") nnInfluLum = atof (arg); else if (varName == "UI_img_path ") strcpy(imgPath, arg); else if (varName == "NN_lazy_threshold") nnLazyThreshold = atoi (arg); // else if (varName == "Map_error") mapError = atoi (arg); @@ -77,6 +77,8 @@ OConfig::parse (const char *var, const char *arg) else if (varName == "Skittle_score_bend_ratio") skittleScoreBendRatio = atof (arg); else if (varName == "Mag_uniqueness") magUniqueness = atoi (arg); else if (varName == "Cam_brightness") brightness = atoi (arg); + else if (varName == "Cam_width") width = atoi (arg); + else if (varName == "Cam_height") height = atoi (arg); } diff --git a/2005/i/robert/src/ovision/see/oconfig.hh b/2005/i/robert/src/ovision/see/oconfig.hh index 2e77792..c34fa8e 100644 --- a/2005/i/robert/src/ovision/see/oconfig.hh +++ b/2005/i/robert/src/ovision/see/oconfig.hh @@ -139,6 +139,8 @@ class OConfig /// Ratio utilisé pour déterminer si le résultat d'une analyse de courbure est /// cohérent double skittleScoreBendRatio; + /// Taille de l'image caméra + int width, height; /// Chargement de poids pour le reseau de neurone void loadNNFile (const char *filePath = "../runtime/rc/poids"); diff --git a/2005/i/robert/src/ovision/see/ovision.cc b/2005/i/robert/src/ovision/see/ovision.cc index d15bbf7..64a372a 100644 --- a/2005/i/robert/src/ovision/see/ovision.cc +++ b/2005/i/robert/src/ovision/see/ovision.cc @@ -29,9 +29,9 @@ OVision::init (const Group::ZoneType aim) oconfig_ = new OConfig; img_ = new Img; // Initialisation caméra - v4l_ = new Video4Linux ("/dev/video", oconfig_->inputColor, oconfig_->brightness); + v4l_ = new Video4Linux ("/dev/video", oconfig_->width, oconfig_->height, + oconfig_->inputColor, oconfig_->brightness); v4l_->calibrate (); - v4l_->setAdaptive (0); // Prendre une image pour que la taille de l'image soit configuré img_->load (*v4l_); colorTab_ = new ColorTable; diff --git a/2005/i/robert/src/ovision/see/segmLearn.cc b/2005/i/robert/src/ovision/see/segmLearn.cc index 4ddf7d8..e5ceafe 100644 --- a/2005/i/robert/src/ovision/see/segmLearn.cc +++ b/2005/i/robert/src/ovision/see/segmLearn.cc @@ -104,8 +104,8 @@ SegmLearn::trainNN (Img *img) // Si on est en yuv ou hsi et que c'est la composante de lum_inosite, on ajoute un poids pour affecter son influence if (k == lumPos_) node_[numOutputMax*3+k] = - (unsigned char)(oconfig_->nnSl*(node_[numOutputMax*3+k] - + oconfig_->nnSl*tabData_[pixelNum*3+k])/(1+oconfig_->nnSl)); + (unsigned char)(node_[numOutputMax*3+k] + + oconfig_->nnInfluLum*oconfig_->nnSl*tabData_[pixelNum*3+k])/(1+oconfig_->nnSl); // Sinon calcul normal else node_[numOutputMax*3+k] = @@ -151,7 +151,7 @@ SegmLearn::findColorNN (const unsigned char *x, const bool testOutputMax) const // Si on est en yuv ou hsi et que c'est la composante de lum_inosite, on ajoute un poids pour affecter son influence if (k == lumPos_) //|| ((img->colorMode == Image) && k==2)) - output[j] += (int) oconfig_->nnInfluLum * tmp * tmp; + output[j] += (int) (oconfig_->nnInfluLum * tmp * tmp); // Sinon calcul normal else output[j] += tmp * tmp; diff --git a/2005/i/robert/src/ovision/see/skittle.cc b/2005/i/robert/src/ovision/see/skittle.cc index f8437d5..a509b19 100644 --- a/2005/i/robert/src/ovision/see/skittle.cc +++ b/2005/i/robert/src/ovision/see/skittle.cc @@ -26,7 +26,7 @@ void Skittle::pca (Zone &zone) { // Agrandissement de la zone de recherche - const int grow = oconfig_->skittleGrow; + const int grow = 0;//oconfig_->skittleGrow; int ymin = img_->minWithBorder (zone.ymin - grow, 0); int ymax = img_->maxWithBorder (zone.ymax + grow, img_->height_); int xmin = img_->minWithBorder (zone.xmin - grow, 0); @@ -45,7 +45,7 @@ Skittle::pca (Zone &zone) for (int x = xmin; x < xmax; x += jump) if (segm_->giveColor (img_->tabData_ + ((tmpY + x) * 3), true, true) == zone.color) { -// *f2 << x << " " << y << std::endl; + // *f2 << x << " " << y << std::endl; Hpoint h (x, y); l.push_back (h); if ((x >= zone.xmin) && (x <= zone.xmax) && (y >= zone.ymin) && (y <= zone.ymax)) @@ -163,24 +163,28 @@ Skittle::analyse (Zone &zone, const std::vector &listReflectBand) // group est partiel ? // if (zone.partial) // quille verticale sur l'image ? + pca (zone); zone.ratio = (zone.ymax - zone.ymin)/(double)(zone.xmax - zone.xmin); - if (zone.ratio > oconfig_->skittleVerticalRatio) - { + if ((pcY_ > 0.95) || (pcY_ < -0.95)) zone.vertical = true; + else zone.vertical = false; + if ((zone.centery > 140) && (pcX_ > 0.98) && (zone.density > 0.7) + && (zone.density < 0.85) && (zone.ratio > 0.6) && (zone.ratio < 0.8)) + return false; + if (zone.vertical) + { // debout ou couché ? //bend_ = bend (zone); whereIsReflectBand (zone, listReflectBand); } else { - zone.vertical = false; bend_ = down; // calcul de l'orientation pca (zone); } bend (zone); - pca (zone); feet_ = whereIsBottom (zone); if (checkArea (zone) == 1) zone.alone = true; diff --git a/2005/i/robert/src/ovision/see/skittle.hh b/2005/i/robert/src/ovision/see/skittle.hh index df87b48..e6568cc 100644 --- a/2005/i/robert/src/ovision/see/skittle.hh +++ b/2005/i/robert/src/ovision/see/skittle.hh @@ -83,6 +83,8 @@ class Skittle double isBottom (const Zone &zone, const Pos pos); /// Verifie la cohérence de la taille de la quille int checkArea (const Zone &zone); + /// test si la zone est la partie supérieur de la quille + bool isUpPart (const Zone &zone); /// Distance cartésienne inline const double dist (const double x1, const double x2, const double y1, const double y2) {return sqrt (x1*x2 + y1*y2);} diff --git a/2005/i/robert/src/ovision/see/test_colortable.cc b/2005/i/robert/src/ovision/see/test_colortable.cc index 8f78a4c..5a0be81 100644 --- a/2005/i/robert/src/ovision/see/test_colortable.cc +++ b/2005/i/robert/src/ovision/see/test_colortable.cc @@ -35,7 +35,7 @@ main(int argc, char **argv) return 1; } ImgInterface img; - img.loadRaw (argv[1], Image::rgb, 360, 296); + img.loadRaw (argv[1], Image::rgb, oconfig_->width, oconfig_->height); ColorTable tab; SegmTable segm (tab); ///////////////////////////////////////////////////////////////////////////////////////// diff --git a/2005/i/robert/src/ovision/see/test_group.cc b/2005/i/robert/src/ovision/see/test_group.cc index a9b4d94..b5f261f 100644 --- a/2005/i/robert/src/ovision/see/test_group.cc +++ b/2005/i/robert/src/ovision/see/test_group.cc @@ -29,7 +29,7 @@ main(int argc, char **argv) return 1; } ImgInterface img; - img.loadRaw ("../runtime/shots/test.rgb", Image::rgb, 360, 296); + img.loadRaw ("../runtime/shots/test.rgb", Image::rgb, oconfig_->width, oconfig_->height); SegmLearn segm; segm.buildNN (oconfig_->nnNbColor, Segm::loadFromFile); Group group(&img, &segm); diff --git a/2005/i/robert/src/ovision/see/test_img.cc b/2005/i/robert/src/ovision/see/test_img.cc index c67098f..ca8a9e7 100644 --- a/2005/i/robert/src/ovision/see/test_img.cc +++ b/2005/i/robert/src/ovision/see/test_img.cc @@ -14,7 +14,7 @@ int main(int argc, char **argv) ImgInterface img; OConfig config; // Chargement de l'image - img.loadRaw (argv[1], Image::rgb, 360, 296); + img.loadRaw (argv[1], Image::rgb, oconfig.width, oconfig.height); // Inversion de l'image img.mirror (); img.writeRaw ("../runtime/shots/toto.rgb"); diff --git a/2005/i/robert/src/ovision/see/test_magnifier.cc b/2005/i/robert/src/ovision/see/test_magnifier.cc index 2840740..f57bb89 100644 --- a/2005/i/robert/src/ovision/see/test_magnifier.cc +++ b/2005/i/robert/src/ovision/see/test_magnifier.cc @@ -30,7 +30,7 @@ main(int argc, char **argv) return 1; } Img img; - img.loadRaw ("../runtime/shots/test.rgb", Image::rgb, 360, 296); + img.loadRaw ("../runtime/shots/test.rgb", Image::rgb, oconfig_->width, oconfig_->height); SegmLearn segm; segm.buildNN (oconfig_->nnNbColor, Segm::loadFromFile); // ColorTable tab; diff --git a/2005/i/robert/src/ovision/see/test_segm.cc b/2005/i/robert/src/ovision/see/test_segm.cc index f7df860..ef61b91 100644 --- a/2005/i/robert/src/ovision/see/test_segm.cc +++ b/2005/i/robert/src/ovision/see/test_segm.cc @@ -19,7 +19,7 @@ int main(int argc, char **argv) // Initialisation des classes OConfig oconfig_; ImgInterface img; - img.loadRaw (argv[1], Image::rgb, 360, 296); + img.loadRaw (argv[1], Image::rgb, oconfig_.width, oconfig_.height); SegmLearn segm; segm.buildNN (oconfig_.nnNbColor, Segm::loadFromFile); segm.showNodes (); -- cgit v1.2.3