summaryrefslogtreecommitdiff
path: root/2005/i
diff options
context:
space:
mode:
authorgaillaro2005-04-24 14:19:12 +0000
committergaillaro2005-04-24 14:19:12 +0000
commitac2a19d063c278cf4aeb95dbce818034536ca53d (patch)
tree4ba766d83e962d0d932a8fcee546c4947457235b /2005/i
parentb61c30486959f3838836fbafeb78c79ea0785683 (diff)
* ajout du programme pour l'apprentissage a partir de plusieurs images
* elimination du cercle au dessus de la quille
Diffstat (limited to '2005/i')
-rw-r--r--2005/i/robert/src/ovision/see/Makefile.defs6
-rw-r--r--2005/i/robert/src/ovision/see/colorTable.cc4
-rw-r--r--2005/i/robert/src/ovision/see/colorTable.hh2
-rw-r--r--2005/i/robert/src/ovision/see/group.hh2
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.cc34
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.hh4
-rw-r--r--2005/i/robert/src/ovision/see/n2ml.cc44
-rw-r--r--2005/i/robert/src/ovision/see/ovision.cc3
-rw-r--r--2005/i/robert/src/ovision/see/segmLearn.cc10
-rw-r--r--2005/i/robert/src/ovision/see/segmLearn.hh2
-rw-r--r--2005/i/robert/src/ovision/see/segmTable.cc12
-rw-r--r--2005/i/robert/src/ovision/see/skittle.cc9
-rw-r--r--2005/i/robert/src/ovision/see/skittle.hh2
-rw-r--r--2005/i/robert/src/ovision/see/test_colortable.cc4
-rw-r--r--2005/i/robert/src/ovision/see/test_magnifier.cc4
15 files changed, 113 insertions, 29 deletions
diff --git a/2005/i/robert/src/ovision/see/Makefile.defs b/2005/i/robert/src/ovision/see/Makefile.defs
index 1169670..1b27152 100644
--- a/2005/i/robert/src/ovision/see/Makefile.defs
+++ b/2005/i/robert/src/ovision/see/Makefile.defs
@@ -1,9 +1,10 @@
-PROGRAMS += test_ovision test_img test_group test_map test_ovisiontracker test_cam test_segm test_magnifier test_ovision test_colortable test_space genct
+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
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
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)
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)
@@ -15,9 +16,10 @@ test_map_OBJECTS = test_map.o $(ovision_OBJECTS) $(image_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 group.o img.o segm.o segmLearn.o oconfig.o imgInterface.o skittle.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_img: $(test_img_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)
diff --git a/2005/i/robert/src/ovision/see/colorTable.cc b/2005/i/robert/src/ovision/see/colorTable.cc
index 6d0780f..2b37fcf 100644
--- a/2005/i/robert/src/ovision/see/colorTable.cc
+++ b/2005/i/robert/src/ovision/see/colorTable.cc
@@ -43,7 +43,7 @@ ColorTable::create (const int nbOutput_, const bool testOutputMax)
{
// Remplissage de la table
x[0]=i; x[1]=j; x[2]=k;
- data_[ i*colorTabSize2 + j*colorTabSize +k ] = segm.giveColor (x , testOutputMax);
+ data_[ i*colorTabSize2 + j*colorTabSize +k ] = segm.giveColor (x , testOutputMax, true);
}
}
@@ -71,7 +71,7 @@ ColorTable::load (const char *filename)
delete [] data_;
data_ = new unsigned char[colorTabSizeTotal];
/// Ouverture du fichier de couleurs
- gzFile file = gzopen (filename, "w+");
+ gzFile file = gzopen (filename, "r");
if (file)
{
std::cout << "ColorTable:: Chargement de la table" << std::endl;
diff --git a/2005/i/robert/src/ovision/see/colorTable.hh b/2005/i/robert/src/ovision/see/colorTable.hh
index 894fc90..f9613fc 100644
--- a/2005/i/robert/src/ovision/see/colorTable.hh
+++ b/2005/i/robert/src/ovision/see/colorTable.hh
@@ -38,7 +38,7 @@ class ColorTable
/// Destructeur
virtual ~ColorTable ();
/// Cree un tableau des couleurs segmentées pour ne plus faire de calcul
- void create(const int nbOutput, const bool testOutputMax = false);
+ void create(const int nbOutput, const bool testOutputMax = true);
/// Cree un fichier de ColorTable
void save (const char *filename = "../runtime/rc/colortable.z") const;
/// Charge un fichier de ColorTable
diff --git a/2005/i/robert/src/ovision/see/group.hh b/2005/i/robert/src/ovision/see/group.hh
index ff5cae7..d84328b 100644
--- a/2005/i/robert/src/ovision/see/group.hh
+++ b/2005/i/robert/src/ovision/see/group.hh
@@ -57,6 +57,8 @@ struct Zone
double ratio;
/// orientation
double pcX, pcY;
+ /// density
+ double density;
};
/// Cree une liste chainee de zones correspondant aux balles
diff --git a/2005/i/robert/src/ovision/see/magnifier.cc b/2005/i/robert/src/ovision/see/magnifier.cc
index 82485b4..e819437 100644
--- a/2005/i/robert/src/ovision/see/magnifier.cc
+++ b/2005/i/robert/src/ovision/see/magnifier.cc
@@ -11,18 +11,16 @@
/// Constructeur
Magnifier::Magnifier (Img *img, Segm *segm, Group::ZoneType aim)
-: segm_ (segm), img_ (img), aim_ (aim), skittleList_ (0)
+: segm_ (segm), img_ (img), aim_ (aim)
{
oconfig_ = OConfig::getInstance ();
itemList_ = new std::vector<Zone>[Group::nbZoneType];
- skittleList_ = new std::vector<Skittle>;
}
/// Destructeur
Magnifier::~Magnifier (void)
{
delete [] itemList_;
- delete skittleList_;
}
@@ -62,11 +60,12 @@ Magnifier::analyse (std::vector<Zone> &zoneList)
continue;
add (*iter, itemList_);
}
+ // parcours des zones jusqu'à ce qu'il n'y ai plus de changement à faire
while (scan ());
- skittleList_->clear ();
+ // analyse des objets trouvés
if (itemList_[aim_].size () != 0)
{
- bool find = 0;
+ bool find = false;
for (std::vector<Zone>::iterator iter = itemList_[aim_].begin ();
iter != itemList_[aim_].end (); ++iter)
{
@@ -75,9 +74,8 @@ Magnifier::analyse (std::vector<Zone> &zoneList)
{
showZone (*iter);
s->show ();
- skittleList_->push_back (*s);
delete s;
- find = 1;
+ find = true;
}
}
return find;
@@ -90,20 +88,33 @@ Magnifier::scan ()
{
bool hasChanged = false;
std::vector<Zone> *newList = new std::vector<Zone>[Group::nbZoneType];
+ int dist;
+ bool find;
for (int i=0; i <Group::nbZoneType; ++i)
{
- for(std::vector<Zone>::iterator iter = itemList_[i].begin (); iter != itemList_[i].end (); ++iter)
+ for (std::vector<Zone>::iterator iter = itemList_[i].begin (); iter != itemList_[i].end (); ++iter)
{
if (!checkIsUnique (*iter, newList))
{
hasChanged = true;
continue;
}
- add (*iter, newList);
+ // on regarde s'il une zone noire est situé en dessous pour virer le cercle supérieur des quilles
+ find = false;
+ dist = iter->ymax - iter->ymin;
+ for (std::vector<Zone>::iterator jter = iter+1; jter != itemList_[i].end (); ++jter)
+ {
+ if ((iter->ymax + dist > jter->ymin) && (abs(iter->xmin - jter->xmin) < 40) && (abs(iter->xmax - jter->xmax) < 40))
+ {
+ find = true;
+ break;
+ }
+ }
+ if (!find) add (*iter, newList);
}
-// delete [] itemList_;
- itemList_ = newList;
}
+ delete [] itemList_;
+ itemList_ = newList;
return hasChanged;
}
@@ -310,6 +321,7 @@ 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> alone : " << z.alone << "\n";
+ std::cout << "<Magnifier::showZone> density: " << z.density << "\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";
diff --git a/2005/i/robert/src/ovision/see/magnifier.hh b/2005/i/robert/src/ovision/see/magnifier.hh
index 58e05de..f569a88 100644
--- a/2005/i/robert/src/ovision/see/magnifier.hh
+++ b/2005/i/robert/src/ovision/see/magnifier.hh
@@ -43,8 +43,6 @@ class Magnifier
std::vector<Zone> *itemList_;
/// Cible
Group::ZoneType aim_;
- /// Liste de quilles
- std::vector<Skittle> *skittleList_;
public:
/// Constructeur
@@ -56,7 +54,7 @@ class Magnifier
/// 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)
+ std::vector<Zone>& getItemList (Group::ZoneType type) const
{return itemList_[type];}
/// Affiche des infos sur une zone
void showZone (const Zone &z) const;
diff --git a/2005/i/robert/src/ovision/see/n2ml.cc b/2005/i/robert/src/ovision/see/n2ml.cc
new file mode 100644
index 0000000..730d05e
--- /dev/null
+++ b/2005/i/robert/src/ovision/see/n2ml.cc
@@ -0,0 +1,44 @@
+// n2ml.cc
+// robert - Programme du robot APBteam
+// Copyright (C) 2005 Olivier Gaillard
+#include <iostream>
+#include <vector>
+#include <string>
+
+#include "imgInterface.hh"
+#include "segmLearn.hh"
+#include "oconfig.hh"
+
+
+int main(int argc, char **argv)
+{
+ // Usage
+ if (argc < 4)
+ {
+ std::cout << "Usage : n2ml <output number> {rgb| yuv} <file list>" << std::endl;
+ return 1;
+ }
+ int nbOutput = atoi(argv[1]);
+ // Parse de la ligne de commande
+ std::string *str = new std::string (argv[2]);
+ Image::PixelFormat pf;
+ if (*str == "rgb") pf = Image::rgb;
+ else if (*str == "yuv") pf = Image::yuv;
+ else std::cerr << "Wrong pixelformat\n";
+ std::vector<std::string> list;
+ while (argc-- > 3)
+ {
+ delete str;
+ str = new std::string (argv[argc]);
+ list.push_back(*str);
+ }
+ // Initialisation des classes
+ OConfig oconfig;
+ Img img;
+ img.loadMultipeRaw (list, pf, 360, 296);
+ SegmLearn segm;
+ segm.buildNN (nbOutput, Segm::generate);
+ segm.trainNN (&img);
+ segm.save ();
+}
+
diff --git a/2005/i/robert/src/ovision/see/ovision.cc b/2005/i/robert/src/ovision/see/ovision.cc
index 126c28a..d15bbf7 100644
--- a/2005/i/robert/src/ovision/see/ovision.cc
+++ b/2005/i/robert/src/ovision/see/ovision.cc
@@ -47,6 +47,7 @@ OVision::init (const Group::ZoneType aim)
space_->addSetupPoint (237, 224, 100, 900);
space_->addSetupPoint (275, 113, 100, 550);
space_->setup (0.00891157, 0.258144, 403.801);
+}
/// Prends une image avec la caméra
void
@@ -92,7 +93,7 @@ OVision::showInfo () const
std::vector<Zone>&
OVision::getSkittles () const
{
- return mag_->getItemList (aim_);
+ return mag_->getItemList(aim_);
}
/// Renvoie le pointeur sur Video4Linux
diff --git a/2005/i/robert/src/ovision/see/segmLearn.cc b/2005/i/robert/src/ovision/see/segmLearn.cc
index b2a0a83..4ddf7d8 100644
--- a/2005/i/robert/src/ovision/see/segmLearn.cc
+++ b/2005/i/robert/src/ovision/see/segmLearn.cc
@@ -167,6 +167,16 @@ SegmLearn::findColorNN (const unsigned char *x, const bool testOutputMax) const
}
+/// Sauvegarde les poids
+void
+SegmLearn::save (char *filename)
+{
+ delete [] oconfig_->node;
+ oconfig_->node = new unsigned char[nbOutput_*3];
+ memcpy (oconfig_->node, node_, nbOutput_*3);
+ oconfig_->createNNFile(filename, nbOutput_);
+ std::cout << nbOutput_ << std::endl;
+}
/// Renvoie le code de la couleur segmentee
diff --git a/2005/i/robert/src/ovision/see/segmLearn.hh b/2005/i/robert/src/ovision/see/segmLearn.hh
index 464e233..d4d8a79 100644
--- a/2005/i/robert/src/ovision/see/segmLearn.hh
+++ b/2005/i/robert/src/ovision/see/segmLearn.hh
@@ -42,6 +42,8 @@ class SegmLearn : public Segm
void buildNN (const int nbOutput, const bool loadFromFile = false);
/// Renvoie le code la couleur segmentee
virtual unsigned char giveColor (const unsigned char *x, const bool testUndefined = false, const bool indexProcess = false, const bool lumFlag = false);
+ /// Sauvegarde les poids
+ void save (char *filename = "../runtime/rc/poids");
private:
/// Genere des poids pour un noeud
diff --git a/2005/i/robert/src/ovision/see/segmTable.cc b/2005/i/robert/src/ovision/see/segmTable.cc
index ff428e2..919107f 100644
--- a/2005/i/robert/src/ovision/see/segmTable.cc
+++ b/2005/i/robert/src/ovision/see/segmTable.cc
@@ -15,6 +15,10 @@
SegmTable::SegmTable (ColorTable &tab)
: tab_ (tab)
{
+ index_ = new int[nbOutput_];
+ for (int i = 0; i<nbOutput_; i++)
+ index_[i] = oconfig_->index[i];
+
}
/// Donne la couleur à partir du tableau
@@ -23,8 +27,8 @@ unsigned char
SegmTable::giveColor (const unsigned char *x, const bool testOutputMax, const bool index_Process, const bool lumFlag)
{
if (lumFlag && (lumPos_ >= 0)) addLum (x[lumPos_]);
-// if (index_Process)
- return index_ [tab_[(int) (x[0] * ColorTable::colorTabSize2 + x[1] * ColorTable::colorTabSize + x[2]) ]];
-// else
-// return colorTable_[ x[0]*colorTabSize2 + x[1]*colorTabSize + x[2] ];
+ // if (index_Process)
+ return tab_[(int) (x[0] * ColorTable::colorTabSize2 + x[1] * ColorTable::colorTabSize + 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 f50705d..f8437d5 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 (const Zone &zone)
+Skittle::pca (Zone &zone)
{
// Agrandissement de la zone de recherche
const int grow = oconfig_->skittleGrow;
@@ -35,7 +35,9 @@ Skittle::pca (const Zone &zone)
int jump = oconfig_->jumpPointDist/oconfig_->skittleDivJump;
if (!jump) jump = 1;
// 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)
{
@@ -46,8 +48,13 @@ Skittle::pca (const Zone &zone)
// *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))
+ ++nbPoints;
}
}
+ // Calcul de la densité
+ zone.area = (zone.xmax - zone.xmin) * (zone.ymax - zone.ymin);
+ zone.density = nbPoints * jump * jump / (double)zone.area;
// Calcul de la composante principale
Hotelling hote (l);
hote.eigenVectors ();
diff --git a/2005/i/robert/src/ovision/see/skittle.hh b/2005/i/robert/src/ovision/see/skittle.hh
index 0fb5de4..df87b48 100644
--- a/2005/i/robert/src/ovision/see/skittle.hh
+++ b/2005/i/robert/src/ovision/see/skittle.hh
@@ -70,7 +70,7 @@ class Skittle
private:
/// Recherche de la composante principale
- void pca (const Zone &zone);
+ void pca (Zone &zone);
/// Recherche de du côté de la courbure
Pos bend (const Zone &zone);
/// Utilisé pour la recherche de la courbure, cherche le point le plus haut
diff --git a/2005/i/robert/src/ovision/see/test_colortable.cc b/2005/i/robert/src/ovision/see/test_colortable.cc
index 6c9f57e..8f78a4c 100644
--- a/2005/i/robert/src/ovision/see/test_colortable.cc
+++ b/2005/i/robert/src/ovision/see/test_colortable.cc
@@ -1,4 +1,4 @@
-// test_group.cc
+// test_colortable.cc
// robert - Programme du robot APBteam
// Copyright (C) 2005 Olivier Gaillard
@@ -42,7 +42,7 @@ main(int argc, char **argv)
// Création de l'image segmentée
segm.segmImg (&img);
img.doImg ();
- img.writeRaw ("../runtime/shots/segm.rgb");
+ img.writeRaw ("../runtime/shots/segm.rgb", img.getTabOut ());
return 0;
}
diff --git a/2005/i/robert/src/ovision/see/test_magnifier.cc b/2005/i/robert/src/ovision/see/test_magnifier.cc
index 91eabd0..2840740 100644
--- a/2005/i/robert/src/ovision/see/test_magnifier.cc
+++ b/2005/i/robert/src/ovision/see/test_magnifier.cc
@@ -33,8 +33,10 @@ main(int argc, char **argv)
img.loadRaw ("../runtime/shots/test.rgb", Image::rgb, 360, 296);
SegmLearn segm;
segm.buildNN (oconfig_->nnNbColor, Segm::loadFromFile);
+// ColorTable tab;
+// SegmTable segm (tab);
Group group (&img, &segm);
- Magnifier mag (&img, &segm);
+ Magnifier mag (&img, &segm, Group::redSkittle);
/////////////////////////////////////////////////////////////////////////////////////////
/// Initialise les couleurs à chercher
std::vector<ObjectColor> colorList;