iCub-main
Loading...
Searching...
No Matches
VisuoThread.cpp
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#include <utility>
19#include <yarp/os/Time.h>
20#include <opencv2/imgproc.hpp>
21#include <yarp/cv/Cv.h>
22#include <iCub/VisuoThread.h>
23
24
25void VisuoThread::close()
26{
27 if (closed)
28 return;
29
30 interrupt();
31
32 outPort[LEFT].close();
33 outPort[RIGHT].close();
34
35 imgPort[LEFT].close();
36 imgPort[RIGHT].close();
37
38 mCUTPort[LEFT].close();
39 mCUTPort[RIGHT].close();
40
41 pftInPort.close();
42 pftOutPort.close();
43
44 boundMILPort.close();
45 cmdMILPort.close();
46 recMILPort.close();
47
48 cmdMSRPort.close();
49 recMSRPort.close();
50
51 if(img[LEFT]!=NULL)
52 {
53 delete img[LEFT];
54 img[LEFT]=NULL;
55 }
56
57 if(img[RIGHT]!=NULL)
58 {
59 delete img[RIGHT];
60 img[RIGHT]=NULL;
61 }
62
63 closed=true;
64}
65
66
68{
69 bool track=false;
70
71 trackBuffer.push_back(*vec);
72
73 if(isTracking() && trackBuffer.size()>minTrackBufSize)
74 {
75 double speed_avg[2];
76 double speed_std[2];
77 speed_avg[LEFT]=speed_avg[RIGHT]=0.0;
78 speed_std[LEFT]=speed_std[RIGHT]=0.0;
79
80 for(unsigned int i=1; i<trackBuffer.size(); i++)
81 {
82 double speed[2];
83 speed[LEFT]=(trackBuffer[i-1][0]-trackBuffer[i][0])*(trackBuffer[i-1][0]-trackBuffer[i][0])+
84 (trackBuffer[i-1][1]-trackBuffer[i][1])*(trackBuffer[i-1][1]-trackBuffer[i][1]);
85 speed_avg[LEFT]+=sqrt(speed[LEFT]);
86 speed_std[LEFT]+=speed[LEFT];
87
88 speed[RIGHT]=(trackBuffer[i-1][0]-trackBuffer[i][0])*(trackBuffer[i-1][0]-trackBuffer[i][0])+
89 (trackBuffer[i-1][1]-trackBuffer[i][1])*(trackBuffer[i-1][1]-trackBuffer[i][1]);
90 speed_avg[RIGHT]+=sqrt(speed[RIGHT]);
91 speed_std[RIGHT]+=speed[RIGHT];
92 }
93
94 double n=1.0/(trackBuffer.size()-1);
95 speed_avg[LEFT]*=n;
96 speed_std[LEFT]=n*speed_std[LEFT]-speed_avg[LEFT]*speed_avg[LEFT];
97 speed_avg[RIGHT]*=n;
98 speed_std[RIGHT]=n*speed_std[RIGHT]-speed_avg[RIGHT]*speed_avg[RIGHT];
99
100 track=true;
101
102 // check that the speeds are not varying too much
103 if(speed_avg[LEFT]>speedStdThresh || speed_avg[RIGHT]>speedStdThresh)
104 {
105 track=false;
106 }
107
108 double dist=(trackBuffer.back()[0]-trackBuffer.back()[6])*(trackBuffer.back()[0]-trackBuffer.back()[6])+
109 (trackBuffer.back()[1]-trackBuffer.back()[7])*(trackBuffer.back()[1]-trackBuffer.back()[7]);
110
111 // avoid strabicity
112 if(sqrt(dist)>stereoDistThresh)
113 {
114 track=false;
115 }
116 // check that both images are tracking similar things
117 }
118
119 while(trackBuffer.size()>maxTrackBufSize)
120 trackBuffer.pop_front();
121
122 return track;
123}
124
125
126void VisuoThread::startTracker(const Vector &stereo, const int &side)
127{
128 int eye_in_use;
129
130 if(stereo[2*dominant_eye]==0.0 && stereo[2*dominant_eye+1]==0.0)
131 {
132 if(stereo[2*(1-dominant_eye)]==0.0 && stereo[2*(1-dominant_eye)+1]==0.0)
133 return;
134
135 eye_in_use=1-dominant_eye;
136 }
137 else
138 eye_in_use=dominant_eye;
139
140 cv::Mat imgMat;
141 imgMutex.lock();
142 if (img[eye_in_use]!=nullptr)
143 imgMat=yarp::cv::toCvMat(*img[eye_in_use]).clone();
144 imgMutex.unlock();
145
146 if (!imgMat.empty())
147 {
148 tpl.resize(side,side);
149 cv::Mat tplMat=yarp::cv::toCvMat(tpl);
150
151 int x=stereo[2*eye_in_use]-0.5*side<0?0:cvRound(stereo[2*eye_in_use]-0.5*side);
152 int y=stereo[2*eye_in_use+1]-0.5*side<0?0:cvRound(stereo[2*eye_in_use+1]-0.5*side);
153 int width=stereo[2*eye_in_use]+0.5*side>=imgMat.cols?imgMat.cols-x:side;
154 int height=stereo[2*eye_in_use+1]+0.5*side>=imgMat.rows?imgMat.rows-y:side;
155
156 imgMat(cv::Rect(x,y,width,height)).copyTo(tplMat);
157 cv::cvtColor(tplMat,tplMat,cv::COLOR_BGR2RGB);
158
159 pftOutPort.write(tpl);
160 }
161
162 lock_guard<mutex> lck(trackMutex);
163 stereoTracker.side=side;
164 tracking=true;
165 trackMode=MODE_TRACK_TEMPLATE;
166}
167
168
170{
171 pftOutPort.write(tpl);
172
173 lock_guard<mutex> lck(trackMutex);
174 tracking=true;
175}
176
177void VisuoThread::updateImages()
178{
179 ImageOf<PixelRgb> *iL=imgPort[LEFT].read(false);
180 ImageOf<PixelRgb> *iR=imgPort[RIGHT].read(false);
181
182 lock_guard<mutex> lck(imgMutex);
183 if(iL!=NULL)
184 {
185 if(img[LEFT]!=NULL)
186 delete img[LEFT];
187
188 img[LEFT]=new ImageOf<PixelRgb>(*iL);
189
190 newImage[LEFT]=true;
191 }
192
193 if(iR!=NULL)
194 {
195 if(img[RIGHT]!=NULL)
196 delete img[RIGHT];
197
198 img[RIGHT]=new ImageOf<PixelRgb>(*iR);
199
200 newImage[RIGHT]=true;
201 }
202}
203
204void VisuoThread::updateLocationsMIL()
205{
206 Bottle *bLocations=recMILPort.read(false);
207
208 if(bLocations!=NULL)// && bLocations->size()==1)
209 {
210 lock_guard<mutex> lck(MILMutex);
211 locations.clear();
212
213 for(int i=0; i<bLocations->get(0).asList()->size(); i++)
214 {
215 Bottle *b=bLocations->get(0).asList()->get(i).asList();
216 locations[b->get(0).asString()]=cvPoint(b->get(1).asInt32(),b->get(2).asInt32());
217 }
218 }
219}
220
221
222void VisuoThread::updateMotionCUT()
223{
224 // Detect motion
225 Bottle *bMotion[2];
226 bMotion[LEFT]=mCUTPort[LEFT].read(false);
227 bMotion[RIGHT]=mCUTPort[RIGHT].read(false);
228
229 double tNow=Time::now();
230
231 bool detected=true;
232
233 lock_guard<mutex> lck(motMutex);
234
235 Vector stereo(4); stereo=0.0;
236 for(int cam=0; cam<2; cam++)
237 {
238 // if even the first element of the buffer is far (in time)
239 // clear the whole buffer
240 if(buffer[cam].size()>0 && tNow-buffer[cam].back().t>timeTol)
241 buffer[cam].clear();
242
243 // If only a single moving blob has been detected
244 if (bMotion[cam] && bMotion[cam]->size()==1)
245 {
246 Item item;
247 item.t=Time::now();
248 item.size=bMotion[cam]->get(0).asList()->get(2).asFloat64();
249 item.p=cvPoint(bMotion[cam]->get(0).asList()->get(0).asInt32(),bMotion[cam]->get(0).asList()->get(1).asInt32());
250 buffer[cam].push_back(item);
251
252 stereo[2*cam]=bMotion[cam]->get(0).asList()->get(0).asFloat64();
253 stereo[2*cam+1]=bMotion[cam]->get(0).asList()->get(1).asFloat64();
254 }
255
256 // Avoid time unconsistencies
257 while (buffer[cam].size() && (tNow-buffer[cam].front().t)>timeTol)
258 buffer[cam].pop_front();
259 }
260
261 if(trackMode==MODE_TRACK_MOTION)
262 stereo_target.set(stereo);
263}
264
265
266
267void VisuoThread::updatePFTracker()
268{
269 Vector *trackVec=pftInPort.read(false);
270
271 Vector stereo;
272 if(trackVec!=NULL && trackVec->size()==12)
273 {
274 //must check if the tracker has gone mad.
275 if(checkTracker(trackVec))
276 {
277 trackMutex.lock();
278 stereoTracker.vec=*trackVec;
279 trackMutex.unlock();
280
281 stereo.resize(4);
282 stereo[0]=stereoTracker.vec[0];
283 stereo[1]=stereoTracker.vec[1];
284 stereo[2]=stereoTracker.vec[6];
285 stereo[3]=stereoTracker.vec[7];
286
287 if(trackMode==MODE_TRACK_TEMPLATE)
288 stereo_target.set(stereo);
289 }
290 else
291 {
292 lock_guard<mutex> lck(trackMutex);
293 stereoTracker.vec.clear();
294 stereoTracker.side=0;
295 }
296 }
297
298 lock_guard<mutex> lck(imgMutex);
299 if(img[LEFT]!=NULL && img[RIGHT]!=NULL)
300 {
301 ImageOf<PixelRgb> drawImg[2];
302 drawImg[LEFT]=*img[LEFT];
303 drawImg[RIGHT]=*img[RIGHT];
304
305 if(stereoTracker.vec.size()==12)
306 {
307 cv::Mat tmpL=yarp::cv::toCvMat(drawImg[LEFT]);
308 cv::circle(tmpL,cv::Point(cvRound(stereoTracker.vec[0]),cvRound(stereoTracker.vec[1])),3,cv::Scalar(0,255),3);
309 cv::rectangle(tmpL,cv::Point(cvRound(stereoTracker.vec[2]),cvRound(stereoTracker.vec[3])),
310 cv::Point(cvRound(stereoTracker.vec[4]),cvRound(stereoTracker.vec[5])),cv::Scalar(0,255),3);
311
312 cv::Mat tmpR=yarp::cv::toCvMat(drawImg[RIGHT]);
313 cv::circle(tmpR,cv::Point(cvRound(stereoTracker.vec[6]),cvRound(stereoTracker.vec[7])),3,cv::Scalar(0,255),3);
314 cv::rectangle(tmpR,cv::Point(cvRound(stereoTracker.vec[8]),cvRound(stereoTracker.vec[9])),
315 cv::Point(cvRound(stereoTracker.vec[10]),cvRound(stereoTracker.vec[11])),cv::Scalar(0,255),3);
316
317 Bottle v;
318 v.clear();
319 Bottle &vl=v.addList();
320 vl.addInt32(cvRound(stereoTracker.vec[0]));
321 vl.addInt32(cvRound(stereoTracker.vec[1]));
322 vl.addInt32(stereoTracker.side);
323 Bottle &vr=v.addList();
324 vr.addInt32(cvRound(stereoTracker.vec[6]));
325 vr.addInt32(cvRound(stereoTracker.vec[7]));
326 vr.addInt32(stereoTracker.side);
327
328 boundMILPort.write(v);
329 }
330
331 if(newImage[LEFT])
332 outPort[LEFT].write(drawImg[LEFT]);
333
334 if(newImage[RIGHT])
335 outPort[RIGHT].write(drawImg[RIGHT]);
336
337 //avoid writing multiple times the same image
338 newImage[LEFT]=false;
339 newImage[RIGHT]=false;
340 }
341}
342
343
344
345VisuoThread::VisuoThread(ResourceFinder &_rf, Initializer *initializer)
346 :PeriodicThread(0.02),rf(_rf),stereo_target(initializer->stereo_target),opcPort(initializer->port_opc)
347{
348 buffer[LEFT].clear();
349 buffer[RIGHT].clear();
350
351 locations.clear();
352
353 img[LEFT]=NULL;
354 img[RIGHT]=NULL;
355
356 stereoTracker.vec.clear();
357 stereoTracker.side=0;
358
359 trackMode=MODE_TRACK_TEMPLATE;
360 closed=false;
361}
362
364{
365 string name=rf.find("name").asString();
366
367 Bottle bVision=rf.findGroup("vision");
368
369 setPeriod((double)bVision.check("period",Value(20)).asInt32()/1000.0);
370
371 minMotionBufSize=bVision.check("minMotionBufSize",Value(10)).asInt32();
372 minTrackBufSize=bVision.check("minTrackBufSize",Value(1)).asInt32();
373 maxTrackBufSize=bVision.check("maxTrackBufSize",Value(2)).asInt32();
374 timeTol=bVision.check("timeTol",Value(0.5)).asFloat64();
375 motionStdThresh=bVision.check("motionStdThresh",Value(5.0)).asFloat64();
376 speedStdThresh=bVision.check("speedStdThresh",Value(700.0)).asFloat64();
377 stereoDistThresh=bVision.check("stereoDistThresh",Value(300.0)).asFloat64();
378 dominant_eye=bVision.check("dominant_eye",Value("left")).asString()=="left"?LEFT:RIGHT;
379
380 rawWaitThresh=bVision.check("raw_detection_wait_thresh",Value(15.0)).asFloat64();
381 motionWaitThresh=bVision.check("motion_detection_wait_thresh",Value(5.0)).asFloat64();
382 objectWaitThresh=bVision.check("object_detection_wait_thresh",Value(5.0)).asFloat64();
383
384 // open ports
385 outPort[LEFT].open("/"+name+"/left/img:o");
386 outPort[RIGHT].open("/"+name+"/right/img:o");
387
388 imgPort[LEFT].open("/"+name+"/left/img:i");
389 imgPort[RIGHT].open("/"+name+"/right/img:i");
390
391 mCUTPort[LEFT].open("/"+name+"/left/blobs:i");
392 mCUTPort[RIGHT].open("/"+name+"/right/blobs:i");
393
394 rawInPort[LEFT].open("/"+name+"/left/raw:i");
395 rawInPort[RIGHT].open("/"+name+"/right/raw:i");
396
397 boundMILPort.open("/"+name+"/MIL/window:o");
398 cmdMILPort.open("/"+name+"/MIL/cmd:o");
399 recMILPort.open("/"+name+"/MIL/rec:i");
400
401 cmdMSRPort.open("/"+name+"/MSR/cmd:o");
402 recMSRPort.open("/"+name+"/MSR/rec:i");
403
404 pftInPort.open("/"+name+"/tracker:i");
405 pftOutPort.open("/"+name+"/tracker:o");
406
407 segPort.open("/"+name+"/seg:o");
408
409 newImage[LEFT]=false;
410 newImage[RIGHT]=false;
411
412 show=false;
413
414 interrupted=false;
415
416 trackMode=MODE_TRACK_TEMPLATE;
417
418 closed=false;
419 return true;
420}
421
423{
424 updateImages();
425 updatePFTracker();
426 updateLocationsMIL();
427 updateMotionCUT();
428}
429
430
432{
433 close();
434}
435
436
437
438//get the action target point in the images reference frame
439bool VisuoThread::getTarget(Value &type, Bottle &options)
440{
441 bool ok=false;
442
443 Bottle &bNewTarget=options.addList();
444 bNewTarget.addString("target");
445
446 Bottle &bTarget=bNewTarget.addList();
447 Bottle &bNewStereo=bTarget.addList();
448 bNewStereo.addString("stereo");
449
450 Bottle &bStereo=bNewStereo.addList();
451
452 if(type.isList())
453 {
454 Bottle *list=type.asList();
455 if(list->size()>2)
456 {
457 if(list->get(0).asString()=="right")
458 {
459 bStereo.addFloat64(0.0);
460 bStereo.addFloat64(0.0);
461 bStereo.addFloat64(list->get(1).asFloat64());
462 bStereo.addFloat64(list->get(2).asFloat64());
463 }
464 else if(list->get(0).asString()=="left")
465 {
466 bStereo.addFloat64(list->get(1).asFloat64());
467 bStereo.addFloat64(list->get(2).asFloat64());
468 bStereo.addFloat64(0.0);
469 bStereo.addFloat64(0.0);
470 }
471 else if(list->get(0).asString()=="cartesian")
472 {
473 Bottle &bNewCartesian=bTarget.addList();
474 bNewCartesian.addString("cartesian");
475
476 Bottle &bCartesian=bNewCartesian.addList();
477
478 for(int i=1; i<list->size(); i++)
479 bCartesian.addFloat64(list->get(i).asFloat64());
480 }
481 else
482 {
483 Bottle &bNewCartesian=bTarget.addList();
484 bNewCartesian.addString("cartesian");
485
486 Bottle &bCartesian=bNewCartesian.addList();
487
488 for(int i=0; i<list->size(); i++)
489 bCartesian.addFloat64(list->get(i).asFloat64());
490 }
491
492 ok=true;
493 }
494 else if(list->size()==2)
495 {
496 bStereo.addFloat64(list->get(0).asFloat64());
497 bStereo.addFloat64(list->get(1).asFloat64());
498 bStereo.addFloat64(0.0);
499 bStereo.addFloat64(0.0);
500
501 ok=true;
502 }
503 }
504 else switch(type.asVocab32())
505 {
506 case PARAM_FIXATION:
507 {
508 ok=getFixation(bStereo);
509 break;
510 }
511 case PARAM_MOTION:
512 {
513 ok=getMotion(bStereo);
514 break;
515 }
516 case PARAM_TRACK:
517 {
518 ok=getTrack(bStereo);
519 break;
520 }
521 case PARAM_RAW:
522 {
523 ok=getRaw(bStereo);
524 break;
525 }
526
527 default:
528 {
529 Bottle &bName=bTarget.addList();
530 bName.addString("name");
531 bName.addString(type.asString());
532
533 getObject(type.asString(),bStereo);
534 break;
535 }
536 }
537
538
539 return ok;
540}
541
542
543bool VisuoThread::getFixation(Bottle &bStereo)
544{
545 Vector stereo(4);
546
547 imgMutex.lock();
548 if(img[LEFT]!=NULL)
549 {
550 stereo[0]=stereo[2]=0.5*img[LEFT]->width();
551 stereo[1]=stereo[3]=0.5*img[LEFT]->height();
552 }
553 else
554 {
555 stereo[0]=stereo[2]=160;
556 stereo[1]=stereo[3]=120;
557 }
558 imgMutex.unlock();
559
560 for(size_t i=0; i<stereo.size(); i++)
561 bStereo.addFloat64(stereo[i]);
562
563 int side=40;
564 startTracker(stereo,side);
565
566 return true;
567}
568
569bool VisuoThread::getMotion(Bottle &bStereo)
570{
571 Vector stereo;
572
573 bool ok=false;
574
575 double t=Time::now();
576
577 while(Time::now()-t<motionWaitThresh && !interrupted)
578 {
579 lock_guard<mutex> lck(motMutex);
580 // If the buffers are sufficently dense and not so small, return true.
581 double size=0.0;
582 if (buffer[LEFT].size()>minMotionBufSize && buffer[RIGHT].size()>minMotionBufSize)
583 {
584 Vector p[2];
585 for (int cam=0; cam<2; cam++)
586 {
587 double size_cam,u,v,n;
588 double u_std,v_std;
589 size_cam=u=v=0.0;
590 u_std=v_std=0.0;
591 n=1.0/buffer[cam].size();
592
593 for (unsigned int i=0; i<buffer[cam].size(); i++)
594 {
595 size_cam+=buffer[cam][i].size;
596 u+=buffer[cam][i].p.x;
597 v+=buffer[cam][i].p.y;
598 u_std+=buffer[cam][i].p.x*buffer[cam][i].p.x;
599 v_std+=buffer[cam][i].p.y*buffer[cam][i].p.y;
600 }
601
602 size_cam*=n;
603 u*=n;
604 v*=n;
605 u_std=sqrt(n*u_std-u*u);
606 v_std=sqrt(n*v_std-v*v);
607
608 //check if the motion detected point is not wildly moving
609 if (u_std<motionStdThresh && v_std<motionStdThresh)
610 {
611 p[cam].resize(2);
612 p[cam][0]=u;
613 p[cam][1]=v;
614 }
615 else
616 break;
617
618 size+=size_cam;
619 }
620
621 int side=cvRound(2*sqrt(size/3.1415)*2);
622
623 if (p[LEFT].size()==2 && p[RIGHT].size()==2)
624 {
625 stereo.resize(4);
626 stereo[0]=p[LEFT][0];
627 stereo[1]=p[LEFT][1];
628 stereo[2]=p[RIGHT][0];
629 stereo[3]=p[RIGHT][1];
630
631 startTracker(stereo,cvRound(side));
632
633 ok=true;
634 }
635 }
636 }
637
638 for(size_t i=0; i<stereo.size(); i++)
639 bStereo.addFloat64(stereo[i]);
640
641 return ok;
642}
643
644
645bool VisuoThread::getTrack(Bottle &bStereo)
646{
647 lock_guard<mutex> lck(trackMutex);
648
649 Vector stereo;
650 bool ok=false;
651
652 if(stereoTracker.vec.size()==12)
653 {
654 stereo.resize(4);
655 stereo[0]=stereoTracker.vec[0];
656 stereo[1]=stereoTracker.vec[1];
657 stereo[2]=stereoTracker.vec[6];
658 stereo[3]=stereoTracker.vec[7];
659 }
660
661 for(size_t i=0; i<stereo.size(); i++)
662 bStereo.addFloat64(stereo[i]);
663
664 tracking=true;
665 trackMode=MODE_TRACK_TEMPLATE;
666
667 return ok;
668}
669
670
671
672bool VisuoThread::getRaw(Bottle &bStereo)
673{
674 Vector stereo;
675
676 bool ok=false;
677
678 //empty the buffers
679 Bottle *bL=rawInPort[LEFT].read(false);
680 Bottle *bR=rawInPort[RIGHT].read(false);
681
682 double t=Time::now();
683
684 while(stereo.size()!=4 && Time::now()-t<rawWaitThresh && !interrupted)
685 {
686 Bottle *bL=rawInPort[LEFT].read(false);
687 Bottle *bR=rawInPort[RIGHT].read(false);
688
689 if(bL!=NULL || bR!=NULL)
690 stereo.resize(4,0.0);
691
692 if(bL!=NULL)
693 {
694 stereo[0]=bL->get(0).asInt32();
695 stereo[1]=bL->get(1).asInt32();
696 }
697
698 if(bR!=NULL)
699 {
700 stereo[2]=bR->get(0).asInt32();
701 stereo[3]=bR->get(1).asInt32();
702 }
703 }
704
705 if(stereo.size()==4)
706 {
707 int side=40;
708 startTracker(stereo,side);
709 ok=true;
710 }
711
712 for(size_t i=0; i<stereo.size(); i++)
713 bStereo.addFloat64(stereo[i]);
714
715 return ok;
716}
717
718// if the object is located in both cameras, return its stereo position
719bool VisuoThread::getObject(const std::string &object_name, Bottle &bStereo)
720{
721 Vector stereo;
722
723 bool ok=opcPort.getStereoPosition(object_name,stereo);
724
725 if(!ok)
726 {
727 double t=Time::now();
728 while(Time::now()-t<objectWaitThresh && !interrupted)
729 {
730 lock_guard<mutex> lck(MILMutex);
731 if(locations.count(object_name)>0)
732 {
733 stereo.resize(4);
734 stereo[0]=locations[object_name].x;
735 stereo[1]=locations[object_name].y;
736 stereo[2]=160.0;
737 stereo[3]=120.0;
738
739 ok=true;
740 }
741 }
742 }
743
744 for(size_t i=0; i<stereo.size(); i++)
745 bStereo.addFloat64(stereo[i]);
746
747 return ok;
748}
749
750
751Bottle VisuoThread::recogMSR(string &obj_name)
752{
753 Bottle bDetect;
754 Bottle *bMSR=recMSRPort.read(false);
755 if(bMSR!=NULL)
756 {
757 bDetect=*bMSR;
758 obj_name=bDetect.get(0).asString();
759 }
760 return bDetect;
761}
762
763
764
765bool VisuoThread::startLearningMIL(const std::string &obj_name)
766{
767 if(!isTracking())
768 return false;
769
770 Bottle command,reply;
771 command.fromString("learn " + obj_name + " template");
772
773 cmdMILPort.write(command,reply);
774
775 return (reply.get(0).toString()=="ack");
776}
777
778
780{
781 Bottle command,reply;
782 command.fromString("set label 0");
783
784 cmdMILPort.write(command,reply);
785
786 return (reply.get(0).toString()=="ack");
787}
788
790{
791 Bottle command,reply;
792 command.fromString("set label template");
793
794 cmdMILPort.write(command,reply);
795
796 return (reply.get(0).toString()=="ack");
797}
798
800{
801 Bottle command,reply;
802 command.fromString("train");
803
804 cmdMILPort.write(command,reply);
805
806 return (reply.get(0).toString()=="ack");
807}
808
809
810
812{
813 outPort[LEFT].interrupt();
814 outPort[RIGHT].interrupt();
815
816 imgPort[LEFT].interrupt();
817 imgPort[RIGHT].interrupt();
818
819 mCUTPort[LEFT].interrupt();
820 mCUTPort[RIGHT].interrupt();
821
822 rawInPort[LEFT].interrupt();
823 rawInPort[RIGHT].interrupt();
824
825 pftInPort.interrupt();
826 pftOutPort.interrupt();
827
828 boundMILPort.interrupt();
829 cmdMILPort.interrupt();
830 recMILPort.interrupt();
831
832 cmdMSRPort.interrupt();
833 recMSRPort.interrupt();
834
835 opcPort.interrupt();
836
837 interrupted=true;
838}
839
841{
842 outPort[LEFT].resume();
843 outPort[RIGHT].resume();
844
845 imgPort[LEFT].resume();
846 imgPort[RIGHT].resume();
847
848 mCUTPort[LEFT].resume();
849 mCUTPort[RIGHT].resume();
850
851 rawInPort[LEFT].resume();
852 rawInPort[RIGHT].resume();
853
854 pftInPort.resume();
855 pftOutPort.resume();
856
857 boundMILPort.resume();
858 cmdMILPort.resume();
859 recMILPort.resume();
860
861 cmdMSRPort.resume();
862 recMSRPort.resume();
863
864 opcPort.resume();
865
866 interrupted=false;
867}
868
869
#define PARAM_TRACK
Definition VisuoThread.h:43
#define PARAM_MOTION
Definition VisuoThread.h:42
#define PARAM_RAW
Definition VisuoThread.h:44
#define PARAM_FIXATION
Definition VisuoThread.h:41
#define MODE_TRACK_MOTION
Definition VisuoThread.h:47
#define MODE_TRACK_TEMPLATE
Definition VisuoThread.h:46
bool suspendLearningMIL()
Bottle recogMSR(string &obj_name)
void startTracker(const Vector &stereo, const int &side)
virtual void threadRelease()
virtual void run()
bool checkTracker(Vector *vec)
bool isTracking()
bool startLearningMIL(const string &obj_name)
void restartTracker()
virtual bool threadInit()
VisuoThread(ResourceFinder &_rf, Initializer *initializer)
bool getTarget(Value &type, Bottle &target)
bool resumeLearningMIL()
int n
#define LEFT
Definition utils.h:33
#define RIGHT
Definition utils.h:34