summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision
diff options
context:
space:
mode:
authorgaillaro2005-05-06 14:43:00 +0000
committergaillaro2005-05-06 14:43:00 +0000
commit9aab8a34ad597c2b46cdde3d7cdc1e44c66c9596 (patch)
tree33dcd7b5fddb67380ad517bccfe76a9cd54b1f4a /2005/i/robert/src/ovision
parent1d6fa32f84b92e6dab641beb918cbb809ce1265b (diff)
modifs avant match vendredi
Diffstat (limited to '2005/i/robert/src/ovision')
-rw-r--r--2005/i/robert/src/ovision/see/Makefile.defs30
-rw-r--r--2005/i/robert/src/ovision/see/eraser.cc108
-rw-r--r--2005/i/robert/src/ovision/see/eraser.hh27
-rw-r--r--2005/i/robert/src/ovision/see/group.cc20
-rw-r--r--2005/i/robert/src/ovision/see/group.hh13
-rw-r--r--2005/i/robert/src/ovision/see/img.cc17
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.cc53
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.hh85
-rw-r--r--2005/i/robert/src/ovision/see/oconfig.cc10
-rw-r--r--2005/i/robert/src/ovision/see/oconfig.hh1
-rw-r--r--2005/i/robert/src/ovision/see/ovision.cc66
-rw-r--r--2005/i/robert/src/ovision/see/ovision.hh3
-rw-r--r--2005/i/robert/src/ovision/see/segmLearn.cc4
-rw-r--r--2005/i/robert/src/ovision/see/segmTable.cc4
-rw-r--r--2005/i/robert/src/ovision/see/skittle.cc58
-rw-r--r--2005/i/robert/src/ovision/see/space.cc5
-rw-r--r--2005/i/robert/src/ovision/see/test_group.cc3
-rw-r--r--2005/i/robert/src/ovision/see/test_magnifier.cc5
-rw-r--r--2005/i/robert/src/ovision/see/test_ovision.cc2
-rw-r--r--2005/i/robert/src/ovision/ui/Makefile.defs4
-rw-r--r--2005/i/robert/src/ovision/ui/comm.cc11
-rw-r--r--2005/i/robert/src/ovision/ui/live.cc36
-rw-r--r--2005/i/robert/src/ovision/ui/live.hh7
-rw-r--r--2005/i/robert/src/ovision/ui/liveView.cc2
24 files changed, 418 insertions, 156 deletions
diff --git a/2005/i/robert/src/ovision/see/Makefile.defs b/2005/i/robert/src/ovision/see/Makefile.defs
index 1b27152..e75b320 100644
--- a/2005/i/robert/src/ovision/see/Makefile.defs
+++ b/2005/i/robert/src/ovision/see/Makefile.defs
@@ -1,30 +1,31 @@
-PROGRAMS += test_ovision test_img test_group test_map test_ovisiontracker test_cam test_segm test_magnifier test_ovision test_colortable test_space genct n2ml
+PROGRAMS += test_ovision test_img test_group test_map test_ovisiontracker test_cam test_segm test_magnifier test_ovision test_colortable test_space genct n2ml test_hotelling test_eraser
LIBS += $(ovision_OBJECTS)
-ovision_OBJECTS = convertImg.o img.o oconfig.o segmTable.o hotelling.o segm.o imgInterface.o colorTable.o segmTable.o segmLearn.o group.o magnifier.o skittle.o ovision.o -lz space.o # map.o
+ovision_OBJECTS = convertImg.o img.o oconfig.o segmTable.o hotelling.o segm.o imgInterface.o colorTable.o segmTable.o segmLearn.o group.o magnifier.o skittle.o ovision.o -lz space.o eraser.o# map.o
-test_img_OBJECTS = test_img.o img.o imgInterface.o oconfig.o $(image_OBJECTS)
-n2ml_OBJECTS = n2ml.o oconfig.o img.o segm.o segmLearn.o $(image_OBJECTS)
+test_img_OBJECTS = test_img.o img.o imgInterface.o oconfig.o $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
+test_eraser_OBJECTS = test_eraser.o eraser.o oconfig.o $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
+n2ml_OBJECTS = n2ml.o oconfig.o img.o segm.o segmLearn.o $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
genct_OBJECTS = genct.o oconfig.o segm.o segmLearn.o colorTable.o -lz
test_hotelling_OBJECTS = test_hotelling.o hotelling.o oconfig.o
-test_cam_OBJECTS = test_cam.o img.o imgInterface.o oconfig.o $(video4linux_OBJECTS) $(image_OBJECTS) $(utils_OBJECTS)
-test_segm_OBJECTS = test_segm.o img.o segm.o segmLearn.o oconfig.o imgInterface.o colorTable.o segmTable.o $(image_OBJECTS)
-test_ovision_OBJECTS = test_ovision.cc $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) $(utils_OBJECTS)
-test_ovisionogl_OBJECTS = test_ovisionogl.o $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) motor.o config.o serial.o
-test_ovisiontracker_OBJECTS = test_ovisiontracker.o $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) motor.o date.o serial.o utils.o logger.o config.o
-test_map_OBJECTS = test_map.o $(ovision_OBJECTS) $(image_OBJECTS)
+test_cam_OBJECTS = test_cam.o img.o imgInterface.o oconfig.o $(video4linux_OBJECTS) $(image_OBJECTS) $(utils_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
+test_segm_OBJECTS = test_segm.o img.o segm.o segmLearn.o oconfig.o imgInterface.o colorTable.o segmTable.o $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
+test_ovision_OBJECTS = test_ovision.cc $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) $(utils_OBJECTS) $(data_OBJECTS)
+test_ovisionogl_OBJECTS = test_ovisionogl.o $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) motor.o config.o serial.o $(data_OBJECTS) $(net_OBJECTS)
+test_ovisiontracker_OBJECTS = test_ovisiontracker.o $(ovision_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) motor.o date.o serial.o utils.o logger.o config.o $(data_OBJECTS) $(net_OBJECTS)
+test_map_OBJECTS = test_map.o $(ovision_OBJECTS) $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
test_space_OBJECTS = test_space.o space.o group.o oconfig.o image.o img.o segm.o
-test_colortable_OBJECTS = test_colortable.o oconfig.o segmTable.o imgInterface.o img.o segm.o segmLearn.o colorTable.o $(image_OBJECTS)
-test_group_OBJECTS = test_group.o group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o $(image_OBJECTS)
-test_magnifier_OBJECTS = test_magnifier.o hotelling.o magnifier.o segmTable.o colorTable.o group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o skittle.o $(image_OBJECTS) -lz
+test_colortable_OBJECTS = test_colortable.o oconfig.o segmTable.o imgInterface.o img.o segm.o segmLearn.o colorTable.o $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS)
+test_group_OBJECTS = test_group.o group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o $(image_OBJECTS) $(data_OBJECTS) $(net_OBJECTS) eraser.o
+test_magnifier_OBJECTS = test_magnifier.o hotelling.o magnifier.o segmTable.o colorTable.o group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o skittle.o $(image_OBJECTS) -lz $(data_OBJECTS) $(net_OBJECTS)
test_img: $(test_img_OBJECTS:%.o=%.o)
+test_eraser: $(test_eraser_OBJECTS:%.o=%.o)
n2ml: $(n2ml_OBJECTS:%.o=%.o)
genct: $(genct_OBJECTS:%.o=%.o)
test_hotelling: $(test_hotelling_OBJECTS:%.o=%.o)
test_cam: $(test_cam_OBJECTS:%.o=%.o)
test_segm: $(test_segm_OBJECTS:%.o=%.o)
- $(CXX) $(LDFLAGS) -lz $^ -o $@
test_group: $(test_group_OBJECTS:%.o=%.o)
test_magnifier: $(test_magnifier_OBJECTS:%.o=%.o)
test_ovision: $(test_ovision_OBJECTS:%.o=%.o)
@@ -33,4 +34,3 @@ test_ovisiontracker: $(test_ovisiontracker_OBJECTS:%.o=%.o)
test_map: $(test_map_OBJECTS:%.o=%.o)
test_space: $(test_space_OBJECTS:%.o=%.o)
test_colortable: $(test_colortable_OBJECTS:%.o=%.o)
- $(CXX) $(LDFLAGS) -lz $^ -o $@
diff --git a/2005/i/robert/src/ovision/see/eraser.cc b/2005/i/robert/src/ovision/see/eraser.cc
index a2393ed..9ca2dc3 100644
--- a/2005/i/robert/src/ovision/see/eraser.cc
+++ b/2005/i/robert/src/ovision/see/eraser.cc
@@ -5,15 +5,16 @@
/// @file eraser.cc Filtre les objets par leurs tailles
#include <iostream>
+#include <fstream>
#include "eraser.hh"
+#include "group.hh"
/// Constructeur
-Eraser::Eraser (const std::string &filename, const int resolution)
- : res_ (resolution)
+Eraser::Eraser (const int maxHeight, const int resolution)
+ : res_ (resolution), maxHeight_ (maxHeight)
{
oconfig_ = OConfig::getInstance ();
- init ();
}
/// Destructeur
@@ -22,31 +23,118 @@ Eraser::~Eraser (void)
}
/// Ouvre le fichier de données
-Eraser::init (std::string &filename)
+void
+Eraser::init (const std::string &filename)
{
// Ouverture du fichier de distance
- std::ifstream file (filename);
- if (!file) {
- throw "<Eraser::init> Error during file opening";
+ std::ifstream file (filename.c_str ());
+ if (!file)
+ {
+ throw "<Eraser::init> Error during file opening\n";
return;
}
+ // Enlève les commentaires
+ char trash[50];
+ file.getline (trash, 50);
+ char c;
+ int y, min, max;
+ while (!file.eof ())
+ {
+ file >> c >> y >> min >> max;
+ add (c, y, min, max);
+ }
// Parcours des lignes et analyse
+ file.close ();
+ // Remplissage du reste
+ add ('V', maxHeight_, tabVMin_[tabVMax_.size () - 1], tabVMax_[tabVMax_.size () -1]);
+ add ('O', maxHeight_, min, max);
+}
+
+/// Remplissage de la table
+void
+Eraser::add (const char c, const int y, const int min, const int max)
+{
+ static int lastO = 0;
+ static int lastV = 0;
+ if (c == 'V')
+ {
+ for (int i = lastV; i <= y/res_; ++i)
+ {
+ tabVMin_.push_back (min);
+ tabVMax_.push_back (max);
+ }
+ lastV = y/res_;
+ }
+ else if (c == 'O')
+ {
+ for (int i = lastO; i <= y/res_; ++i)
+ {
+ tabOMin_.push_back (min);
+ tabOMax_.push_back (max);
+ std::cout << i << " " << min << " " << max << "\n";
+ }
+ lastO = (y+res_)/res_;
+ }
+ else
+ {
+ throw "<Eraser::init> Bad syntax in file\n";
+ return;
+ }
}
/// Objet à la bonne taille ?
bool
Eraser::killOrNot (const Zone &zone)
{
- int y = zone.ymax % res_;
+ int y = zone.ymax / res_;
+ if (zone.vertical)
+ {
+ if ((zone.area > tabVMin_[y]) || (zone.area < tabVMax_[y]))
+ return true;
+ }
+ else
+ {
+ if ((zone.area > tabOMin_[y]) || (zone.area < tabOMax_[y]))
+ return true;
+ }
+ return false;
+}
+
+
+/// Zone trop petite
+bool
+Eraser::isTooSmall (const Zone &zone)
+{
+ int y = zone.ymax / res_;
+ if (zone.vertical)
+ {
+ if (zone.area < tabVMin_[y])
+ return true;
+ }
+ else
+ {
+ if (zone.area < tabOMin_[y])
+ return true;
+ }
+ return false;
+}
+
+/// Zone trop grande
+bool
+Eraser::isTooBig (const Zone &zone)
+{
+ int y = zone.ymax / res_;
if (zone.vertical)
{
- if ((zone.area > tabVMin[y]) || (zone.area < tabVMax[y]))
+ if (zone.area > tabVMax_[y])
return true;
}
else
{
- if ((zone.area > tabOMin[y]) || (zone.area < tabOMax[y]))
+ if (zone.area > tabOMax_[y])
+ {
return true;
+ }
}
return false;
}
diff --git a/2005/i/robert/src/ovision/see/eraser.hh b/2005/i/robert/src/ovision/see/eraser.hh
index 7a98626..b35bb09 100644
--- a/2005/i/robert/src/ovision/see/eraser.hh
+++ b/2005/i/robert/src/ovision/see/eraser.hh
@@ -24,28 +24,45 @@
#define eraser_h
#include <vector>
+#include <string>
#include "oconfig.hh"
+struct Zone;
+
/// Filtre les objets par taille
class Eraser
{
/// Classe oconfig
OConfig *oconfig_;
/// Tableau des tailles pour une quille verticale
- std::vector<unsigned> tabVMin;
- std::vector<unsigned> tabVMax;
+ std::vector<int> tabVMin_;
+ std::vector<int> tabVMax_;
/// Tableau des tailles pour une quille oblique
- std::vector<unsigned> tabOMin;
- std::vector<unsigned> tabOMax;
+ std::vector<int> tabOMin_;
+ std::vector<int> tabOMax_;
+ /// Résolution des tableaux précédents
+ int res_;
+ /// Hauteur maximum de l'image
+ int maxHeight_;
public:
/// Constructeur
- Eraser (const std::string &filename, const int resolution);
+ Eraser (const int maxHeight, const int resolution);
/// Destructeur
~Eraser (void);
+ /// Ouvre le fichier de données
+ void init (const std::string &filename = "../runtime/rc/eraser");
+ /// Objet à la bonne taille ?
+ bool killOrNot (const Zone &zone);
+ /// Zone trop petite
+ bool isTooSmall (const Zone &zone);
+ /// Zone trop grande
+ bool isTooBig (const Zone &zone);
private:
+ /// Remplissage de la table
+ void add (const char c, const int y, const int min, const int max);
};
#endif // eraser_h
diff --git a/2005/i/robert/src/ovision/see/group.cc b/2005/i/robert/src/ovision/see/group.cc
index eee05bb..104427f 100644
--- a/2005/i/robert/src/ovision/see/group.cc
+++ b/2005/i/robert/src/ovision/see/group.cc
@@ -12,8 +12,8 @@
/// Constructeur
/// @param *img classe image
/// @param *segm classe segm
-Group::Group (Img *img, Segm *segm)
- : segm_ (segm), img_ (img)
+Group::Group (Img *img, Segm *segm, Eraser *eraser)
+ : segm_ (segm), img_ (img), eraser_ (eraser)
{
oconfig_ = OConfig::getInstance ();
}
@@ -40,15 +40,7 @@ Group::addZone (const int idColor, const int xmin, const int xmax, const int ymi
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;
- else if (iter->label == "reflectBand") zone.id = reflectBand;
- break;
- }
+ zone.id = iter->type;
zoneList_.push_back (zone);
}
@@ -66,9 +58,11 @@ void Group::plague (const unsigned char numColor, const int x, const int y)
int tmpY = img_->tabY_[y];
// Parcours de l'objet trouve de haut en bas et de gauche à droite
const int j = 2;
- while ((xmax < img_->width_-1)&& (segm_->giveColor(img_->tabData_ + ((xmax)+tmpY)*3, true, true) == numColor)) {xmax += j;}
+ const int wMinus1 = img_->width_-1;
+ const int hMinus1 = img_->height_-1;
+ while ((xmax < wMinus1)&& (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 ((ymax < hMinus1) && (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
diff --git a/2005/i/robert/src/ovision/see/group.hh b/2005/i/robert/src/ovision/see/group.hh
index 6cd62d8..a90e910 100644
--- a/2005/i/robert/src/ovision/see/group.hh
+++ b/2005/i/robert/src/ovision/see/group.hh
@@ -29,10 +29,12 @@
#include "segm.hh"
#include "oconfig.hh"
#include "hpoint.hh"
+#include "eraser.hh"
/// Liste chainee des zones trouvees par la classe group
-struct Zone
+class Zone
{
+ public:
/// type de la zone
int id;
/// bornes de la zone pour x
@@ -61,6 +63,9 @@ struct Zone
double density;
/// autre critère de verticalité
bool circleUp;
+ enum Pos {south, north, east, west, southwest, southeast, northeast, northwest, center};
+ Pos posOut;
+ bool small;
};
/// Cree une liste chainee de zones correspondant aux balles
@@ -72,6 +77,8 @@ class Group
Img *img_;
/// Classe oconfig
OConfig *oconfig_;
+ /// Eraser
+ Eraser *eraser_;
/// liste chainee pour sauver les zones des balles
std::vector<Zone> zoneList_;
/// Ajoute une balle ou un poteau à la liste de groupes
@@ -81,12 +88,12 @@ class Group
public:
/// Type d'objects à trouver
- static const int nbZoneType = 6;
+ static const int nbZoneType = 7;
enum ZoneType {greenSkittle, redSkittle, border, base, gap, reflectBand, undefined};
/// Convertit le label de couleur en nombre
static std::string translateToColorName (const int color);
/// Constructeur
- Group (Img *img, Segm *segm);
+ Group (Img *img, Segm *segm, Eraser *eraser);
/// Selectionne les points a tester
void jumpPoints(const std::vector<ObjectColor> &colorList);
void jumpPoints(int color);
diff --git a/2005/i/robert/src/ovision/see/img.cc b/2005/i/robert/src/ovision/see/img.cc
index fa38e4a..babddd0 100644
--- a/2005/i/robert/src/ovision/see/img.cc
+++ b/2005/i/robert/src/ovision/see/img.cc
@@ -41,6 +41,7 @@ void
Img::doTabY ()
{
delete [] tabY_;
+ delete [] tabData_;
tabY_ = new int[height_];
for (int i=0; i<height_; ++i)
tabY_[i] = i*width_;
@@ -102,16 +103,18 @@ Img::loadMultipeRaw (const std::vector<std::string> &imgList, const Image::Pixel
void
Img::load (ImageReader &loader)
{
- delete[] tabData_;
// Ouvre l'image
Image image;
image.read (loader);
- loader.getParam (width_, height_, colorMode_);
- doTabY ();
- nbPixels_ = width_ * height_;
- tabData_ = new unsigned char[image.getBufSize ()];
+ if (!tabData_)
+ {
+ loader.getParam (width_, height_, colorMode_);
+ // Récupère le format de couleur
+ colorMode_ = image.getPixelFormat ();
+ doTabY ();
+ nbPixels_ = width_ * height_;
+ tabData_ = new unsigned char[image.getBufSize ()];
+ }
memcpy (tabData_, image.getBuf (), image.getBufSize ());
- // Récupère le format de couleur
- colorMode_ = image.getPixelFormat ();
}
diff --git a/2005/i/robert/src/ovision/see/magnifier.cc b/2005/i/robert/src/ovision/see/magnifier.cc
index 5811328..b61b260 100644
--- a/2005/i/robert/src/ovision/see/magnifier.cc
+++ b/2005/i/robert/src/ovision/see/magnifier.cc
@@ -10,8 +10,8 @@
#include "skittle.hh"
/// Constructeur
-Magnifier::Magnifier (Img *img, Segm *segm, Group::ZoneType aim)
-: segm_ (segm), img_ (img), aim_ (aim)
+Magnifier::Magnifier (Img *img, Segm *segm, Eraser *eraser, Group::ZoneType aim)
+: segm_ (segm), img_ (img), eraser_ (eraser), aim_ (aim)
{
oconfig_ = OConfig::getInstance ();
itemList_ = new std::vector<Zone>[Group::nbZoneType];
@@ -66,10 +66,13 @@ Magnifier::analyse (std::vector<Zone> &zoneList)
Skittle *s = isSkittle (*iter);
if (s)
{
- showZone (*iter);
- s->show ();
- delete s;
- find = true;
+ iter->alone = !eraser_->isTooBig (*iter);
+ iter->small = eraser_->isTooSmall (*iter);
+ if (iter->partial) getPosOut (*iter);
+ showZone (*iter);
+ //s->show ();
+ delete s;
+ find = true;
}
}
return find;
@@ -77,6 +80,37 @@ Magnifier::analyse (std::vector<Zone> &zoneList)
return false;
}
+
+/// Renvoie la position d'une quille
+void
+Magnifier::getPosOut (Zone &zone)
+{
+ static const int widthDiv3 = img_->width_ / 3;
+ static const int width2Div3 = widthDiv3 * 2;
+ static const int heightDiv3 = img_->height_ / 3;
+ static const int height2Div3 = heightDiv3 * 2;
+
+ if (zone.centery < heightDiv3)
+ {
+ if (zone.centerx < widthDiv3) zone.posOut = Zone::northwest;
+ else if (zone.centerx < width2Div3) zone.posOut = Zone::north;
+ else zone.posOut = Zone::northeast;
+ }
+ else if (zone.centery < height2Div3)
+ {
+ if (zone.centerx < widthDiv3) zone.posOut = Zone::west;
+ else if (zone.centerx < width2Div3) zone.posOut = Zone::center;
+ else zone.posOut = Zone::east;
+ }
+ else
+ {
+ if (zone.centerx < widthDiv3) zone.posOut = Zone::southwest;
+ else if (zone.centerx < width2Div3) zone.posOut = Zone::south;
+ else zone.posOut = Zone::southeast;
+ }
+
+}
+
bool
Magnifier::scan ()
{
@@ -319,10 +353,13 @@ Magnifier::showZone (const Zone &z) const
{
std::cout << "------------------------------------------------------------------\n";
std::cout << "<Magnifier::showZone> position : " << z.xmin << ", " << z.xmax << ", " << z.ymin << ", " << z.ymax << "\n";
+ std::cout << "<Magnifier::showZone> area : " << z.area << "\n";
+ std::cout << "<Magnifier::showZone> small : " << z.small << "\n";
std::cout << "<Magnifier::showZone> alone : " << z.alone << "\n";
- std::cout << "<Magnifier::showZone> density: " << z.density << "\n";
- std::cout << "<Magnifier::showZone> circleUp: " << z.circleUp << "\n";
+// std::cout << "<Magnifier::showZone> density: " << z.density << "\n";
+// std::cout << "<Magnifier::showZone> circleUp: " << z.circleUp << "\n";
std::cout << "<Magnifier::showZone> ratio/vertical: " << z.ratio << " " << (z.vertical?"vertical":"") << "\n";
// std::cout << "<Magnifier::showZone> orientation : " << z.pcX_ << ", " << z.pcY_ << "\n";
std::cout << "<Magnifier::showZone> partial : " << z.partial << "\n";
+ std::cout << "<Magnifier::showZone> posOut : " << z.posOut << "\n";
}
diff --git a/2005/i/robert/src/ovision/see/magnifier.hh b/2005/i/robert/src/ovision/see/magnifier.hh
index f569a88..0130d3b 100644
--- a/2005/i/robert/src/ovision/see/magnifier.hh
+++ b/2005/i/robert/src/ovision/see/magnifier.hh
@@ -29,52 +29,57 @@
#include "oconfig.hh"
#include "group.hh"
#include "img.hh"
+#include "eraser.hh"
/// Filtre la liste d'objets trouvées
class Magnifier
{
- /// Classe segmentation
- Segm *segm_;
- /// Classe oconfig
- OConfig *oconfig_;
- /// Classe img
- Img *img_;
- /// Liste des objects après analyse
- std::vector<Zone> *itemList_;
- /// Cible
- Group::ZoneType aim_;
+ /// Classe segmentation
+ Segm *segm_;
+ /// Classe oconfig
+ OConfig *oconfig_;
+ /// Classe img
+ Img *img_;
+ /// Classe eraser
+ Eraser *eraser_;
+ /// Liste des objects après analyse
+ std::vector<Zone> *itemList_;
+ /// Cible
+ Group::ZoneType aim_;
- public:
- /// Constructeur
- Magnifier (Img *img, Segm *segm, Group::ZoneType aim);
- /// Destructeur
- ~Magnifier (void);
- /// Analyse une liste de zones
- bool analyse (std::vector<Zone> &zoneList);
- /// Affiche les zones trouvees après analyse
- void showItems (const Group::ZoneType type) const;
- /// Renvoie une liste d'objet
- std::vector<Zone>& getItemList (Group::ZoneType type) const
- {return itemList_[type];}
- /// Affiche des infos sur une zone
- void showZone (const Zone &z) const;
+ public:
+ /// Constructeur
+ Magnifier (Img *img, Segm *segm, Eraser *eraser, Group::ZoneType aim);
+ /// Destructeur
+ ~Magnifier (void);
+ /// Analyse une liste de zones
+ bool analyse (std::vector<Zone> &zoneList);
+ /// Affiche les zones trouvees après analyse
+ void showItems (const Group::ZoneType type) const;
+ /// Renvoie une liste d'objet
+ std::vector<Zone>& getItemList (Group::ZoneType type) const
+ {return itemList_[type];}
+ /// Affiche des infos sur une zone
+ void showZone (const Zone &z) const;
- private:
- /// Ajout d'un objet
- void addItem (Zone &zone, std::vector<Zone> *list);
- void add (Zone &zone, std::vector<Zone> *list);
- /// Test si l'object s'agit d'un doublon
- bool checkIsUnique (const Zone &zone, std::vector<Zone> *list);
- bool scan ();
- /// Test si les zones sont liées
- bool areBound (const Zone &z1, const Zone &z2);
- /// Test la validité des objects
- Skittle* isSkittle (Zone &zone);
- bool isRedSkittle (const Zone &zone) const;
- bool isGreenSkittle (const Zone &zone) const;
- bool isBase (const Zone &zone) const;
- bool isBorder (const Zone &zone) const;
- bool isGap (const Zone &zone) const;
+ private:
+ /// Ajout d'un objet
+ void addItem (Zone &zone, std::vector<Zone> *list);
+ void add (Zone &zone, std::vector<Zone> *list);
+ /// Test si l'object s'agit d'un doublon
+ bool checkIsUnique (const Zone &zone, std::vector<Zone> *list);
+ bool scan ();
+ /// Test si les zones sont liées
+ bool areBound (const Zone &z1, const Zone &z2);
+ /// Test la validité des objects
+ Skittle* isSkittle (Zone &zone);
+ bool isRedSkittle (const Zone &zone) const;
+ bool isGreenSkittle (const Zone &zone) const;
+ bool isBase (const Zone &zone) const;
+ bool isBorder (const Zone &zone) const;
+ bool isGap (const Zone &zone) const;
+ /// Renvoie la position d'une quille
+ void getPosOut (Zone &zone);
};
#endif // magnifier_h
diff --git a/2005/i/robert/src/ovision/see/oconfig.cc b/2005/i/robert/src/ovision/see/oconfig.cc
index 6830081..3d4d746 100644
--- a/2005/i/robert/src/ovision/see/oconfig.cc
+++ b/2005/i/robert/src/ovision/see/oconfig.cc
@@ -11,6 +11,7 @@
#include <sstream>
#include "oconfig.hh"
+#include "group.hh"
OConfig *OConfig::instance = 0;
@@ -143,6 +144,13 @@ OConfig::loadNNFile (const char *filePath)
std::istringstream iss (buf);
ObjectColor tmp;
iss >> tmp.label >> tmp.color;
+ if (tmp.label == "redSktittle") tmp.type = Group::redSkittle;
+ else if (tmp.label == "greenSkittle") tmp.type = Group::greenSkittle;
+ else if (tmp.label == "border") tmp.type = Group::border;
+ else if (tmp.label == "base") tmp.type = Group::base;
+ else if (tmp.label == "gap") tmp.type = Group::gap;
+ else if (tmp.label == "reflectBand") tmp.type = Group::reflectBand;
+ else tmp.type = Group::undefined;
groupColor.push_back (tmp);
}
// Chargement des poids
@@ -192,7 +200,9 @@ OConfig::createNNFile (const char *filename, const int nbOutput) const
std::ofstream file (filename);
// Couleurs
for (std::vector<ObjectColor>::const_iterator i = groupColor.begin (); i < groupColor.end (); ++i)
+ {
file << i->label << " " << i->color << "\n";
+ }
// Poids
file << "#index\t#x1\tx2\tx3\n";
for (int i=0; i<nbOutput; i++)
diff --git a/2005/i/robert/src/ovision/see/oconfig.hh b/2005/i/robert/src/ovision/see/oconfig.hh
index c34fa8e..80c3de8 100644
--- a/2005/i/robert/src/ovision/see/oconfig.hh
+++ b/2005/i/robert/src/ovision/see/oconfig.hh
@@ -33,6 +33,7 @@ struct ObjectColor
{
std::string label;
int color;
+ int type;
};
diff --git a/2005/i/robert/src/ovision/see/ovision.cc b/2005/i/robert/src/ovision/see/ovision.cc
index 13afc18..5dd7c51 100644
--- a/2005/i/robert/src/ovision/see/ovision.cc
+++ b/2005/i/robert/src/ovision/see/ovision.cc
@@ -3,7 +3,7 @@
/// Constructeur
OVision::OVision (bool useSocket)
- : oconfig_ (0), img_ (0), colorTab_ (0), segm_ (0),
+ : oconfig_ (0), img_ (0), colorTab_ (0), segm_ (0), eraser_ (0),
group_ (0), mag_ (0), step_ (0), aim_ (Group::undefined) //map_ (0),
{
// socket_ = 0;
@@ -27,8 +27,31 @@ void
OVision::init (const Group::ZoneType aim)
{
aim_ = aim;
+ oconfig_ = new OConfig;
// Initialisation des classes
- oconfig_ = new OConfig;
+ if (aim == Group::redSkittle)
+ {
+ colorTab_ = new ColorTable ("../runtime/rc/colorTableGreen.z");
+ //oconfig_->nnInfluLum = ;
+ oconfig_->groupColor.clear ();
+ ObjectColor tmp;
+ tmp.label = "redSkittle";
+ tmp.color = 4;
+ tmp.type = Group::redSkittle;
+ oconfig_->groupColor.push_back (tmp);
+ }
+ else
+ {
+ colorTab_ = new ColorTable ("../runtime/rc/colorTableRed.z");
+ //oconfig_->nnInfluLum = ;
+ ObjectColor tmp;
+ oconfig_->groupColor.clear ();
+ tmp.label = "greenSkittle";
+ tmp.color = 4;
+ tmp.type = Group::greenSkittle;
+ oconfig_->groupColor.push_back (tmp);
+ }
+
img_ = new Img;
// Initialisation caméra
v4l_ = new Video4Linux ("/dev/video", oconfig_->width, oconfig_->height,
@@ -36,19 +59,20 @@ OVision::init (const Group::ZoneType aim)
v4l_->calibrate ();
// Prendre une image pour que la taille de l'image soit configuré
img_->load (*v4l_);
- colorTab_ = new ColorTable;
segm_ = new SegmTable (*colorTab_);
segm_->setMode (oconfig_->inputColor);
- group_ = new Group (img_, segm_);
- mag_ = new Magnifier (img_, segm_, aim_);
+ 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 (314, 6, 100, 400);
- space_->addSetupPoint (237, 224, 100, 900);
- space_->addSetupPoint (275, 113, 100, 550);
- space_->setup (0.00891157, 0.258144, 403.801);
+ 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
@@ -91,6 +115,30 @@ OVision::showInfo () const
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_->getLoc (zone.ymax, zone.centerx, x, y);
+ double newPcX, newPcY;
+ if (zone.pcY > 0)
+ {
+ newPcY = - zone.pcY;
+ newPcX = - zone.pcX;
+ }
+ else
+ {
+ newPcX = zone.pcX;
+ newPcY = zone.pcY;
+ }
+ int tmpX = (int)((zone.xmax - zone.centerx) * newPcX + zone.centerx);
+ int tmpY = (int)((zone.ymax - zone.centery) *newPcY + zone.centery);
+ int newX, newY;
+ space_->getLoc (tmpX, tmpY, newX, newY);
+ angle = (int)(atan (tmpX / (tmpY+9)));
+ dist = tmpY;
+}
+
/// Renvoie la liste des quilles
std::vector<Zone>&
OVision::getSkittles () const
diff --git a/2005/i/robert/src/ovision/see/ovision.hh b/2005/i/robert/src/ovision/see/ovision.hh
index eddd7be..bc722ef 100644
--- a/2005/i/robert/src/ovision/see/ovision.hh
+++ b/2005/i/robert/src/ovision/see/ovision.hh
@@ -41,6 +41,7 @@ class OVision
Img *img_;
ColorTable *colorTab_;
SegmTable *segm_;
+ Eraser *eraser_;
Group *group_;
Magnifier *mag_;
Space *space_;
@@ -70,6 +71,8 @@ class OVision
std::vector<Zone>& OVision::getSkittles () const;
/// Renvoie le pointeur sur Video4Linux
Video4Linux &getVideo4Linux () const;
+ /// Renvoie la position de la quille dans le référentiel robot
+ void getLoc (Zone &zone, int &x, int &y, int &angle, int &dist);
};
#endif // ovision_h
diff --git a/2005/i/robert/src/ovision/see/segmLearn.cc b/2005/i/robert/src/ovision/see/segmLearn.cc
index e5ceafe..a03efd9 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)(node_[numOutputMax*3+k]
- + oconfig_->nnInfluLum*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] =
diff --git a/2005/i/robert/src/ovision/see/segmTable.cc b/2005/i/robert/src/ovision/see/segmTable.cc
index 919107f..1284450 100644
--- a/2005/i/robert/src/ovision/see/segmTable.cc
+++ b/2005/i/robert/src/ovision/see/segmTable.cc
@@ -26,9 +26,11 @@ SegmTable::SegmTable (ColorTable &tab)
unsigned char
SegmTable::giveColor (const unsigned char *x, const bool testOutputMax, const bool index_Process, const bool lumFlag)
{
+ static int cts2 = ColorTable::colorTabSize2;
+ static int cts = ColorTable::colorTabSize;
if (lumFlag && (lumPos_ >= 0)) addLum (x[lumPos_]);
// if (index_Process)
- return tab_[(int) (x[0] * ColorTable::colorTabSize2 + x[1] * ColorTable::colorTabSize + x[2]) ];
+ return tab_[(int) (x[0] * cts2 + x[1] * cts + x[2]) ];
// else
// return colorTable_[ x[0]*colorTabSize2 + x[1]*colorTabSize + x[2] ];
}
diff --git a/2005/i/robert/src/ovision/see/skittle.cc b/2005/i/robert/src/ovision/see/skittle.cc
index a509b19..602f77a 100644
--- a/2005/i/robert/src/ovision/see/skittle.cc
+++ b/2005/i/robert/src/ovision/see/skittle.cc
@@ -26,24 +26,26 @@ void
Skittle::pca (Zone &zone)
{
// Agrandissement de la zone de recherche
- 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);
- int xmax = img_->maxWithBorder (zone.xmax + grow, img_->width_);
+ /*const int grow = 0;//oconfig_->skittleGrow;
+ ymin = img_->minWithBorder (zone.ymin - grow, 0);
+ ymax = img_->maxWithBorder (zone.ymax + grow, img_->height_);
+ xmin = img_->minWithBorder (zone.xmin - grow, 0);
+ xmax = img_->maxWithBorder (zone.xmax + grow, img_->width_);*/
+ int ymin, ymax, xmin, xmax;
+ ymin = zone.ymin; ymax = zone.ymax;
+ xmin = zone.xmin; xmax = zone.xmax;
/// Initialisation du saut de point
- int jump = oconfig_->jumpPointDist/oconfig_->skittleDivJump;
- if (!jump) jump = 1;
+ //int jump = oconfig_->jumpPointDist/oconfig_->skittleDivJump;
+ //if (!jump) jump = 1;
+ int jump = 5;
// Parcours d'une partie des pixels de l'image
// Sauvegarde des points et de la densité
- int tmpY;
int nbPoints = 0;
std::vector<Hpoint> l;
for (int y = ymin; y < ymax; y += jump)
{
- tmpY = y*img_->width_;
for (int x = xmin; x < xmax; x += jump)
- if (segm_->giveColor (img_->tabData_ + ((tmpY + x) * 3), true, true) == zone.color)
+ if (segm_->giveColor (img_->tabData_ + ((img_->tabY_[y] + x) * 3), true, true) == zone.color)
{
// *f2 << x << " " << y << std::endl;
Hpoint h (x, y);
@@ -168,27 +170,27 @@ Skittle::analyse (Zone &zone, const std::vector<Zone> &listReflectBand)
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é ?
+// 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
- {
- bend_ = down;
+// whereIsReflectBand (zone, listReflectBand);
+// }
+// else
+// {
+// bend_ = down;
// calcul de l'orientation
- pca (zone);
- }
+// pca (zone);
+// }
- bend (zone);
- feet_ = whereIsBottom (zone);
- if (checkArea (zone) == 1)
- zone.alone = true;
- else zone.alone = false;
+// bend (zone);
+// feet_ = whereIsBottom (zone);
+// if (checkArea (zone) == 1)
+// zone.alone = true;
+// else zone.alone = false;
// f->close ();
diff --git a/2005/i/robert/src/ovision/see/space.cc b/2005/i/robert/src/ovision/see/space.cc
index dc618fc..c58268d 100644
--- a/2005/i/robert/src/ovision/see/space.cc
+++ b/2005/i/robert/src/ovision/see/space.cc
@@ -128,7 +128,10 @@ void
Space::getLoc (const int locImgX, const int locImgY, double &locX, double &locY)
{
// Calcul de locX
- locX = tabX_[locImgY*imgWidth_ + locImgX];
+// locX = tabX_[locImgY*imgWidth_ + locImgX];
+
+ ///XXX patch
+ locX = 100-(double)locImgX/60 * 50;
// Calcul de locY
locY = aY_*locImgY*locImgY + bY_*locImgY + cY_;
}
diff --git a/2005/i/robert/src/ovision/see/test_group.cc b/2005/i/robert/src/ovision/see/test_group.cc
index e3f0b3a..3d5f037 100644
--- a/2005/i/robert/src/ovision/see/test_group.cc
+++ b/2005/i/robert/src/ovision/see/test_group.cc
@@ -32,7 +32,8 @@ main(int argc, char **argv)
img.loadRaw ("../runtime/shots/test.rgb", Image::rgb, oconfig_->width, oconfig_->height);
SegmLearn segm;
segm.buildNN (oconfig_->nnNbColor, Segm::loadFromFile);
- Group group(&img, &segm);
+ Eraser eraser (oconfig_->width, 10);
+ Group group(&img, &segm, &eraser);
/////////////////////////////////////////////////////////////////////////////////////////
/// Initialise les couleurs à chercher
std::vector<ObjectColor> colorList;
diff --git a/2005/i/robert/src/ovision/see/test_magnifier.cc b/2005/i/robert/src/ovision/see/test_magnifier.cc
index df1f4f3..1be395d 100644
--- a/2005/i/robert/src/ovision/see/test_magnifier.cc
+++ b/2005/i/robert/src/ovision/see/test_magnifier.cc
@@ -35,7 +35,9 @@ main(int argc, char **argv)
segm.buildNN (oconfig_->nnNbColor, Segm::loadFromFile);
// ColorTable tab;
// SegmTable segm (tab);
- Group group (&img, &segm);
+
+ Eraser eraser (oconfig_->width, 10);
+ Group group (&img, &segm, &eraser);
Magnifier mag (&img, &segm, Group::redSkittle);
/////////////////////////////////////////////////////////////////////////////////////////
/// Initialise les couleurs à chercher
@@ -43,6 +45,7 @@ main(int argc, char **argv)
ObjectColor tmp;
tmp.label = "ball";
tmp.color = 4;
+ tmp.type = Group::redSkittle
colorList.push_back (tmp);
/////////////////////////////////////////////////////////////////////////////////////////
/// Cherche les groupes
diff --git a/2005/i/robert/src/ovision/see/test_ovision.cc b/2005/i/robert/src/ovision/see/test_ovision.cc
index 3d00350..25e7e88 100644
--- a/2005/i/robert/src/ovision/see/test_ovision.cc
+++ b/2005/i/robert/src/ovision/see/test_ovision.cc
@@ -35,7 +35,7 @@ main(int argv, char **argc)
// Affiche d'info sur l'update
// ovision.showInfo ();
// Affiche les coordonnées de la première balle
- double x, y;
+// double x, y;
// if (ovision.getBall (x, y))
// std::cout << x <<"----" << y << std::endl;
usleep (500000);
diff --git a/2005/i/robert/src/ovision/ui/Makefile.defs b/2005/i/robert/src/ovision/ui/Makefile.defs
index 343e45f..b212205 100644
--- a/2005/i/robert/src/ovision/ui/Makefile.defs
+++ b/2005/i/robert/src/ovision/ui/Makefile.defs
@@ -2,8 +2,8 @@ PROGRAMS += adjust ui liveView
LIBSGL= -L/usr/X11R6/lib -lGL -lGLU -lglut
LIBNCURSES=-lmenu -lncurses
-adjust_OBJECTS = adjust.o comm.o live.o $(ovision_OBJECTS) $(data_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) $(utils_OBJECTS)
-liveView_OBJECTS = liveView.o live.o $(ovision_OBJECTS) $(data_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) $(utils_OBJECTS)
+adjust_OBJECTS = adjust.o comm.o live.o $(ovision_OBJECTS) $(data_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) $(utils_OBJECTS) $(net_OBJECTS)
+liveView_OBJECTS = liveView.o live.o $(ovision_OBJECTS) $(data_OBJECTS) $(image_OBJECTS) $(video4linux_OBJECTS) $(utils_OBJECTS) $(net_OBJECTS)
ui_OBJECTS = ui.o mainui.o oconfig.o group.o segm.o
ui: $(ui_OBJECTS:%.o=%.o)
diff --git a/2005/i/robert/src/ovision/ui/comm.cc b/2005/i/robert/src/ovision/ui/comm.cc
index a2109c4..0065bd2 100644
--- a/2005/i/robert/src/ovision/ui/comm.cc
+++ b/2005/i/robert/src/ovision/ui/comm.cc
@@ -107,6 +107,7 @@ Comm::executeUiCmds (const char *buffer)
}
// On live_->segmente l'image puis on la stocke
live_->segmAndGroup ();
+ live_->rootPics ();
std::cout << "Couleur " << numColor << " changé aux valeurs " << (int)live_->segm->node_[numColor*3] << " " << (int)live_->segm->node_[numColor*3+1] << " " << (int)live_->segm->node_[numColor*3+2];
break;
@@ -136,6 +137,7 @@ Comm::executeUiCmds (const char *buffer)
}
// On live_->segmente l'image puis on la stocke
live_->segmAndGroup();
+ live_->rootPics ();
std::cout << nbColorToMerge << " colors merged to " << numIndexColor << std::endl;
}
break;
@@ -145,10 +147,16 @@ Comm::executeUiCmds (const char *buffer)
ss >> numColorToShow;
// Cas ou toutes les couleurs doivent etre affiche
if (numColorToShow == -1)
+ {
live_->segmAndGroup ();
+ live_->rootPics ();
+ }
// Afficher seulement une couleur
else
+ {
live_->segmAndGroup (numColorToShow);
+ live_->rootPics ();
+ }
break;
case 'd': // supprimer couleur
@@ -168,6 +176,8 @@ Comm::executeUiCmds (const char *buffer)
live_->segm->showNodes();
// On live_->segmente l'image puis on la stocke
live_->segmAndGroup();
+ live_->rootPics ();
+
break;
case 'r': // Reload l'image
@@ -269,6 +279,7 @@ Comm::executeUiCmds (const char *buffer)
live_->segm->trainNN(live_->img);
// On live_->segmente l'image puis on la stocke
live_->segmAndGroup();
+ live_->rootPics ();
// Synchronisation des poids avec ui
sendNodes();
break;
diff --git a/2005/i/robert/src/ovision/ui/live.cc b/2005/i/robert/src/ovision/ui/live.cc
index 60918ac..2484f32 100644
--- a/2005/i/robert/src/ovision/ui/live.cc
+++ b/2005/i/robert/src/ovision/ui/live.cc
@@ -16,12 +16,14 @@
#include "image/raw_reader.hh"
#include "data/data_input_file.hh"
#include "video4linux/video4linux.hh"
+#include "socket/server_socket.hh"
+#include "socket/address.hh"
/// Constructeur
/// @param *filename nom de l'image a utiliser
Live::Live (const unsigned nbImg, const ImageInput imgInput)
- : colorToFind_ (-1), group (0), width_ (640), height_ (480),
- imgInput_ (imgInput)
+ : reader_ (0), db_ (0), st_ (0), colorToFind_ (-1), group (0),
+ width_ (640), height_ (480), imgInput_ (imgInput)
{
if (nbImg < 6) nbImg_ = 6;
else nbImg_ = nbImg;
@@ -62,6 +64,21 @@ Live::init (const Image::PixelFormat pf, const char *filename)
}
break;
case socket:
+ {
+ // Serveur
+ ServerSocket ss (2000);
+ Address a;
+ SocketText *st_ = new SocketText (ss, a);
+ st_->nonblock ();
+ // DataBuffer de reception
+ DataBuffer *db_ = new DataBuffer;
+ // Reception des données
+ while (!st_->recv ());
+ *st_ >> *db_;
+ if (db_->type () != DataBuffer::Image)
+ std::cerr << "<Live::init> Echec de la transmission\n";
+ reader_ = new RawReader (*db_, width_, height_, pf);
+ }
break;
}
img->load (*reader_);
@@ -74,7 +91,9 @@ Live::init (const Image::PixelFormat pf, const char *filename)
segm = new SegmLearn;
segm->setMode (pf);
segm->buildNN (oconfig->nnNbColor, Segm::loadFromFile);
- mag = new Magnifier (img, segm, Group::ZoneType (oconfig->uiGroupToDisplay));
+ eraser = new Eraser (oconfig->width, 10);
+ eraser->init ();
+ mag = new Magnifier (img, segm, eraser, Group::ZoneType (oconfig->uiGroupToDisplay));
segmAndGroup ();
// Affichage de l'image pilote avec la couleur d'aquisition et en RGB
tex[1] = loadImage (img->width_, img->height_, data[0], tex[1]);
@@ -101,9 +120,7 @@ Live::updateImg (const Image::PixelFormat pf, const char *filename)
}
break;
case cam:
- {
std::cout << "<Live::updateImg> Changement d'image caméra" << std::endl;
- }
case socket:
break;
}
@@ -133,6 +150,9 @@ Live::~Live()
delete segm;
delete group;
delete [] data;
+ delete db_;
+ delete st_;
+ delete reader_;
}
/// Recharge le fichier de config
@@ -150,7 +170,7 @@ Live::segmAndGroup (const int numColorToShow)
// Création des groupes
delete group;
- group = new Group (img, segm);
+ group = new Group (img, segm, eraser);
std::vector<Zone> list;
if (numColorToShow >= 0)
{
@@ -179,6 +199,6 @@ Live::segmAndGroup (const int numColorToShow)
// Création de l'image segmentée
img->doImg ();
memcpy (data[2], img->getTabOut (), sizeof (char)*img->nbPixels_*3);
- tex[2] = loadImage(img->width_, img->height_, data[2], tex[2]);
- tex[5] = loadImage(img->width_, img->height_, data[5], tex[5]);
+// tex[2] = loadImage(img->width_, img->height_, data[2], tex[2]);
+// tex[5] = loadImage(img->width_, img->height_, data[5], tex[5]);
}
diff --git a/2005/i/robert/src/ovision/ui/live.hh b/2005/i/robert/src/ovision/ui/live.hh
index 4eac3be..c9137a8 100644
--- a/2005/i/robert/src/ovision/ui/live.hh
+++ b/2005/i/robert/src/ovision/ui/live.hh
@@ -30,6 +30,9 @@
#include "ovision/see/oconfig.hh"
#include "ovision/see/group.hh"
#include "ovision/see/magnifier.hh"
+
+#include "socket/socket_text.hh"
+#include "data/data_buffer.hh"
#define NB_POINTS_UI 6
@@ -38,6 +41,8 @@ class Live
{
unsigned nbImg_;
ImageReader *reader_;
+ DataBuffer *db_;
+ SocketText *st_;
int colorToFind_;
public:
enum ImageInput {file, cam, socket};
@@ -56,6 +61,8 @@ class Live
OConfig *oconfig;
/// classe segmentation
SegmLearn *segm;
+ /// classe eraser
+ Eraser *eraser;
/// classe group
Group *group;
/// classe magnifier
diff --git a/2005/i/robert/src/ovision/ui/liveView.cc b/2005/i/robert/src/ovision/ui/liveView.cc
index 0357456..e903f26 100644
--- a/2005/i/robert/src/ovision/ui/liveView.cc
+++ b/2005/i/robert/src/ovision/ui/liveView.cc
@@ -187,7 +187,7 @@ keyPressed(unsigned char key, int x, int y)
}
}
}
- else if (ii == Live::cam)
+ else if ((ii == Live::cam) || (ii == Live::socket))
{
if (key == ' ')
live->updateImg ();