summaryrefslogtreecommitdiff
path: root/2005/i/robert
diff options
context:
space:
mode:
Diffstat (limited to '2005/i/robert')
-rw-r--r--2005/i/robert/src/ovision/see/Makefile.defs4
-rw-r--r--2005/i/robert/src/ovision/see/img.hh4
-rw-r--r--2005/i/robert/src/ovision/see/magnifier.cc3
-rw-r--r--2005/i/robert/src/ovision/see/ovision.cc36
-rw-r--r--2005/i/robert/src/ovision/see/ovision.hh8
-rw-r--r--2005/i/robert/src/ovision/see/space.cc11
-rw-r--r--2005/i/robert/src/ovision/see/space.hh2
-rw-r--r--2005/i/robert/src/ovision/see/test_cam.cc6
-rw-r--r--2005/i/robert/src/ovision/see/test_ovision.cc9
-rw-r--r--2005/i/robert/src/ovision/ui/Makefile.defs4
-rw-r--r--2005/i/robert/src/ovision/ui/comm.cc3
-rw-r--r--2005/i/robert/src/ovision/ui/live.cc54
12 files changed, 102 insertions, 42 deletions
diff --git a/2005/i/robert/src/ovision/see/Makefile.defs b/2005/i/robert/src/ovision/see/Makefile.defs
index 2f2b930..9bd7f33 100644
--- a/2005/i/robert/src/ovision/see/Makefile.defs
+++ b/2005/i/robert/src/ovision/see/Makefile.defs
@@ -9,8 +9,9 @@ n2ml_OBJECTS = n2ml.o oconfig.o img.o segm.o segmLearn.o $(image_OBJECTS) $(data
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) $(data_OBJECTS) $(net_OBJECTS)
+test_cam_socket_OBJECTS = test_cam_socket.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_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)
@@ -25,6 +26,7 @@ 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_cam_socket: $(test_cam_socket_OBJECTS:%.o=%.o)
test_segm: $(test_segm_OBJECTS:%.o=%.o)
test_group: $(test_group_OBJECTS:%.o=%.o)
test_magnifier: $(test_magnifier_OBJECTS:%.o=%.o)
diff --git a/2005/i/robert/src/ovision/see/img.hh b/2005/i/robert/src/ovision/see/img.hh
index 5033bbf..f88fecd 100644
--- a/2005/i/robert/src/ovision/see/img.hh
+++ b/2005/i/robert/src/ovision/see/img.hh
@@ -63,6 +63,10 @@ class Img
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;}
+ /// Get data image buffer.
+ inline unsigned char * getBuffer (void) const { return tabData_; }
+ /// Get the size of the image (height * width * 3).
+ inline unsigned long size (void) const { return nbPixels_; }
private:
/// Crée le tableau Y
diff --git a/2005/i/robert/src/ovision/see/magnifier.cc b/2005/i/robert/src/ovision/see/magnifier.cc
index 8ac1eb4..f4ac2f1 100644
--- a/2005/i/robert/src/ovision/see/magnifier.cc
+++ b/2005/i/robert/src/ovision/see/magnifier.cc
@@ -43,6 +43,7 @@ Magnifier::~Magnifier (void)
bool
Magnifier::analyse (std::vector<Zone> &zoneList)
{
+ std::cout << zoneList.size () << std::endl;
// remise à zéro de toutes les listes
for (int i=0; i<Group::nbZoneType; ++i)
itemList_[i].clear ();
@@ -362,4 +363,4 @@ Magnifier::showZone (const Zone &z) const
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/ovision.cc b/2005/i/robert/src/ovision/see/ovision.cc
index 734a789..e16539a 100644
--- a/2005/i/robert/src/ovision/see/ovision.cc
+++ b/2005/i/robert/src/ovision/see/ovision.cc
@@ -81,8 +81,11 @@ OVision::init (const Group::ZoneType aim)
v4l_->calibrate ();
// Prendre une image pour que la taille de l'image soit configuré
img_->load (*v4l_);
- segm_ = new SegmTable (*colorTab_);
+// segm_ = new SegmTable (*colorTab_);
+// segm_->setMode (oconfig_->inputColor);
+ segm_ = new SegmLearn;
segm_->setMode (oconfig_->inputColor);
+ segm_->buildNN (oconfig_->nnNbColor, Segm::loadFromFile);
eraser_ = new Eraser (oconfig_->width, 10);
eraser_->init ();
group_ = new Group (img_, segm_, eraser_);
@@ -111,9 +114,10 @@ OVision::update ()
// Compteur du nombre d'image traité
step_++;
// Cherche les balles
- group_->jumpPoints (oconfig_->groupColor);
+ // group_->jumpPoints (oconfig_->groupColor);
+ //group_->jumpPoints (0);
// Analyse et tri la liste de zones trouvées
- mag_->analyse (group_->getZoneList ());
+ //mag_->analyse (group_->getZoneList ());
// Parcours la liste de balles trouvées
/* if (group_->zoneListBall)
{
@@ -123,23 +127,33 @@ OVision::update ()
space->GetLoc (x, y, x, y);
}
*/
+ // Création des groupes
+ Group group (img_, segm_, eraser_);
+ std::vector<Zone> list;
+ group.jumpPoints(oconfig_->groupColor);
+ mag_->analyse (group.getZoneList ());
+ std::vector<Zone> &l = mag_->getItemList (Group::greenSkittle);
+ for (std::vector<Zone>::iterator iter = l.begin ();
+ iter != l.end (); ++iter)
+ {
+ mag_->showZone (*iter);
+ }
+ std::ostringstream ss;
+ ss << "vis" << step_ << ".yuv";
+ std::string name = ss.str ();
+ img_->writeRaw (name.c_str ());
}
/// Affiche d'info sur l'update
void
-OVision::showInfo () const
+OVision::showInfo (const Zone &zone) 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;
+ mag_->showZone (zone);
}
/// 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)
+OVision::getLoc (Zone &zone, int &x, int &y, double &angle, int &dist)
{
space_->getRealLoc (zone, x, y, angle, dist);
}
diff --git a/2005/i/robert/src/ovision/see/ovision.hh b/2005/i/robert/src/ovision/see/ovision.hh
index 6d3b892..8ecc230 100644
--- a/2005/i/robert/src/ovision/see/ovision.hh
+++ b/2005/i/robert/src/ovision/see/ovision.hh
@@ -25,6 +25,7 @@
#include "oconfig.hh"
#include "segmTable.hh"
+#include "segmLearn.hh"
#include "group.hh"
#include "magnifier.hh"
#include "colorTable.hh"
@@ -40,7 +41,7 @@ class OVision
OConfig *oconfig_;
Img *img_;
ColorTable *colorTab_;
- SegmTable *segm_;
+ SegmLearn *segm_;
Eraser *eraser_;
Group *group_;
Magnifier *mag_;
@@ -66,15 +67,16 @@ class OVision
/// Envoie l'image par socket
void sendImg ();
/// Affiche d'info sur l'update
- void showInfo () const;
+ void showInfo (const Zone &zone) const;
/// Renvoie la liste des quilles
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
/// Donne l'angle du robot par rapport à la balle + distance
- void getLoc (Zone &zone, int &x, int &y, int &angle, int &dist);
+ void getLoc (Zone &zone, int &x, int &y, double &angle, int &dist);
void readColorSkittle (ObjectColor &o);
+
};
#endif // ovision_h
diff --git a/2005/i/robert/src/ovision/see/space.cc b/2005/i/robert/src/ovision/see/space.cc
index efba67b..4133830 100644
--- a/2005/i/robert/src/ovision/see/space.cc
+++ b/2005/i/robert/src/ovision/see/space.cc
@@ -163,7 +163,7 @@ Space::getPos (const double locX, const double locY, const double posRobotX, con
/// Give Real Location dist and angle
void
-Space::getRealLoc (Zone &zone, int &x, int &y, int &angle, int &dist)
+Space::getRealLoc (Zone &zone, int &x, int &y, double &angle, int &dist)
{
// we want a pcY positive to sub it to centery
double newPcX, newPcY;
@@ -180,10 +180,15 @@ Space::getRealLoc (Zone &zone, int &x, int &y, int &angle, int &dist)
// we are looking for the bottom of the object
int tmpX = (int)((zone.xmax - zone.centerx) * newPcX + zone.centerx);
int tmpY = (int)((zone.ymax - zone.centery) * newPcY + zone.centery);
- std::cout << "<Space::getRealLoc> : "<< tmpX << " " << tmpY << "\n";
int newX, newY;
getLoc (tmpX, tmpY, newX, newY);
- angle = (int)(atan ((double)newX / ((double)newY + 90)));
+ newY += 90;
+ angle = (atan ((double)newX / ((double)newY)));
+ // correction de la calibration a l'arrache
+ angle += .174;
+ newX = (int)(newX * cos (.174));
+ newY = (int)(newY * cos (.174));
x = newX; y = newY;
dist = (int)sqrt (y*y + x*x);
+ std::cout << "<Space::getRealLoc> : "<< x << " " << y << " " << dist << " " << angle*360.0f/3.1415f/2.0f << "\n";
}
diff --git a/2005/i/robert/src/ovision/see/space.hh b/2005/i/robert/src/ovision/see/space.hh
index 7e9f7e8..a55eaf1 100644
--- a/2005/i/robert/src/ovision/see/space.hh
+++ b/2005/i/robert/src/ovision/see/space.hh
@@ -57,7 +57,7 @@ class Space
void getPos (const double locX, const double locY, const double posRobotX,
const double posRobotY, const double angleRobot, double &posX, double &posY);
/// Give Real Location dist and angle
- void getRealLoc (Zone &zone, int &x, int &y, int &angle, int &dist);
+ void getRealLoc (Zone &zone, int &x, int &y, double &angle, int &dist);
/// Ajoute un point pour l'etalonnage
void addSetupPoint (const int x, const int y, const int distx, const int disty);
/// Chargement des points a partir d'un fichier
diff --git a/2005/i/robert/src/ovision/see/test_cam.cc b/2005/i/robert/src/ovision/see/test_cam.cc
index f7dd315..799cbd1 100644
--- a/2005/i/robert/src/ovision/see/test_cam.cc
+++ b/2005/i/robert/src/ovision/see/test_cam.cc
@@ -21,13 +21,13 @@ int main(int argc, char **argv)
{
// Initialisation des classes
Img img;
- OConfig config;
+ OConfig oconfig;
// Acquisition de l'image et sauvegarde
if (argv[1]) ;
else
{
- Image::PixelFormat pf = Image::yuv;
- Video4Linux vid ("/dev/video", pf);
+ Video4Linux vid ("/dev/video", oconfig.width, oconfig.height,
+ oconfig.inputColor, oconfig.brightness);
vid.calibrate ();
img.load (vid);
}
diff --git a/2005/i/robert/src/ovision/see/test_ovision.cc b/2005/i/robert/src/ovision/see/test_ovision.cc
index c86c37d..765df94 100644
--- a/2005/i/robert/src/ovision/see/test_ovision.cc
+++ b/2005/i/robert/src/ovision/see/test_ovision.cc
@@ -25,7 +25,8 @@ main(int argv, char **argc)
}
OVision ovision;
ovision.init (aim);
- int t = 50;
+
+ int t = 200;
while (t--)
{
// Prends une image
@@ -42,8 +43,10 @@ main(int argv, char **argc)
std::vector<Zone> &z = ovision.getSkittles ();
for (unsigned i=0; i < z.size (); ++i)
{
- int x, y, dist, angle;
- ovision.getLoc (z[i], x, y, dist, angle);
+ int x, y, dist;
+ double angle;
+// ovision.showInfo (z[i]);
+ ovision.getLoc (z[i], x, y, angle, dist);
}
usleep (500000);
}
diff --git a/2005/i/robert/src/ovision/ui/Makefile.defs b/2005/i/robert/src/ovision/ui/Makefile.defs
index b88f318..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) #$(net_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 0065bd2..9e7a446 100644
--- a/2005/i/robert/src/ovision/ui/comm.cc
+++ b/2005/i/robert/src/ovision/ui/comm.cc
@@ -261,6 +261,7 @@ Comm::executeUiCmds (const char *buffer)
case 't': // Entraine le reseau
+ live_->segm->setMode (Image::yuv);
live_->segm->trainNN(live_->img);
// On live_->segmente l'image puis on la stocke
live_->segmAndGroup();
@@ -274,8 +275,10 @@ Comm::executeUiCmds (const char *buffer)
// Assignation du nombre de couleurs a isoler par le reseau
live_->oconfig->nnNbColor = nbColor;
// Genere aleatoire les poids
+ live_->segm->setMode (Image::yuv);
live_->segm->buildNN(live_->oconfig->nnNbColor, Segm::generate);
// Apprentissage
+ live_->segm->setMode (Image::yuv);
live_->segm->trainNN(live_->img);
// On live_->segmente l'image puis on la stocke
live_->segmAndGroup();
diff --git a/2005/i/robert/src/ovision/ui/live.cc b/2005/i/robert/src/ovision/ui/live.cc
index c608c8f..7a8b042 100644
--- a/2005/i/robert/src/ovision/ui/live.cc
+++ b/2005/i/robert/src/ovision/ui/live.cc
@@ -66,18 +66,31 @@ Live::init (const Image::PixelFormat pf, const char *filename)
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);
+ ServerSocket ss (2000);
+ Address a;
+ SocketText *st_ = new SocketText (ss, a);
+ st_->nonblock ();
+ std::cerr << "<Live::init> Init socket\n";
+ // DataBuffer de reception
+ DataBuffer *db_ = new DataBuffer;
+ uint8_t c = 'a';
+ DataBuffer dbAskImg (&c, 1, 1, DataBuffer::AskImage);
+ std::cout << "Demande image...\n";
+ *st_ << dbAskImg;
+ std::cout << "envoye...\n";
+ st_->send ();
+ std::cout << "ok.\n";
+ // Reception des données
+ std::cout << "Rcpt...\n";
+ while (!st_->recv ());
+ std::cout << "Lecture...\n";
+ *st_ >> *db_;
+ std::cout << "ok.\n";
+ if (db_->type () != DataBuffer::Image)
+ std::cerr << "<Live::init> Echec de la transmission\n";
+ std::cout << "Reader...\n";
+ reader_ = new RawReader (*db_, width_, height_, pf);
+ std::cout << "Ok..\n";
}
break;
}
@@ -127,8 +140,20 @@ Live::updateImg (const Image::PixelFormat pf, const char *filename)
break;
case cam:
std::cout << "<Live::updateImg> Changement d'image caméra" << std::endl;
+ break;
case socket:
- break;
+ std::cerr << "<Live::init> Ask data\n";
+ uint8_t c = 'a';
+ DataBuffer dbAskImg (&c, 1, 1, DataBuffer::AskImage);
+ *st_ << dbAskImg;
+ st_->send ();
+ // 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_);
memcpy(data[0], img->tabData_, sizeof(char) * img->nbPixels_ * 3);
@@ -188,7 +213,8 @@ Live::segmAndGroup (const int numColorToShow)
group->jumpPoints (oconfig->groupColor);
mag->analyse (group->getZoneList ());
list = mag->getItemList ((Group::ZoneType)oconfig->uiGroupToDisplay);
- int x, y, angle, dist;
+ int x, y, dist;
+ double angle;
for (std::vector<Zone>::iterator iter = list.begin ();
iter != list.end (); ++iter)
{