string ofxTSPSPerson::getJSON( string type, ofPoint centroid, int cameraWidth, int cameraHeight, bool bSendContours ){ //construct a JSON object stringstream message; message<<"{"; message<<"\"type\":\""<<type<<"\","; message<<"\"id\":"<<pid<<","; message<<"\"age\":"<<age<<","; message<<"\"depth\":"<<depth<<","; message<<"\"centroid\":{"<<"\"x\":"<<centroid.x<<",\"y\":"<<centroid.y<<"},"; //pass in normalized centroid message<<"\"velocity\":{"<<"\"x\":"<<ofToString(velocity.x, 3)<<",\"y\":"<<ofToString(velocity.y, 3)<<"},"; ofRectangle scaledRect = getBoundingRectNormalized(cameraWidth,cameraHeight); message<<"\"boundingrect\":{"<<"\"x\":"<<scaledRect.x<<",\"y\":"<<scaledRect.y<<",\"width\":"<<scaledRect.width<<",\"height\":"<<scaledRect.height<<"},"; message<<"\"opticalflow\":{"<<"\"x\":"<<opticalFlowVectorAccumulation.x<<",\"y\":"<<opticalFlowVectorAccumulation.y<<"},"; ofRectangle scaledHaar = getHaarRectNormalized(cameraWidth,cameraHeight); message<<"\"haarrect\":{"<<"\"x\":"<<scaledHaar.x<<",\"y\":"<<scaledHaar.y<<",\"width\":"<<scaledHaar.width<<",\"height\":"<<scaledHaar.height<<"},"; if (bSendContours){ message<<"\"contours\":["; for (int i=0; i<simpleContour.size(); i++){ message<<"{\"x\":"<<ofToString(simpleContour[i].x, 3)<<",\"y\":"<<ofToString(simpleContour[i].y, 3)<<"}"; if (i+1 < simpleContour.size()) message<<","; }; message<<"]"; } message<<"}"; return message.str(); }
//-------------------------------------------------------------- vector<ofxOscMessage> Person::getOSCMessages( string type, bool bUseLegacy, int cameraWidth, int cameraHeight, bool sendContours ){ vector<ofxOscMessage> v; ofxOscMessage m; m.setAddress( type ); m.addIntArg( pid ); if(!bUseLegacy){ m.addIntArg(oid); } m.addIntArg(age); ofPoint centroidNormalized = getCentroidNormalized(cameraWidth, cameraHeight); m.addFloatArg(centroidNormalized.x); m.addFloatArg(centroidNormalized.y); m.addFloatArg(velocity.x); m.addFloatArg(velocity.y); if(!bUseLegacy){ m.addFloatArg(depth); } ofRectangle boundingRect = getBoundingRectNormalized(cameraWidth,cameraHeight); m.addFloatArg(boundingRect.x); m.addFloatArg(boundingRect.y); m.addFloatArg(boundingRect.width); m.addFloatArg(boundingRect.height); if(!bUseLegacy){ m.addFloatArg(highest.x / cameraWidth ); m.addFloatArg(highest.y / cameraHeight ); } ofRectangle haarRect = getHaarRectNormalized(cameraWidth,cameraHeight); if (!bUseLegacy){ m.addFloatArg(haarRect.x); m.addFloatArg(haarRect.y); m.addFloatArg(haarRect.width); m.addFloatArg(haarRect.height); } m.addFloatArg(opticalFlowVectorAccumulation.x); m.addFloatArg(opticalFlowVectorAccumulation.y); if (sendContours){ //any args after 11 will be contours for (int i=0; i<simpleContour.size(); i++){ m.addFloatArg(simpleContour[i].x); m.addFloatArg(simpleContour[i].y); }; } v.push_back(m); return v; };
//-------------------------------------------------------------- string Person::getJSON( string type, int cameraWidth, int cameraHeight, bool bSendContours, string append ){ //construct a JSON object stringstream message; message<<"{"; message<<"\"type\":\""<<type<<"\","; message<<"\"id\":"<<pid<<","; message<<"\"age\":"<<age<<","; message<<"\"depth\":"<<depth<<","; ofPoint normalizedCentroid = getCentroidNormalized( cameraWidth, cameraHeight ); message<<"\"centroid\":{"<<"\"x\":"<<normalizedCentroid.x<<",\"y\":"<<normalizedCentroid.y <<"},"; //pass in normalized centroid message<<"\"velocity\":{"<<"\"x\":"<<ofToString(velocity.x, 3)<<",\"y\":"<<ofToString(velocity.y, 3)<<"},"; ofRectangle scaledRect = getBoundingRectNormalized(cameraWidth,cameraHeight); message<<"\"boundingrect\":{"<<"\"x\":"<<scaledRect.x<<",\"y\":"<<scaledRect.y<<",\"width\":"<<scaledRect.width<<",\"height\":"<<scaledRect.height<<"},"; message<<"\"opticalflow\":{"<<"\"x\":"<<opticalFlowVectorAccumulation.x<<",\"y\":"<<opticalFlowVectorAccumulation.y<<"},"; ofRectangle scaledHaar = getHaarRectNormalized(cameraWidth,cameraHeight); message<<"\"haarrect\":{"<<"\"x\":"<<scaledHaar.x<<",\"y\":"<<scaledHaar.y<<",\"width\":"<<scaledHaar.width<<",\"height\":"<<scaledHaar.height<<"},"; message<<"\"highest\":{"<<"\"x\":"<<( (float) highest.x / cameraWidth )<<",\"y\":"<<( (float) highest.y / cameraHeight)<<"}"; // TO-DO: Normalize these!!! if (bSendContours){ message<<","; message<<"\"contours\":["; for (int i=0; i<simpleContour.size(); i++){ message<<"{\"x\":"<<ofToString(simpleContour[i].x, 3)<<",\"y\":"<<ofToString(simpleContour[i].y, 3)<<"}"; if (i+1 < simpleContour.size()) message<<","; }; message<<"]"; } message<<append; // trusting you to make good decisions here! message<<"}"; return message.str(); }