13 size_t found=mode.find_first_of(
'+');
14 if ((found>0) && (found!=string::npos))
16 submode=mode.substr(0,found);
17 if (found+1<mode.length())
18 mode=mode.substr(found+1,mode.length()-found);
25 return !submode.empty();
30 period = rf.check(
"period",Value(0.03)).asDouble();
31 int verbosity=rf.check(
"verbosity",Value(0)).asInt();
32 string name=rf.check(
"name",Value(
"agentDetector")).asString().c_str();
35 string show=rf.check(
"showImages",Value(
"false")).asString().c_str();
36 showMode=rf.check(
"showMode",Value(
"rgb+depth+skeleton+players")).asString().c_str();
45 string opcName=rf.check(
"opc",Value(
"OPC")).asString().c_str();
50 yInfo()<<
"Waiting connection to OPC...";
56 for(
auto e : entityList) {
67 string rfhName=rf.check(
"rfh",Value(
"referenceFrameHandler")).asString().c_str();
68 rfh.open(
"/"+name+
"/rfh:o");
70 string rfhRemote =
"/"+rfhName+
"/rpc";
72 while (!Network::connect(
rfh.getName(), rfhRemote.c_str()))
74 yInfo()<<
"Waiting connection to RFH...";
80 yWarning() <<
" ========================= KINECT NEEDS TO BE CALIBRATED ============================" ;
82 string clientName = name +
"/kinect";
85 depthPort.open((
"/"+clientName+
"/depthPort:o").c_str());
86 imagePort.open((
"/"+clientName+
"/imagePort:o").c_str());
87 playersPort.open((
"/"+clientName+
"/playersPort:o").c_str());
88 skeletonPort.open((
"/"+clientName+
"/skeletonPort:o").c_str());
92 options.put(
"carrier",
"tcp");
93 options.put(
"remote",
"kinectServer");
94 options.put(
"local",clientName.c_str());
95 options.put(
"verbosity",verbosity);
104 int xPos = rf.check(
"x",Value(10)).asInt();
105 int yPos = rf.check(
"y",Value(10)).asInt();
107 int img_width=opt.find(
"img_width").asInt();
108 int img_height=opt.find(
"img_height").asInt();
109 int depth_width=opt.find(
"depth_width").asInt();
110 int depth_height=opt.find(
"depth_height").asInt();
112 rgb.resize(img_width, img_height);
113 depth.resize(depth_width,depth_height);
118 depthTmp=cvCreateImage(cvSize(depth_width,depth_height),IPL_DEPTH_32F,1);
119 rgbTmp=cvCreateImage(cvSize(img_width,img_height),IPL_DEPTH_8U,3);
123 vector<bool> alreadyOpen(4,
false);
126 while (!mode.empty())
134 int x_rgb=rf.check(
"x-rgb",Value(xPos)).asInt();
135 int y_rgb=rf.check(
"y-rgb",Value(yPos)).asInt();
136 yInfo(
"\"rgb\" window selected in (%d,%d)",x_rgb,y_rgb);
138 cvNamedWindow(
"rgb",CV_WINDOW_AUTOSIZE);
139 cvMoveWindow(
"rgb",x_rgb,y_rgb);
143 yWarning(
"\"rgb\" window already open");
145 else if (submode==
"depth")
149 int x_depth=rf.check(
"x-depth",Value(xPos+300)).asInt();
150 int y_depth=rf.check(
"y-depth",Value(yPos)).asInt();
151 yInfo(
"\"depth\" window selected in (%d,%d)",x_depth,y_depth);
153 cvNamedWindow(
"depth",CV_WINDOW_AUTOSIZE);
154 cvMoveWindow(
"depth",x_depth,y_depth);
160 yWarning(
"\"depth\" window already open");
162 else if (submode==
"skeleton")
166 int x_skeleton=rf.check(
"x-skeleton",Value(xPos)).asInt();
167 int y_skeleton=rf.check(
"y-skeleton",Value(yPos+300)).asInt();
168 yInfo(
"\"skeleton\" window selected in (%d,%d)",x_skeleton,y_skeleton);
170 cvNamedWindow(
"skeleton",CV_WINDOW_AUTOSIZE);
171 cvMoveWindow(
"skeleton",x_skeleton,y_skeleton);
175 yWarning(
"\"skeleton\" window already open");
177 else if (submode==
"players")
181 int x_players=rf.check(
"x-players",Value(xPos+300)).asInt();
182 int y_players=rf.check(
"y-players",Value(yPos+300)).asInt();
183 yInfo(
"\"players\" window selected in (%d,%d)",x_players,y_players);
185 cvNamedWindow(
"players",CV_WINDOW_AUTOSIZE);
186 cvMoveWindow(
"players",x_players,y_players);
190 yWarning(
"\"players\" window already open");
193 yError(
"unrecognized show mode!");
198 rpc.open(
"/"+name+
"/rpc");
210 if (
rfh.getOutputCount()>0)
213 bCmd.addString(
"mat");
214 bCmd.addString(
"kinect");
215 bCmd.addString(
"icub");
216 rfh.write(bCmd,reply);
218 if (reply.get(0).asString()!=
"nack")
220 if (Bottle *bMat=reply.get(1).asList())
223 for (
int i=0; i<4; i++)
224 for (
int j=0; j<4; j++)
261 if (cmd.get(0).asString() ==
"change_partner_name" ) {
262 if(cmd.get(1).isString()) {
263 reply.addString(
"ack");
267 reply.addString(
"nack");
270 else if (cmd.get(0).asString() ==
"pause" ) {
272 reply.addString(
"ack");
274 else if (cmd.get(0).asString() ==
"resume" ) {
276 reply.addString(
"ack");
280 reply.addString(
"nack");
346 cvCvtColor((IplImage*)
rgb.getIplImage(),
rgbTmp,CV_BGR2RGB);
350 while (!mode.empty())
355 cvShowImage(
"rgb",
rgbTmp);
356 else if (submode==
"depth")
358 else if (submode==
"skeleton")
359 cvShowImage(
"skeleton",(IplImage*)
skeletonImage.getIplImage());
360 else if (submode==
"players")
361 cvShowImage(
"players",(IplImage*)
playersImage.getIplImage());
363 yError(
"unrecognized show mode!");
379 Vector clickedPoint(3);
382 yInfo()<<clickedPoint.toString(3,3);
388 bObject.addString(
"==");
393 bPresent.addString(
"==");
394 bPresent.addDouble(1.0);
396 bCond.addList()=bObject;
397 bCond.addString(
"&&");
398 bCond.addList()=bPresent;
406 if (presentObjects.size()==1) {
407 o=
dynamic_cast<Object*
>(presentObjects.front());
409 for(
auto& presentObject : presentObjects) {
410 if(presentObject->name() ==
"target") {
411 o=
dynamic_cast<Object*
>(presentObject);
417 Bottle botRPH, botRPHRep;
418 botRPH.addString(
"add");
419 botRPH.addString(
"kinect");
420 Bottle &cooKinect=botRPH.addList();
421 cooKinect.addDouble(clickedPoint[0]);
422 cooKinect.addDouble(clickedPoint[1]);
423 cooKinect.addDouble(clickedPoint[2]);
425 Bottle &cooiCub=botRPH.addList();
429 rfh.write(botRPH,botRPHRep);
430 yInfo(
"Sent to RFH: %s", botRPH.toString().c_str());
431 yInfo(
"Got from RFH: %s", botRPHRep.toString().c_str());
435 yWarning(
"There should be 1 and only 1 object on the table");
436 yWarning(
"If there is more than one object, the object you want");
437 yWarning(
"to calibrate must be called \"target\"");
445 Bottle calibBottle,calibReply;
446 calibBottle.addString(
"cal");
447 calibBottle.addString(
"kinect");
448 rfh.write(calibBottle,calibReply);
449 yInfo(
"Calibrated: %s!", calibReply.toString().c_str());
452 calibBottle.addString(
"save");
453 rfh.write(calibBottle,calibReply);
454 yInfo(
"Saved to file: %s!", calibReply.toString().c_str());
458 yWarning(
"Unable to calibrate with less than 3 points pairs collected");
467 for(deque<Player>::iterator p=
joints.begin(); p!=
joints.end(); p++)
470 bool reallyTracked =
false;
471 for(map<string,Joint>::iterator jnt = p->skeleton.begin() ; jnt != p->skeleton.end() ; jnt++)
473 if (jnt->second.x != 0 && jnt->second.y != 0 && jnt->second.z != 0)
475 reallyTracked =
true;
break;
511 yInfo(
"Assigning name %s to skeleton %i", playerName.c_str(), p->ID);
514 if(specificAgent ==
nullptr) {
515 yError() << playerName <<
" is not in the OPC";
518 specificAgent->m_present = 1.0;
519 yInfo() <<
" specific agent is commited";
521 yInfo() <<
" specific agent is commited done";
528 for(map<string,Joint>::iterator jnt = p->skeleton.begin() ; jnt != p->skeleton.end() ; jnt++)
533 kPosition[0] = jnt->second.x;
534 kPosition[1] = jnt->second.y;
535 kPosition[2] = jnt->second.z;
538 Vector irPos = icubPos.subVector(0,2);
545 jntBtl.addString(jnt->first);
546 jntBtl.addDouble(jnt->second.x);
547 jntBtl.addDouble(jnt->second.y);
548 jntBtl.addDouble(jnt->second.z);
549 skeleton.addList() = jntBtl;
558 bBodyPartLoc.addString(jnt->first);
559 bBodyPartLoc.addString(irPos.toString());
561 bAgentLoc.addList() = bBodyPartLoc;
588 return sqrt(pow((j1.x - j2.x),2.0) + pow((j1.y - j2.y),2.0) + pow((j1.z - j2.z),2.0));
616 double bestVal = DBL_MAX;
623 for(
size_t i=0; i<currentPattern.size();i++)
625 distance += pow( patternIt->second[i] - currentPattern[i], 2.0);
627 distance = sqrt(distance);
629 if (distance < bestVal)
632 bestName = patternIt->first;
650 H(0,0) = cos(phi); H(0,1) = -sin(phi); H(0,2) = 0.0; H(0,3) = Xs[0];
651 H(1,0) = sin(phi); H(1,1) = cos(phi); H(1,2) = 0.0; H(1,3) = Xs[1];
652 H(2,0) = 0.0; H(2,1) = 0.0; H(2,2) = 1.0; H(2,3) = 0.0;
653 H(3,0) = 0.0; H(3,1) = 0.0; H(3,2) = 0.0; H(3,3) = 1.0;
int pointsCnt
integer of number of points
bool respond(const Bottle &cmd, Bottle &reply)
OPCClient * opc
OPC client object.
ImageOf< PixelBgr > skeletonImage
skeleton imange in a Yarp format
yarp::sig::VectorOf< double > m_ego_orientation
Orientation of the Object, in the initial ego-centered reference frame of the agent mainting the OPC ...
void close()
Close the client ports.
Agent * partner
human as an agent object
static void click_callback(int event, int x, int y, int flags, void *param)
double m_present
Is the object present in the scene A value of 1.0 means that the object currently is in the scene A v...
void commit()
Commit all the entities & relations stored locally, erasing the server copies.
map< int, string > identities
T * addOrRetrieveEntity(const std::string &name)
Obtains an entity with the given name.
static clickType clicked
clicked type of object: left, right or nothing
Port rfh
port to referenceFrameHandler
bool connect(const std::string &opcName)
Try to connect the client to an OPC server.
Represent any physical entity (including objects and agents) that can be stored within the OPC...
yarp::sig::VectorOf< double > m_ego_position
Position of the Object, in the initial ego-centered reference frame of the agent mainting the OPC (in...
static float clickY
float value of clicked coordinate in x and y axes
string getIdentity(Player p)
getIdentity Obtain identity of partner
yarp::os::BufferedPort< Bottle > agentLocOutPort
Output Yarp Buffered Port of Bottle contains agent location.
bool isMounted
boolean value to check if the IR is mounted or not
map< string, Vector > skeletonPatterns
properties of skeleton obtained from kinect
bool configure(ResourceFinder &rf)
string partner_default_name
string value of default name of partner
Vector getSkeletonPattern(Player p)
getSkeletonPattern Obtain some properties of partner skeleton, such as eblow, shoulder, head position and size
ImageOf< PixelBgr > playersImage
partner image in a Yarp format
bool showImageParser(string &mode, string &submode)
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelBgr > > playersPort
Output Yarp Buffered Port of partner images.
std::list< std::shared_ptr< Entity > > EntitiesCacheCopy() const
Getter of the list of the copies of the entities stored locally.
string showMode
string value of show mode of module: rgb, depth, skeleton, players
double distanceVector(Joint j1, Joint j2)
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelFloat > > depthPort
Output Yarp Buffered Port of images contains depth information.
An OPC client using the datastructures defined within the icub-client library.
Port rpc
rpc server port to receive requests
ImageOf< PixelMono16 > depth
depth image in a Yarp format
Matrix kinect2icub
conversion matrix from kinect frame to icub frame
double dThresholdDisparition
timing maximal of non-reconnaissance of a agent, after thath we consider the agent as absent ...
std::list< Entity * > Entities(const yarp::os::Bottle &condition)
Getter of the list of entities of matching a complex condition (e.g "(entity "==" agent) "&&" (isPres...
Vector transform2IR(Vector v)
transform2IR Transform a position to IR reference frame
double dSince
double value of timers
void checkout(bool updateCache=true)
Poll the OPC for all entities and relations and store them locally.
KinectWrapperClient client
kinect wrapper client object
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelRgb > > imagePort
Output Yarp Buffered Port of images contains images.
yarp::os::BufferedPort< Bottle > outputSkeletonPort
Output Yarp Buffered Port of Bottle contains skeleton properties.
yarp::os::BufferedPort< yarp::sig::ImageOf< yarp::sig::PixelBgr > > skeletonPort
Output Yarp Buffered Port of skeleton images.
bool handleMultiplePlayers
boolean value for multiple players or not, if not, obtain only the closest player ...
unsigned long dTimingLastApparition
time struct of the last appartition of an agent
ImageOf< PixelFloat > depthToDisplay
depth image to display in a Yarp format
bool isCalibrated
boolean value to check if the kinect is calibrated or not
std::map< std::string, yarp::sig::VectorOf< double > > m_parts