summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert/src/ovision')
-rw-r--r--2005/i/robert/src/ovision/see/Makefile.defs4
-rw-r--r--2005/i/robert/src/ovision/see/group.cc8
-rw-r--r--2005/i/robert/src/ovision/see/group.hh3
-rw-r--r--2005/i/robert/src/ovision/see/hotelling.cc5
-rw-r--r--2005/i/robert/src/ovision/see/hotelling.hh28
-rw-r--r--2005/i/robert/src/ovision/see/hpoint.hh53
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.cc50
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.hh1
8 files changed, 115 insertions, 37 deletions
diff --git a/2005/i/robert/src/ovision/see/Makefile.defs b/2005/i/robert/src/ovision/see/Makefile.defs
index 92b9671..0f0e61a 100644
--- a/2005/i/robert/src/ovision/see/Makefile.defs
+++ b/2005/i/robert/src/ovision/see/Makefile.defs
@@ -2,7 +2,7 @@ PROGRAMS += test_ovision test_img test_group test_map test_ovisiontracker test_c
LIBS += $(ovision_OBJECTS)
LDFLAGS= -Wall -g -fprofile-arcs -ftest-coverage -fmessage-length=0
-ovision_OBJECTS = convertImg.o img.o oconfig.o ovision.o segm.o imgInterface.o colorTable.o segmTable.o segmLearn.o group.o magnifier.o #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 #space.o map.o
test_img_OBJECTS = test_img.o img.o imgInterface.o oconfig.o $(image_OBJECTS)
test_hotelling_OBJECTS = test_hotelling.o hotelling.o oconfig.o
@@ -15,7 +15,7 @@ test_map_OBJECTS = test_map.o $(ovision_OBJECTS) $(image_OBJECTS)
test_dist_OBJECTS = test_dist.o $(ovision_OBJECTS)
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 magnifier.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 $(image_OBJECTS)
test_img: $(test_img_OBJECTS:%.o=%.o)
test_hotelling: $(test_hotelling_OBJECTS:%.o=%.o)
diff --git a/2005/i/robert/src/ovision/see/group.cc b/2005/i/robert/src/ovision/see/group.cc
index 56aaa55..8bb80b6 100644
--- a/2005/i/robert/src/ovision/see/group.cc
+++ b/2005/i/robert/src/ovision/see/group.cc
@@ -30,7 +30,7 @@ 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;
-
+ zone.color = idColor;
for (std::vector<ObjectColor>::iterator iter = oconfig_->groupColor.begin ();
iter != oconfig_->groupColor.end (); ++iter)
if (idColor == iter->color)
@@ -42,7 +42,6 @@ Group::addZone (const int idColor, const int xmin, const int xmax, const int ymi
else if (iter->label == "gap") zone.id = gap;
break;
}
-
zoneList_.push_back (zone);
}
@@ -98,10 +97,10 @@ void Group::jumpPoints (int color)
void Group::jumpPoints (const std::vector<ObjectColor> &colorList)
{
+ // Initialisation
zoneList_.clear ();
segm_->clearLum ();
segm_->setMode (img_->colorMode_);
-
int tmpY;
unsigned char curColor;
std::vector<ObjectColor>::const_iterator iter;
@@ -112,11 +111,10 @@ void Group::jumpPoints (const std::vector<ObjectColor> &colorList)
for (int x=0; x<img_->width_; x+=oconfig_->jumpPointDist)
{
curColor = segm_->giveColor (img_->tabData_ + ((tmpY + x) * 3), true, true);
-
for (iter = colorList.begin (); iter != colorList.end (); ++iter)
if ((iter->color >= 0) && (iter->color == curColor))
{
- plague(curColor, x, y);
+ plague (curColor, x, y);
break;
}
}
diff --git a/2005/i/robert/src/ovision/see/group.hh b/2005/i/robert/src/ovision/see/group.hh
index 3aa0730..b1a449c 100644
--- a/2005/i/robert/src/ovision/see/group.hh
+++ b/2005/i/robert/src/ovision/see/group.hh
@@ -28,6 +28,7 @@
#include "img.hh"
#include "segm.hh"
#include "oconfig.hh"
+#include "hpoint.hh"
/// Liste chainee des zones trouvees par la classe group
struct Zone
@@ -44,6 +45,8 @@ struct Zone
bool partial;
/// l'objet est situé en bas de l'image
bool bottom;
+ /// couleur de la zone
+ int color;
};
/// Cree une liste chainee de zones correspondant aux balles
diff --git a/2005/i/robert/src/ovision/see/hotelling.cc b/2005/i/robert/src/ovision/see/hotelling.cc
index ac490d0..c15ba0b 100644
--- a/2005/i/robert/src/ovision/see/hotelling.cc
+++ b/2005/i/robert/src/ovision/see/hotelling.cc
@@ -3,6 +3,7 @@
// Copyright (C) 2005 Olivier Gaillard
#include <iostream>
+#include <math.h>
#include "hotelling.hh"
@@ -126,8 +127,10 @@ Hotelling::showCovMatrix () const
/// Affiche les eigenvectors
void
-Hotelling::showEigenVectors () const
+Hotelling::show () const
{
+ std::cout << "EigenValues :\n"
+ << "\t" << val1_ << ", " << val2_ << "\n";
std::cout << "EigenVectors :\n"
<< "\t" << e1_[0] << ", " << e1_[1] << "\n"
<< "\t" << e2_[0] << ", " << e2_[1] << std::endl;
diff --git a/2005/i/robert/src/ovision/see/hotelling.hh b/2005/i/robert/src/ovision/see/hotelling.hh
index 8acf3b3..ba32027 100644
--- a/2005/i/robert/src/ovision/see/hotelling.hh
+++ b/2005/i/robert/src/ovision/see/hotelling.hh
@@ -26,31 +26,7 @@
#include <vector>
#include "oconfig.hh"
-
-class Hpoint
-{
- double p_[2];
- public:
- Hpoint () {p_[0]=0; p_[1]=0;}
- Hpoint (const int i, const int j) {set (i, j);}
- inline double operator [] (const unsigned i) const {return i<2?p_[i]:0;}
- inline Hpoint& operator = (Hpoint &h)
- {
- if (&h != this)
- {
- h.p_[0] = p_[0];
- h.p_[1] = p_[1];
- }
- return *this;
- }
- inline void set (const double i, const double j)
- {p_[0]=i; p_[1]=j;}
- inline void norm ()
- {
- double n = sqrt (p_[0]*p_[0] + p_[1]*p_[1]);
- p_[0] /= n; p_[1] /= n;
- }
-};
+#include "hpoint.hh"
/// Detecte l'orientation principale d'une masse de données
class Hotelling
@@ -78,7 +54,7 @@ class Hotelling
/// Affiche la matrice de covariance
void showCovMatrix () const;
/// Affiche les eigenvectors
- void showEigenVectors () const;
+ void show () const;
/// Calcul des eigenvectors
void eigenVectors ();
/// Accessors
diff --git a/2005/i/robert/src/ovision/see/hpoint.hh b/2005/i/robert/src/ovision/see/hpoint.hh
new file mode 100644
index 0000000..bc4d54e
--- /dev/null
+++ b/2005/i/robert/src/ovision/see/hpoint.hh
@@ -0,0 +1,53 @@
+// 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 hpoint_h
+#define hpoint_h
+
+#include <math.h>
+
+class Hpoint
+{
+ double p_[2];
+ public:
+ Hpoint () {p_[0]=0; p_[1]=0;}
+ Hpoint (const int i, const int j) {set (i, j);}
+ inline double operator [] (const unsigned i) const {return i<2?p_[i]:0;}
+ inline Hpoint& operator = (Hpoint &h)
+ {
+ if (&h != this)
+ {
+ p_[0] = h.p_[0];
+ p_[1] = h.p_[1];
+ }
+ return *this;
+ }
+ inline void set (const double i, const double j)
+ {p_[0]=i; p_[1]=j;}
+ inline void norm ()
+ {
+ double n = sqrt (p_[0]*p_[0] + p_[1]*p_[1]);
+ p_[0] /= n; p_[1] /= n;
+ }
+};
+
+#endif // hpoint_h
diff --git a/2005/i/robert/src/ovision/see/magnifier.cc b/2005/i/robert/src/ovision/see/magnifier.cc
index 067bae3..c7d5dc0 100644
--- a/2005/i/robert/src/ovision/see/magnifier.cc
+++ b/2005/i/robert/src/ovision/see/magnifier.cc
@@ -5,6 +5,7 @@
#include <iostream>
#include "magnifier.hh"
+#include "hotelling.hh"
/// Constructeur
Magnifier::Magnifier (Img *img, Segm *segm)
@@ -74,6 +75,8 @@ Magnifier::analyse (const std::vector<Zone> &zoneList)
break;
}
}
+ Zone &z = itemList_[Group::redSkittle][0];
+ isSkittle (z);
}
@@ -81,7 +84,7 @@ Magnifier::analyse (const std::vector<Zone> &zoneList)
bool
Magnifier::checkIsUnique (const Zone &zone)
{
- const int uniqueness = 50;
+ const int uniqueness = 200;
for (std::vector<Zone>::iterator iter = itemList_[zone.id].begin ();
iter != itemList_[zone.id].end (); ++iter)
if ((abs (zone.centerx - iter->centerx) < uniqueness)
@@ -93,13 +96,54 @@ Magnifier::checkIsUnique (const Zone &zone)
if (zone.xmax > iter->xmax) iter->xmax = zone.xmax;
if (zone.ymax > iter->ymax) iter->ymax = zone.ymax;
- iter->centerx = (iter->xmax - iter->xmin) / 2;
- iter->centery = (iter->ymax - iter->ymin) / 2;
+ iter->centerx = (iter->xmax + iter->xmin) / 2;
+ iter->centery = (iter->ymax + iter->ymin) / 2;
return false;
}
return true;
}
+/// Test si l'objet est une quille
+bool
+Magnifier::isSkittle (Zone &zone)
+{
+ // Agrandissement de la zone de recherche
+ const int grow = 20;
+ int ymin = (zone.ymin - grow);
+ ymin = (ymin > 0) ? ymin : 0;
+ int ymax = (zone.ymax + grow);
+ ymax = (ymax < img_->height_) ? ymax : img_->height_;
+ int xmin = (zone.xmin - grow);
+ xmin = (xmin > 0) ? xmin : 0;
+ int xmax = (zone.xmax + grow);
+ xmax = (xmax < img_->width_) ? xmax : img_->width_;
+ // Parcours d'une partie des pixels de l'image
+ int tmpY;
+ int jump = oconfig_->jumpPointDist/5;
+ if (!jump) jump = 1;
+ std::vector<Hpoint> l;
+ for (int y = zone.ymin - grow; y < zone.ymax + grow; y += jump)
+ {
+ tmpY = y*img_->width_;
+ for (int x=zone.xmin - grow; x < zone.xmax + grow; x += jump)
+ if (segm_->giveColor (img_->tabData_ + ((tmpY + x) * 3), true, true) == zone.color)
+ {
+ Hpoint h (x, y);
+ l.push_back (h);
+ }
+ }
+ // Calcul de la composante principale
+ for (std::vector<Hpoint>::iterator iter = l.begin (); iter != l.end (); ++iter)
+ std::cout << (*iter)[0] << " " << (*iter)[1] << std::endl;
+ Hotelling hote (l);
+ hote.eigenVectors ();
+ double i, j;
+ hote.getPC (i, j);
+ hote.show ();
+ std::cout << "PC : " << i << " " << j << std::endl;
+ return true;
+}
+
/// Test si l'objet est une quille rouge
bool
Magnifier::isRedSkittle (const Zone &zone) const
diff --git a/2005/i/robert/src/ovision/see/magnifier.hh b/2005/i/robert/src/ovision/see/magnifier.hh
index 1d7aa67..021f872 100644
--- a/2005/i/robert/src/ovision/see/magnifier.hh
+++ b/2005/i/robert/src/ovision/see/magnifier.hh
@@ -61,6 +61,7 @@ class Magnifier
/// Test si l'object s'agit d'un doublon
bool checkIsUnique (const Zone &zone);
/// Test la validité des objects
+ bool isSkittle (Zone &zone);
bool isRedSkittle (const Zone &zone) const;
bool isGreenSkittle (const Zone &zone) const;
bool isBase (const Zone &zone) const;