iCub-main
Loading...
Searching...
No Matches
VisuoThread.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2010 RobotCub Consortium, European Commission FP6 Project IST-004370
3* Author: Carlo Ciliberto, Vadim Tikhanoff
4* email: carlo.ciliberto@iit.it vadim.tikhanoff@iit.it
5* website: www.robotcub.org
6* Permission is granted to copy, distribute, and/or modify this program
7* under the terms of the GNU General Public License, version 2 or any
8* later version published by the Free Software Foundation.
9*
10* A copy of the license can be found at
11* http://www.robotcub.org/icub/license/gpl.txt
12*
13* This program is distributed in the hope that it will be useful, but
14* WITHOUT ANY WARRANTY; without even the implied warranty of
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16* Public License for more details
17*/
18
19#ifndef __VISUO_THREAD__
20#define __VISUO_THREAD__
21
22
23
24#include <yarp/os/PeriodicThread.h>
25#include <yarp/os/ResourceFinder.h>
26#include <yarp/os/BufferedPort.h>
27
28#include <yarp/sig/Vector.h>
29#include <yarp/sig/Image.h>
30
31#include <opencv2/core/core_c.h>
32#include <opencv2/imgproc.hpp>
33
34#include <mutex>
35#include <string>
36#include <deque>
37#include <map>
38
39#include <iCub/utils.h>
40
41#define PARAM_FIXATION yarp::os::createVocab32('f','i','x','a')
42#define PARAM_MOTION yarp::os::createVocab32('m','o','t','i')
43#define PARAM_TRACK yarp::os::createVocab32('t','r','a','c')
44#define PARAM_RAW yarp::os::createVocab32('r','a','w')
45
46#define MODE_TRACK_TEMPLATE 0
47#define MODE_TRACK_MOTION 1
48
49using namespace std;
50using namespace yarp::os;
51using namespace yarp::sig;
52
53
55{
56 Vector vec;
57 int side;
58};
59
60
61
62
63class VisuoThread: public PeriodicThread
64{
65private:
66 ResourceFinder &rf;
67
68 StereoTarget &stereo_target;
70
71 int trackMode;
72
73 bool interrupted;
74
75 Port outPort[2];
76 BufferedPort<ImageOf<PixelRgb> > imgPort[2];
77 BufferedPort<Bottle> mCUTPort[2];
78 BufferedPort<Bottle> rawInPort[2];
79 BufferedPort<Vector> pftInPort;
80 Port pftOutPort; //send template to the pft throught this port
81
82
83 Port segPort;
84
85 //MIL Ports
86 Port boundMILPort;
87 RpcClient cmdMILPort;
88 BufferedPort<Bottle> recMILPort;
89
90 //multiSensoryObjectRecognition Ports
91 Port cmdMSRPort;
92 BufferedPort<Bottle> recMSRPort;
93
94 mutex imgMutex;
95 mutex motMutex;
96 mutex MILMutex;
97 mutex trackMutex;
98
99 unsigned int minMotionBufSize;
100 unsigned int minTrackBufSize;
101 unsigned int maxTrackBufSize;
102 double timeTol;
103 double motionStdThresh;
104 double speedStdThresh;
105 double stereoDistThresh;
106
107 double rawWaitThresh;
108 double motionWaitThresh;
109 double objectWaitThresh;
110
111 int dominant_eye;
112 ImageOf<PixelRgb> *img[2];
113 ImageOf<PixelBgr> tpl;
114
115 StereoTracker stereoTracker;
116 deque<Vector> trackBuffer;
117 bool tracking;
118
119 bool newImage[2];
120
121 bool show;
122 bool closed;
123
124 struct Item
125 {
126 double t;
127 double size;
128 CvPoint p;
129 };
130
131 deque<Item> buffer[2];
132 //map<string,CvPoint> locations[2];
133 map<string,CvPoint> locations;
134
135
136 bool getFixation(Bottle &bStereo);
137 bool getMotion(Bottle &bStereo);
138 bool getTrack(Bottle &bStereo);
139 bool getRaw(Bottle &bStereo);
140 bool getObject(const string &object_name, Bottle &bStereo);
141
142
143 void close();
144 void updateImages();
145 void updateLocationsMIL();
146 void updateMotionCUT();
147 void updatePFTracker();
148public:
149 VisuoThread(ResourceFinder &_rf, Initializer *initializer);
150
151 virtual bool threadInit();
152 virtual void run();
153 virtual void threadRelease();
154
155
157 {
158 lock_guard<mutex> lck(trackMutex);
159 return tracking;
160 }
161
162 bool checkTracker(Vector *vec);
163
164 void startTracker(const Vector &stereo, const int &side);
165 void restartTracker();
166
167
169 {
170 trackMode=MODE_TRACK_MOTION;
171 return true;
172 }
173
174 bool getTarget(Value &type, Bottle &target);
175
176 Bottle recogMSR(string &obj_name);
177
178
179 void doShow()
180 {
181 show=!show;
182 }
183
184
185
186 bool startLearningMIL(const string &obj_name);
187 bool suspendLearningMIL();
188 bool resumeLearningMIL();
189 bool trainMIL();
190
191 bool startLearningMSR(const string &obj_name, const int &arm);
192 bool startRecogMSR(const int &arm);
195 bool stopMSR();
196 void checkDoneMSR(bool &done);
197
198 void interrupt();
199 void reinstate();
200};
201
202#endif
203
204
#define MODE_TRACK_MOTION
Definition VisuoThread.h:47
bool suspendLearningMIL()
Bottle recogMSR(string &obj_name)
void doShow()
bool stopMSR()
bool startLearningMSR(const string &obj_name, const int &arm)
void startTracker(const Vector &stereo, const int &side)
virtual void threadRelease()
virtual void run()
bool startRecogMSR(const int &arm)
bool suspendLearningMSR()
bool trackMotion()
bool checkTracker(Vector *vec)
bool isTracking()
bool startLearningMIL(const string &obj_name)
void restartTracker()
virtual bool threadInit()
void checkDoneMSR(bool &done)
bool resumeLearningMSR()
VisuoThread(ResourceFinder &_rf, Initializer *initializer)
bool getTarget(Value &type, Bottle &target)
bool resumeLearningMIL()
bool done
Definition main.cpp:42