#include "ovision.hh" #include /// Constructeur OVision::OVision (bool useSocket) : oconfig_ (0), img_ (0), colorTab_ (0), segm_ (0), eraser_ (0), group_ (0), mag_ (0), space_ (0), v4l_ (0), step_ (0), aim_ (Group::undefined) //map_ (0), { // socket_ = 0; } /// Destructeur OVision::~OVision () { delete oconfig_; delete img_; delete v4l_; delete segm_; delete group_; delete mag_; delete space_; delete colorTab_; } /// Iniialisatoin de toutes les classes void OVision::init (const Group::ZoneType aim) { aim_ = aim; oconfig_ = new OConfig; // Initialisation des classes if (aim == Group::redSkittle) { colorTab_ = new ColorTable ("../runtime/rc/colortableRed.z"); oconfig_->nnInfluLum = 0.4; oconfig_->groupColor.clear (); ObjectColor tmp; tmp.label = "redSkittle"; tmp.color = 3; tmp.type = aim; oconfig_->groupColor.push_back (tmp); } else { colorTab_ = new ColorTable ("../runtime/rc/colortableGreen.z"); oconfig_->nnInfluLum = 0.4; ObjectColor tmp; oconfig_->groupColor.clear (); tmp.label = "greenSkittle"; tmp.color = 0; tmp.type = aim; oconfig_->groupColor.push_back (tmp); } img_ = new Img; // Initialisation caméra v4l_ = new Video4Linux ("/dev/video", oconfig_->width, oconfig_->height, oconfig_->inputColor, oconfig_->brightness); v4l_->calibrate (); // Prendre une image pour que la taille de l'image soit configuré img_->load (*v4l_); segm_ = new SegmTable (*colorTab_); segm_->setMode (oconfig_->inputColor); eraser_ = new Eraser (oconfig_->width, 10); eraser_->init (); group_ = new Group (img_, segm_, eraser_); mag_ = new Magnifier (img_, segm_, eraser_, aim_); // Mode de couleur utilisé pour les la segmentation segm_->setMode (oconfig_->inputColor); space_ = new Space (img_->width_, img_->height_); // Calibration des longueurs space_->addSetupPoint (56, 155, 50, 315); space_->addSetupPoint (65, 51, 50, 465); space_->addSetupPoint (164, 46, -50, 465); space_->setup (0.003, -2.106, 561.391); } /// 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); } */ } /// 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 mag_->showItems (aim_); std::cout << "-------------\n" << std::endl; std::cout << "-------------\n" << std::endl; } /// Renvoie la position de la quille dans le référentiel robot void OVision::getLoc (Zone &zone, int &x, int &y, int &angle, int &dist) { space_->getRealLoc (zone, x, y, angle, dist); } /// Renvoie la liste des quilles std::vector& OVision::getSkittles () const { return mag_->getItemList(aim_); } /// Renvoie le pointeur sur Video4Linux Video4Linux & OVision::getVideo4Linux () const { return *v4l_; } /// Envoie l'image par socket_ void OVision::sendImg () { // socket__->Send (img_->tabData); }