summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/ovision.cc
blob: 9a74c2195cb7c1216b542bed6a62693490b0cce6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "ovision.hh"
#include <iostream>
    
/// Constructeur
OVision::OVision (bool useSocket)
    : oconfig_ (0), img_ (0), colorTab_ (0), segm_ (0),
    group_ (0), mag_ (0), step_ (0), aim_ (Group::undefined) //map_ (0), 
{
//    socket_ 	= 0;
}

/// Destructeur
OVision::~OVision ()
{
    delete oconfig_;
    delete img_;
    delete segm_;
    delete group_;
    delete mag_;
//    delete map_;
//    delete space_;
//    delete socket_;
}

/// Iniialisatoin de toutes les classes
void 
OVision::init (const Group::ZoneType aim)
{
    aim_ = aim;
    // Initialisation des classes
    oconfig_ = 	new OConfig;
    img_ =	new Img;
    // Initialisation cam�ra
    v4l_ = new Video4Linux ("/dev/video", oconfig_->inputColor);
    v4l_->calibrate ();
    // Prendre une image pour que la taille de l'image soit configur�
    img_->load (*v4l_);
    colorTab_ =	new ColorTable;
    segm_ =	new SegmTable (*colorTab_);
    group_ =	new Group (img_, segm_);
    mag_ =	new Magnifier (img_, segm_, aim_);
    // Mode de couleur utilis� pour les la segmentation
    segm_->setMode (oconfig_->inputColor);
    space_ = 	new Space (img_->width_, img_->height_);
//    map_ =	new Map (space);
    // 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);
    // Ouverture ou cr�ation de la table de couleur
    /// Initialisation des socket_s
    //    socket_ = new SocketClient ("10.42.51.2" , 106560*3);
    //    socket_->Init ();

    //    std::cout << "Chargement OVision ................ OK" << std::endl;
}

/// 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);
	  }
	  */
    // Mets � jour la map_
    /*    map_->AddBallsToMap (group_);
	  double balX, balY;
	  if (map_->GetCurBallPos (balX, balY))
	  std::cout << "Balle Courante: " << balX << "   " << balY << std::endl;
	  if (map_->IsTree ())
	  {
	  double treeX, treeY;
	  map_->GetTreePos (treeX, treeY);
	  std::cout << "Tree: " << treeX << "   " << treeY << std::endl; 
	  }
	  */
}

/// 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
    group_->showZones();
    mag_->showItems (Group::redSkittle);
    std::cout << "-------------\n" << std::endl;
    std::cout << "-------------\n" << std::endl;
}

/// Renvoie la position
bool
OVision::getBall (double &x, double &y) const
{
    return false;
//    return map_->GetCurBallPos (x, y);
}

/// Renvoie le pointeur sur Video4Linux
Video4Linux & 
OVision::getVideo4Linux () const
{
    return *v4l_;
}

/// Envoie l'image par socket_
void 
OVision::sendImg ()
{
//    socket__->Send (img_->tabData);
}