25 #include <yarp/os/all.h> 26 #include <yarp/sig/all.h> 27 #include <yarp/math/Math.h> 28 #include <yarp/math/Rand.h> 29 #include <iCub/ctrl/filters.h> 32 #include <opencv2/opencv.hpp> 33 #include <opencv2/tracking.hpp> 38 #define RET_INVALID -1 39 #define OBJECT_UNKNOWN "?" 71 enum {
idle, init, no_need, tracking };
83 IOLObject(
const int filter_order=1,
const double presenceTmo_=0.0,
84 const string &trackerType_=
"BOOSTING",
const double trackerTmo_=0.0) :
85 filterPos(filter_order), filterDim(10*filter_order),
86 init_filters(true), presenceTmo(presenceTmo_),
87 trackerType(trackerType_), trackerState(
idle),
88 trackerTmo(trackerTmo_), trackerTimer(0.0)
90 trackerResult.x=trackerResult.y=0;
91 trackerResult.width=trackerResult.height=0;
101 presenceTimer=Time::now();
111 bool dead=(Time::now()-presenceTimer>=presenceTmo);
125 void filt(
const Vector &
x, Vector &xFilt,
126 const Vector &d, Vector &dFilt)
130 filterPos.init(x); xFilt=
x;
131 filterDim.init(d); dFilt=d;
136 xFilt=filterPos.filt(x);
137 dFilt=filterDim.filt(d);
147 if (trackerState==no_need)
158 trackerResult.x=bbox.x;
159 trackerResult.y=bbox.y;
160 trackerResult.width=bbox.width;
161 trackerResult.height=bbox.height;
162 trackerState=no_need;
172 cv::Mat frame=cv::cvarrToMat((IplImage*)img.getIplImage());
173 if (trackerState==init)
175 #if CV_MINOR_VERSION <= 2 176 tracker=cv::Tracker::create(trackerType);
178 if(trackerType==
"BOOSTING")
179 tracker=cv::TrackerBoosting::create();
180 else if(trackerType==
"MIL")
181 tracker=cv::TrackerMIL::create();
182 else if (trackerType==
"TLD")
183 tracker=cv::TrackerTLD::create();
184 else if (trackerType==
"KCF")
185 tracker=cv::TrackerKCF::create();
187 throw std::runtime_error(
"This tracker is not supported. Supported trackers: BOOSTING, MIL, TLD, KCF");
189 tracker->init(frame,trackerResult);
190 trackerTimer=Time::now();
191 trackerState=tracking;
193 else if (trackerState==tracking)
195 if (Time::now()-trackerTimer<trackerTmo)
197 tracker->update(frame,trackerResult);
198 CvPoint tl=cvPoint((
int)trackerResult.x,(
int)trackerResult.y);
199 CvPoint br=cvPoint(tl.x+(
int)trackerResult.width,
200 tl.y+(
int)trackerResult.height);
202 if ((tl.x<5) || (br.x>frame.cols-5) ||
203 (tl.y<5) || (br.y>frame.rows-5))
221 bbox=cvRect((
int)trackerResult.x,(
int)trackerResult.y,
222 (
int)trackerResult.width,(
int)trackerResult.height);
223 return (trackerState!=
idle);
246 BufferedPort<ImageOf<PixelBgr> >
imgIn;
275 map<string,IOLObject>
db;
306 void yInfoGated(
const char *msg, ...)
const;
314 string findName(
const Bottle &scores,
const string &tag);
321 Bottle skimBlobs(
const Bottle &blobs);
329 bool thresBBox(CvRect &bbox,
const Image &img);
343 CvPoint getBlobCOG(
const Bottle &blobs,
const unsigned int i);
351 bool getBlobPoints(
const CvPoint &cog, deque<CvPoint> &blobPoints);
360 bool getSuperQuadric(
const CvPoint &point, Vector &pos, Vector &dim);
368 bool get3DPosition(
const CvPoint &point, Vector &
x);
377 bool get3DPositionAndDimensions(
const CvRect &bbox, Vector &
x, Vector &dim);
378 Vector calibPosition(
const Vector &
x);
385 bool getClickPosition(CvPoint &pos);
398 void drawBlobs(
const Bottle &blobs,
const unsigned int i,
const Bottle &scores);
406 void rotate(cv::Mat &src,
const double angle, cv::Mat &dst);
414 void drawScoresHistogram(
const Bottle &blobs,
const Bottle &scores,
const int i);
422 int findClosestBlob(
const Bottle &blobs,
const CvPoint &loc);
430 int findClosestBlob(
const Bottle &blobs,
const Vector &loc);
437 Bottle classify(
const Bottle &blobs);
445 void train(
const string &
object,
const Bottle &blobs,
const int i);
450 void doLocalization();
462 ObjectArea getReachableArea(
const yarp::sig::VectorOf<double> &objpos);
464 bool configure(ResourceFinder &
rf);
474 void setBounds(ResourceFinder &
rf, Vector &bounds,
string configName,
double std_lower,
double std_upper);
475 bool interruptModule();
477 bool attach(RpcServer &source);
482 bool train_object(
const string &name);
483 bool remove_object(
const string &name);
485 bool change_name(
const string &old_name,
const string &new_name);
486 bool set_object_persistence(
const string &sw);
487 string get_object_persistence();
Vector robot_area_y_bounds
Yarp Vector of min, max bounding of robot region in y-axis.
Bottle lastBlobs
Bottle contains last blob information.
double lastBlobsArrivalTime
time stamp of last received blob
Bottle opcBlobs
Bottle contains received blobs of objects from OPC.
Vector skim_blobs_y_bounds
Yarp Vector of min, max bounding in y-axis to reduce the blob detection.
map< string, Filter * > histFiltersPool
RpcClient rpcGetSPQ
rpc client port to send requests to superquadric-model and receive superquadric parameters ...
MedianFilter filterPos
median filter for position of object
ClassifierReporter classifierReporter
Vector shared_area_y_bounds
Yarp Vector of min, max bounding of shared region in y-axis.
void heartBeat()
heartBeat current time value
iol2opc_IDL IDL Interface to iol2opc service.
cv::Ptr< cv::Tracker > tracker
Vector human_area_y_bounds
Yarp Vector of min, max bounding of human region in y-axis.
double trackerTimer
current value of tracker timer
BufferedPort< ImageOf< PixelBgr > > imgHistogram
buffered port of output image of histogram of classification scores.
RpcClient rpcClassifier
rpc client port to send requests to himrepClassifier
int trackerState
tracker state: idle, init, no_need or tracking
Vector robot_area_x_bounds
Yarp Vector of min, max bounding of robot region in x-axis.
void track(const Image &img)
track procdure to start tracking an image
Port imgClassifier
port of output image to himrefClassifier
BufferedPort< ImageOf< PixelBgr > > imgIn
buffered port of input calibrated image from left camera of iCub
BufferedPort< ImageOf< PixelBgr > > imgRtLocOut
buffered port of output image for real-time objects localization
BufferedPort< ImageOf< PixelBgr > > imgTrackOut
buffered port of output image of tracked object
double trackerTmo
set value of tracker timout
double blobs_detection_timeout
Vector human_area_x_bounds
Yarp Vector of min, max bounding of human region in x-axis.
IOLObject onlyKnownObjects
Bottle opcScores
Bottle contains received (class) score of objects from OPC.
An OPC client using the datastructures defined within the icub-client library.
map< string, IOLObject > db
MedianFilter filterDim
median filter for object dimension
BufferedPort< Bottle > blobExtractor
buffered port of input of received blobs from lbpExtract
void latchBBox(const CvRect &bbox)
latchBBox assign tracker with bounding box value
BufferedPort< ImageOf< PixelBgr > > imgSelBlobOut
buffered port of output image inside the selected blob (by clicking on)
Vector shared_area_x_bounds
Yarp Vector of min, max bounding of shared region in x-axis.
BufferedPort< Bottle > getClickPort
buffered port of input of clicked position
RpcServer rpcPort
rpc server to receive user request
BufferedPort< Bottle > histObjLocPort
buffered port of input of localized objects from iol localizer
void prepare()
prepare initialize the tracker
RpcClient rpcGetBlobPoints
rpc client port to send requests to lbpExtract and receive all points of a blob
OPCClient * opc
OPC client object.
bool is_tracking(CvRect &bbox) const
is_tracking procedure to check the tracking state
Vector skim_blobs_x_bounds
Yarp Vector of min, max bounding in x-axis to reduce the blob detection.
deque< CvScalar > histColorsCode
VectorOf< int > tracker_min_blob_size
minimum size of tracker blob
bool isDead()
isDead duration comparison procedure with presenceTmo
bool useSPQ
boolean flag to enable/disable using Superquadric-model for object pose and size estimation ...
RpcClient rpcGet3D
rpc client port to send requests to SFM
BufferedPort< Bottle > objLocOut
buffered port of output of localized objects
IOLObject(const int filter_order=1, const double presenceTmo_=0.0, const string &trackerType_="BOOSTING", const double trackerTmo_=0.0)
double presenceTimer
current timer
void filt(const Vector &x, Vector &xFilt, const Vector &d, Vector &dFilt)
filt apply the median filter
RtLocalization rtLocalization
double presenceTmo
current set timeout
ImageOf< PixelBgr > imgRtLoc
Image for real-time objects localization.
bool connectedSPQ
boolean flag to check internal connection to Superquadric-model