|
1 |
| -#include "k2_client/k2_client.h" |
2 |
| -#include "k2_client/FaceArray.h" |
3 |
| -#include <iconv.h> |
4 |
| -#include <cstdio> |
5 |
| - |
6 |
| -int main(int argC,char **argV) |
7 |
| -{ |
8 |
| - while(ros::ok()) |
9 |
| - { |
10 |
| - ROS_ERROR("STARTFACE is running."); |
11 |
| - |
12 |
| - } |
13 |
| - return 0; |
14 |
| -} |
| 1 | +#include "k2_client/k2_client.h" |
| 2 | +#include "k2_client/FaceArray.h" |
| 3 | +#include <iconv.h> |
| 4 | +#include <cstdio> |
| 5 | + |
| 6 | +int main(int argC,char **argV) |
| 7 | +{ |
| 8 | + while(ros::ok()) |
| 9 | + { |
| 10 | + mySocket.readData(); |
| 11 | + std::string jsonString(mySocket.mBuffer); |
| 12 | + Json::Value jsonObject; |
| 13 | + Json::Reader jsonReader; |
| 14 | + bool parsingSuccessful = jsonReader.parse(jsonString,jsonObject,false); |
| 15 | + if(!parsingSuccessful) |
| 16 | + { |
| 17 | + ROS_ERROR("Failure to parse"); |
| 18 | + continue; |
| 19 | + } |
| 20 | + k2_client::FaceArray faceArray; |
| 21 | + try |
| 22 | + { |
| 23 | + for(int i=0;i<6;i++) |
| 24 | + { |
| 25 | + k2_client::Face face; |
| 26 | + face.header.stamp = ros::Time::now(); |
| 27 | + face.header.frame_id = ros::this_node::getNamespace().substr(1,std::string::npos) + "/depthFrame"; |
| 28 | + |
| 29 | + face.appearance.wearingGlasses = jsonObject[i]["FaceProperties"]["WearingGlasses"].asBool(); |
| 30 | + face.activities.eyeLeftClosed = jsonObject[i]["FaceProperties"]["EyeLeftClosed"].asBool(); |
| 31 | + face.activities.eyeRightClosed = jsonObject[i]["FaceProperties"]["EyeRightClosed"].asBool(); |
| 32 | + face.activities.mouthOpen = jsonObject[i]["FaceProperties"]["MouthOpen"].asBool(); |
| 33 | + face.activities.mouthMoved = jsonObject[i]["FaceProperties"]["MouthMoved"].asBool(); |
| 34 | + face.activities.lookingAway = jsonObject[i]["FaceProperties"]["LookingAway"].asBool(); |
| 35 | + face.expressions.neutral = jsonObject[i]["FaceProperties"]["Neutral"].asBool(); |
| 36 | + face.expressions.neutral = jsonObject[i]["FaceProperties"]["Happy"].asBool(); |
| 37 | + |
| 38 | + face.facePointsInInfraredSpace.eyeLeftX = jsonObject[i]["FacePointsInInfraredSpace"]["EyeLeft"]["X"].asDouble(); |
| 39 | + face.facePointsInInfraredSpace.eyeLeftY = jsonObject[i]["FacePointsInInfraredSpace"]["EyeLeft"]["Y"].asDouble(); |
| 40 | + face.facePointsInInfraredSpace.eyeRightX = jsonObject[i]["FacePointsInInfraredSpace"]["EyeRight"]["X"].asDouble(); |
| 41 | + face.facePointsInInfraredSpace.eyeRightY = jsonObject[i]["FacePointsInInfraredSpace"]["EyeRight"]["Y"].asDouble(); |
| 42 | + face.facePointsInInfraredSpace.noseX = jsonObject[i]["FacePointsInInfraredSpace"]["EyeRight"]["X"].asDouble(); |
| 43 | + face.facePointsInInfraredSpace.noseY = jsonObject[i]["FacePointsInInfraredSpace"]["EyeRight"]["Y"].asDouble(); |
| 44 | + face.facePointsInInfraredSpace.mouthCornerLeftX = jsonObject[i]["FacePointsInInfraredSpace"]["MouthCornerLeft"]["X"].asDouble(); |
| 45 | + face.facePointsInInfraredSpace.mouthCornerLeftY = jsonObject[i]["FacePointsInInfraredSpace"]["MouthCornerLeft"]["Y"].asDouble(); |
| 46 | + face.facePointsInInfraredSpace.mouthCornerRightX = jsonObject[i]["FacePointsInInfraredSpace"]["MouthCornerRight"]["X"].asDouble(); |
| 47 | + face.facePointsInInfraredSpace.mouthCornerRightY = jsonObject[i]["FacePointsInInfraredSpace"]["MouthCornerRight"]["Y"].asDouble(); |
| 48 | + |
| 49 | + face.facePointsInColorSpace.eyeLeftX = jsonObject[i]["FacePointsInColorSpace"]["EyeLeft"]["X"].asDouble(); |
| 50 | + face.facePointsInColorSpace.eyeLeftY = jsonObject[i]["FacePointsInColorSpace"]["EyeLeft"]["Y"].asDouble(); |
| 51 | + face.facePointsInColorSpace.eyeRightX = jsonObject[i]["FacePointsInColorSpace"]["EyeRight"]["X"].asDouble(); |
| 52 | + face.facePointsInColorSpace.eyeRightY = jsonObject[i]["FacePointsInColorSpace"]["EyeRight"]["Y"].asDouble(); |
| 53 | + face.facePointsInColorSpace.noseX = jsonObject[i]["FacePointsInColorSpace"]["EyeRight"]["X"].asDouble(); |
| 54 | + face.facePointsInColorSpace.noseY = jsonObject[i]["FacePointsInColorSpace"]["EyeRight"]["Y"].asDouble(); |
| 55 | + face.facePointsInColorSpace.mouthCornerLeftX = jsonObject[i]["FacePointsInColorSpace"]["MouthCornerLeft"]["X"].asDouble(); |
| 56 | + face.facePointsInColorSpace.mouthCornerLeftY = jsonObject[i]["FacePointsInColorSpace"]["MouthCornerLeft"]["Y"].asDouble(); |
| 57 | + face.facePointsInColorSpace.mouthCornerRightX = jsonObject[i]["FacePointsInColorSpace"]["MouthCornerRight"]["X"].asDouble(); |
| 58 | + face.facePointsInColorSpace.mouthCornerRightY = jsonObject[i]["FacePointsInColorSpace"]["MouthCornerRight"]["Y"].asDouble(); |
| 59 | + |
| 60 | + face.faceBoundingBoxInInfraredSpace.left = jsonObject[i]["FaceBoundingBoxInInfraredSpace"]["Left"].asInt(); |
| 61 | + face.faceBoundingBoxInInfraredSpace.top = jsonObject[i]["FaceBoundingBoxInInfraredSpace"]["Top"].asInt(); |
| 62 | + face.faceBoundingBoxInInfraredSpace.right = jsonObject[i]["FaceBoundingBoxInInfraredSpace"]["Right"].asInt(); |
| 63 | + face.faceBoundingBoxInInfraredSpace.bottom = jsonObject[i]["FaceBoundingBoxInInfraredSpace"]["Bottom"].asInt(); |
| 64 | + |
| 65 | + face.faceBoundingBoxInColorSpace.left = jsonObject[i]["FaceBoundingBoxInColorSpace"]["Left"].asInt(); |
| 66 | + face.faceBoundingBoxInColorSpace.top = jsonObject[i]["FaceBoundingBoxInColorSpace"]["Top"].asInt(); |
| 67 | + face.faceBoundingBoxInColorSpace.right = jsonObject[i]["FaceBoundingBoxInColorSpace"]["Right"].asInt(); |
| 68 | + face.faceBoundingBoxInColorSpace.bottom = jsonObject[i]["FaceBoundingBoxInColorSpace"]["Bottom"].asInt(); |
| 69 | + |
| 70 | + face.faceRotationQuaternion.X = jsonObject[i]["FaceRotationQuaternion"]["X"].asDouble(); |
| 71 | + face.faceRotationQuaternion.Y = jsonObject[i]["FaceRotationQuaternion"]["Y"].asDouble(); |
| 72 | + face.faceRotationQuaternion.Z = jsonObject[i]["FaceRotationQuaternion"]["Z"].asDouble(); |
| 73 | + face.faceRotationQuaternion.W = jsonObject[i]["FaceRotationQuaternion"]["W"].asDouble(); |
| 74 | + |
| 75 | + //face.trackingId = jsonObject[i]["TrackingId"].asInt(); |
| 76 | + face.faceFrameFeatures = jsonObject[i]["FaceFrameFeatures"].asInt(); |
| 77 | + |
| 78 | + faceArray.faces.push_back(face); |
| 79 | + } |
| 80 | + } |
| 81 | + catch (...) |
| 82 | + { |
| 83 | + ROS_ERROR("An exception occured"); |
| 84 | + continue; |
| 85 | + } |
| 86 | + if (faceArray.faces.size() > 0) |
| 87 | + facePub.publish(faceArray); |
| 88 | + } |
| 89 | + return 0; |
| 90 | +} |
0 commit comments