summaryrefslogtreecommitdiff
path: root/2005/i/robert/src/ovision/see/ovision.cc
blob: c66d64a3a9942d5a0b636dc19ede287ea6472a39 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "ovision.hh"
#include <iostream>
    
/// Constructeur
OVision::OVision (bool useSocket)
    : oconfig_ (0), img_ (0), colorTab_ (0), segm_ (0), eraser_ (0),
    group_ (0), mag_ (0), space_ (0), v4l_ (0), step_ (0),
    aim_ (Group::undefined) //map_ (0), 
{
//    socket_ 	= 0;
}

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

/// Iniialisatoin de toutes les classes
void 
OVision::init (const Group::ZoneType aim)
{
    aim_ = aim;
    oconfig_ = new OConfig; 
    // Initialisation des classes
    if (aim == Group::redSkittle)
      {
	colorTab_ = new ColorTable ("../runtime/rc/colortableRed.z");
	oconfig_->nnInfluLum = 0.4;
	oconfig_->groupColor.clear ();
	ObjectColor tmp;
	tmp.label = "redSkittle";
	tmp.color = 3;
	tmp.type = aim;
	oconfig_->groupColor.push_back (tmp);
      }
    else
      {
	colorTab_ = new ColorTable ("../runtime/rc/colortableGreen.z");
	oconfig_->nnInfluLum = 0.4;
	ObjectColor tmp;
	oconfig_->groupColor.clear ();
	tmp.label = "greenSkittle";
	tmp.color = 0;
	tmp.type = aim; 
	oconfig_->groupColor.push_back (tmp);
      }

    img_ =	new Img;
    // Initialisation cam�ra
    v4l_ = new Video4Linux ("/dev/video", oconfig_->width, oconfig_->height,
			    oconfig_->inputColor, oconfig_->brightness);
    v4l_->calibrate ();
    // Prendre une image pour que la taille de l'image soit configur�
    img_->load (*v4l_);
    segm_ =	new SegmTable (*colorTab_);
    segm_->setMode (oconfig_->inputColor);
    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 (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
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);
	  }
	  */
}

/// 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
    mag_->showItems (aim_);
    std::cout << "-------------\n" << std::endl;
    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_->getRealLoc (zone, x, y, angle, dist);
}

/// Renvoie la liste des quilles 
std::vector<Zone>&
OVision::getSkittles () const
{
    return mag_->getItemList(aim_);
}

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

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