summaryrefslogtreecommitdiff
path: root/2004/i/nono/src/ovision/test_ovision_tracker.cc
blob: 393dca851560c60da45f29db5def4ba34993b06a (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
// test_ovision_tracker.cc
// nono - programme du robot 2004. {{{
//
// Copyright (C) 2004 Nicolas Schodet et Olivier Gaillard
//
// Robot APB Team/Efrei 2004.
//        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.
//
// }}}
#include "video4linux/video4linux.h"
#include "map.h"
#include "oconfig.h"
#include "group.h"
#include "space.h"
#include "motor/motor.h"
#include "motor/movement_types.h"
#include "motor/goto_tracker.h"

int 
main ()
{
    try
      {
    /////////////////////////////////////////////////////////////////////////////////////////
    /// Initialisation des classes
    OConfig oconfig("rc/vision.conf");

    Img img;
    Video4Linux::ColorSpace cs;
    cs = Video4Linux::rgb;
    Video4Linux v4l("/dev/video", cs, 55000);
    v4l.calibrate ();

    Space space(img.width, img.height, &oconfig);
    space.AddSetupPoint (230, 16, 30, 300);
    space.AddSetupPoint (208, 168, 40, 600);
    space.AddSetupPoint (201, 230, 50, 900);
    space.Setup ();

    SegmNN segmNN(&img, &oconfig);
    segmNN.BuildNN(oconfig.nn_NbCouleurs, LOAD_FROM_FILE);

    Group group(&img, &segmNN);

    Map map(&oconfig, &space);
    /////////////////////////////////////////////////////////////////////////////////////////

    // Param�tre les moteurs.
    Motor m;
    m.go ();
    GotoTracker *tracker = new GotoTracker ();
    Movement *mov = new MovementGoto (tracker);
    m.addMovement (mov);

    /////////////////////////////////////////////////////////////////////////////////////////
    /// Prends une image a partir de la camera  et l'analyse
    //char filename[30];
    int i = 0;
    while (i < 3)
      {
	std::cout << "-----------------------------------------------------------------" << std::endl;
	std::cout << "image n�" << i << std::endl;
	img.load(v4l);
	std::cout << "image n�" << i << " loaded" << std::endl;
	//img.load(v4l);
	//sprintf(filename, "test%i.rgb", i);
	//img.WriteRGB(filename);
	segmNN.Segm();
    
	group.JumpPoints(oconfig.groupColor);
	group.ShowZones();
	std::cout << "-------------\n" << std::endl;
	if (group.zoneListBall)
	  {
	    int x,y;
	    double angle;
	    x = group.zoneListBall->centerx - img.width/2;
	    y = img.height -  group.zoneListBall->centery;
	    std::cout << x << "    " << y << std::endl;
	    space.GetLoc(0, y, x, y);
	    std::cout << y << std::endl;
	    tracker->setTracked (true, y, 0);
	    m.waitOk ();
	  }
	else
	  {
	    tracker->setTracked (false, 1, 1);
	    m.waitOk ();
	  }
	std::cout << "-------------\n" << std::endl;

	i++;
      }
    /////////////////////////////////////////////////////////////////////////////////////////
    return 0;
      }
    catch (const std::exception &e)
      {
	std::cout << e.what () << std::endl;
	return 1;
      }
}