From 4ed296ad0e59aacc431a400fd09ccd606b5bba4d Mon Sep 17 00:00:00 2001 From: gaillaro Date: Sun, 17 Apr 2005 08:55:31 +0000 Subject: ajout de l'interface ovision --- 2005/i/robert/src/ovision/see/group.hh | 2 + 2005/i/robert/src/ovision/see/magnifier.cc | 10 +-- 2005/i/robert/src/ovision/see/magnifier.hh | 4 +- 2005/i/robert/src/ovision/see/ovision.cc | 131 +++++++++++++++++++++++++++++ 2005/i/robert/src/ovision/see/ovision.hh | 73 ++++++++++++++++ 2005/i/robert/src/ovision/see/skittle.cc | 44 ++++++---- 2005/i/robert/src/ovision/see/skittle.hh | 22 +++-- 7 files changed, 253 insertions(+), 33 deletions(-) create mode 100644 2005/i/robert/src/ovision/see/ovision.cc create mode 100644 2005/i/robert/src/ovision/see/ovision.hh (limited to '2005/i/robert') diff --git a/2005/i/robert/src/ovision/see/group.hh b/2005/i/robert/src/ovision/see/group.hh index 6cf2db1..6d5502a 100644 --- a/2005/i/robert/src/ovision/see/group.hh +++ b/2005/i/robert/src/ovision/see/group.hh @@ -41,6 +41,8 @@ struct Zone int ymin, ymax; /// centre de la zone trouvee int centerx, centery; + /// aire de la zone + int area; /// l'objet est vue partiellement ou completement bool partial; /// l'objet est situé en bas de l'image diff --git a/2005/i/robert/src/ovision/see/magnifier.cc b/2005/i/robert/src/ovision/see/magnifier.cc index 8ae323e..c528444 100644 --- a/2005/i/robert/src/ovision/see/magnifier.cc +++ b/2005/i/robert/src/ovision/see/magnifier.cc @@ -41,13 +41,13 @@ Group::GetDelta (int type, int y) /// Analyse une liste de zones /// @param zoneList liste des zones extraites par la classe group void -Magnifier::analyse (const std::vector &zoneList) +Magnifier::analyse (std::vector &zoneList) { // remise à zéro de toutes les listes for (int i=0; i::const_iterator iter = zoneList.begin (); iter != zoneList.end (); ++iter) + for(std::vector::iterator iter = zoneList.begin (); iter != zoneList.end (); ++iter) { // on vire si trop petit // XXX test avec l'aire ? @@ -167,10 +167,10 @@ Magnifier::isGap (const Zone &zone) const /// Ajout d'un objet void -Magnifier::addItem (const Zone &zone) +Magnifier::addItem (Zone &zone) { - // TODO remplir les flags - + // TODO remplir les flags : partial, ... + zone.area = (zone.xmax - zone.xmin) * (zone.ymax - zone.ymin); itemList_[zone.id].push_back (zone); } diff --git a/2005/i/robert/src/ovision/see/magnifier.hh b/2005/i/robert/src/ovision/see/magnifier.hh index 021f872..b25c3ac 100644 --- a/2005/i/robert/src/ovision/see/magnifier.hh +++ b/2005/i/robert/src/ovision/see/magnifier.hh @@ -48,7 +48,7 @@ class Magnifier /// Destructeur ~Magnifier (void); /// Analyse une liste de zones - void analyse (const std::vector &zoneList); + void analyse (std::vector &zoneList); /// Affiche les zones trouvees après analyse void showItems (const Group::ZoneType type) const; /// Renvoie une liste d'objet @@ -57,7 +57,7 @@ class Magnifier private: /// Ajout d'un objet - void addItem (const Zone &zone); + void addItem (Zone &zone); /// Test si l'object s'agit d'un doublon bool checkIsUnique (const Zone &zone); /// Test la validité des objects diff --git a/2005/i/robert/src/ovision/see/ovision.cc b/2005/i/robert/src/ovision/see/ovision.cc new file mode 100644 index 0000000..71f76d2 --- /dev/null +++ b/2005/i/robert/src/ovision/see/ovision.cc @@ -0,0 +1,131 @@ +#include "ovision.hh" +#include + +/// Constructeur +OVision::OVision (bool useSocket) + : oconfig_ (0), img_ (0), colorTab_ (0), segm_ (0), + group_ (0), mag_ (0), step_ (0) //map_ (0), +{ +// socket_ = 0; +} + +/// Destructeur +OVision::~OVision () +{ + delete oconfig_; + delete img_; + delete segm_; + delete group_; + delete mag_; +// delete map_; +// delete space_; +// delete socket_; +} + +/// Iniialisatoin de toutes les classes +void +OVision::init () +{ + // Initialisation des classes + oconfig_ = new OConfig; + img_ = new Img; + // Initialisation caméra + v4l_ = new Video4Linux ("/dev/video", oconfig_->inputColor); + v4l_->calibrate (); + // Prendre une image pour que la taille de l'image soit configuré + img_->load (*v4l_); + colorTab_ = new ColorTable; + segm_ = new SegmTable (*colorTab_); + group_ = new Group (img_, segm_); + mag_ = new Magnifier (img_, segm_); + // Mode de couleur utilisé pour les la segmentation + segm_->setMode (oconfig_->inputColor); +// space = new Space(img_->width, img_->height); +// map_ = new Map (space); + // Calibration des longueurs +// space->AddSetupPoint (314, 6, 100, 400); +// space->AddSetupPoint (237, 224, 100, 900); +// space->AddSetupPoint (275, 113, 100, 550); +// space->Setup (0.00891157, 0.258144, 403.801); + // Ouverture ou création de la table de couleur + /// Initialisation des socket_s + // socket_ = new SocketClient ("10.42.51.2" , 106560*3); + // socket_->Init (); + + // std::cout << "Chargement OVision ................ OK" << std::endl; +} + +/// Prends une image avec la caméra +void +OVision::takeShoot () +{ + img_->load (*v4l_); +} + +/// Analyse une image +void +OVision::update () +{ + // Compteur du nombre d'image traité + step_++; + // Cherche les balles + group_->jumpPoints (oconfig_->groupColor); + // Analyse et tri la liste de zones trouvées + mag->analyse (group->getZoneList ()); + // Parcours la liste de balles trouvées + /* if (group_->zoneListBall) + { + int x,y; + x = group_->zoneListBall->centerx; + y = img_->height - group_->zoneListBall->centery; + space->GetLoc (x, y, x, y); + } + */ + // Mets à jour la map_ + /* map_->AddBallsToMap (group_); + double balX, balY; + if (map_->GetCurBallPos (balX, balY)) + std::cout << "Balle Courante: " << balX << " " << balY << std::endl; + if (map_->IsTree ()) + { + double treeX, treeY; + map_->GetTreePos (treeX, treeY); + std::cout << "Tree: " << treeX << " " << treeY << std::endl; + } + */ +} + +/// Affiche d'info sur l'update +void +OVision::showInfo () const +{ + std::cout << "-----------------------------------------------------------------" << std::endl; + std::cout << "image n°" << step_ << std::endl; + // Info sur les zones trouvées + group_->showZones(); + mag_->showItems (Group::redSkittle); + std::cout << "-------------\n" << std::endl; + std::cout << "-------------\n" << std::endl; +} + +/// Renvoie la position +bool +OVision::getBall (double &x, double &y) const +{ + return false; +// return map_->GetCurBallPos (x, y); +} + +/// Renvoie le pointeur sur Video4Linux +Video4Linux & +OVision::getVideo4Linux () const +{ + return *v4l_; +} + +/// Envoie l'image par socket_ +void +OVision::sendImg () +{ +// socket__->Send (img_->tabData); +} diff --git a/2005/i/robert/src/ovision/see/ovision.hh b/2005/i/robert/src/ovision/see/ovision.hh new file mode 100644 index 0000000..89f78d2 --- /dev/null +++ b/2005/i/robert/src/ovision/see/ovision.hh @@ -0,0 +1,73 @@ +// robert - programme du robot 2005 +// +// Copyright (C) 2005 Olivier Gaillard +// +// Robot APB Team/Efrei 2005. +// Web: http://assos.efrei.fr/robot/ +// Email: robot AT efrei DOT fr +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +#ifndef ovision_h +#define ovision_h + +#include "oconfig.hh" +#include "segmTable.hh" +#include "group.hh" +#include "magnifier.hh" +#include "colorTable.hh" +#include "space.hh" +//#include "map.hh" +//#include "socket/socketClient.hh" +#include "video4linux/video4linux.hh" +#include "image/image.hh" + + +class OVision +{ + OConfig *oconfig_; + Img *img_; + ColorTable *colorTab_; + SegmTable *segm_; + Group *group_; + Magnifier *mag_; +// Space *space_; +// Map *map_; + // SocketClient *socket_; + Video4Linux *v4l_; + /// Nombre d'images déjà traitées + int step_; + public: + /// Constructeur + OVision (bool useSocket = false); + /// Destructeur + ~OVision (void); + /// Iniialisatoin de toutes les classes + void init (); + /// Prends une image avec la caméra + void takeShoot (); + /// Analyse une image + void update (); + /// Envoie l'image par socket + void sendImg (); + /// Affiche d'info sur l'update + void showInfo () const; + /// Renvoie la position + bool getBall (double &x, double &y) const; + /// Renvoie le pointeur sur Video4Linux + Video4Linux &getVideo4Linux () const; +}; + +#endif // ovision_h diff --git a/2005/i/robert/src/ovision/see/skittle.cc b/2005/i/robert/src/ovision/see/skittle.cc index 3fb5f64..1253e26 100644 --- a/2005/i/robert/src/ovision/see/skittle.cc +++ b/2005/i/robert/src/ovision/see/skittle.cc @@ -23,7 +23,7 @@ Skittle::~Skittle (void) /// Recherche de la composante principale void -Skittle::pca (Zone &zone) +Skittle::pca (const Zone &zone) { // Agrandissement de la zone de recherche const int grow = oconfig_->skittleGrow; @@ -63,14 +63,18 @@ Skittle::climb (const int startX, int startY, const int color) } /// Vérifie qu'un catadiopre est à proximité -int -Skittle::isReflectBand (Zone &zone, std::vector &listReflectBand) +Skittle::Pos +Skittle::whereIsReflectBand (const Zone &zone, const std::vector &listReflectBand) { - // Test les variables de composantes principales - if (!pcX_ && !pcY_ && listReflectBand.size ()) - { + const double minAreaRatio = 0.1; + const double maxAreaRatio = 0.4; + // Test les variables de composantes principales + liste transmise + if (pcX_ || !pcY_ || listReflectBand.size ()) + return error; + // Analyse de la taille + if (zone.area < minAreaRatio || zone.area > maxAreaRatio) // valeur réelle 0.2 // Parcours la liste des catadiopres - for (std::vector::iterator iter = listReflectBand.begin (); + for (std::vector::const_iterator iter = listReflectBand.begin (); iter != listReflectBand.end (); ++iter) { // Test la distance cartésienne @@ -78,16 +82,19 @@ Skittle::isReflectBand (Zone &zone, std::vector &listReflectBand) // Test la distance orthogonale if (orthoDist (iter->centerx - zone.centerx, iter->centery - zone.centery, pcX_, pcY_)) - return 1; - + { + if (iter->centerx > zone.centerx) + return up; + else return down; + } + } - } - return 0; + return farAway; } /// Recherche de du côté de la courbure -Skittle::BendType -Skittle::bend (Zone &zone) +Skittle::Pos +Skittle::bend (const Zone &zone) { /// Border const int border = oconfig_->skittleBorder; @@ -116,7 +123,7 @@ Skittle::bend (Zone &zone) std::cout << std::endl; const int score = (int)((zone.xmax - zone.xmin - 2*border) / jump * oconfig_->skittleScoreBendRatio) - 2; - BendType bending = error; + Pos bending = error; if (above > score) bending = up; else if (below > score) bending = down; @@ -125,7 +132,7 @@ Skittle::bend (Zone &zone) /// Analyse la zone bool -Skittle::analyse (Zone &zone, std::vector &listReflectBand) +Skittle::analyse (const Zone &zone, const std::vector &listReflectBand) { // group est partiel ? // if (zone.partial) @@ -135,7 +142,7 @@ Skittle::analyse (Zone &zone, std::vector &listReflectBand) std::cout << "vertical !!!" << std::endl; // debout ou couché ? bend_ = bend (zone); - isReflectBand (zone, listReflectBand); + whereIsReflectBand (zone, listReflectBand); } else // calcul de l'orientation @@ -149,5 +156,8 @@ Skittle::show () const { std::cout << " position : " << (bend_ == up ? "up" : (bend_ == down ? "down" : "error")) << "\n"; - std::cout << " orientation : " << pcX_ << ", " << pcY_ << std::endl; + std::cout << " orientation : " << pcX_ << ", " << pcY_ << "\n"; + std::cout << " catadiopre: " << (reflectBand_ == up ? "up" + : (reflectBand_ == down ? "down" + : (reflectBand_ == farAway ? "farAway" : "error"))) << std::endl; } diff --git a/2005/i/robert/src/ovision/see/skittle.hh b/2005/i/robert/src/ovision/see/skittle.hh index ebdeb6f..fb5ff77 100644 --- a/2005/i/robert/src/ovision/see/skittle.hh +++ b/2005/i/robert/src/ovision/see/skittle.hh @@ -42,38 +42,42 @@ class Skittle Img *img_; /// Composante principale double pcX_, pcY_; - /// Position + /// Enum pos + enum Pos {up, down, farAway, error}; + /// Courbure double bend_; + /// Position de la bande réfléchissante + Pos reflectBand_; public: - /// debout/couché/erreur - enum BendType {up, down, error}; /// Constructeur Skittle (Img *img, Segm *segm); /// Destructeur ~Skittle (void); /// Analyse d'une zone - bool analyse (Zone &zone, std::vector &listReflectBand); + bool analyse (const Zone &zone, const std::vector &listReflectBand); /// Affiche les infos sur la quille void show () const; private: /// Recherche de la composante principale - void pca (Zone &zone); + void pca (const Zone &zone); /// Recherche de du côté de la courbure - BendType bend (Zone &zone); + Pos bend (const Zone &zone); /// Utilisé pour la recherche de la courbure, cherche le point le plus haut int climb (const int startX, const int startY, const int color); /// Vérifie qu'un catadiopre est à proximité - int isReflectBand (Zone &zone, std::vector &listReflectBand); + Pos whereIsReflectBand (const Zone &zone, const std::vector &listReflectBand); /// Renvoie le minimum en fonction d'une bordure 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;} /// Distance cartésienne - inline double dist (double x1, double x2, double y1, double y2) {return sqrt (x1*x2 + y1*y2);} + inline const double dist (const double x1, const double x2, const double y1, const double y2) + {return sqrt (x1*x2 + y1*y2);} /// Distance orthogonale à une droite - inline double orthoDist (double v1x, double v1y, double v2x, double v2y) + inline const double orthoDist (const double v1x, const double v1y, + const double v2x, const double v2y) {return ((v1x*v2y - v2x*v1y) / sqrt (v2x*v2x + v2y*v2y));} }; -- cgit v1.2.3