#pragma once #include #include #include #include #include using namespace std; class HepuTarget2 //doc 4.7.31 { private: public: using Ptr = std::shared_ptr; public: const string cmd = "ivpClientTracking"; string token; int channelid;//0:红外 1:可见光 int trackingStatus;//跟踪状态,0:非跟踪状态;1:跟踪正常;2:跟踪不稳定;3:跟踪目标失锁;4:跟踪目标丢失;10:跟踪通信异常;其他:跟踪失败; struct Size{ int width; int height; }; struct Rect{ int x; int y; int width; int height; }; Size size;//跟踪视频尺寸 Rect rect;//跟踪目标在图像上的位置坐标,在跟踪视频尺寸坐标系下 double response;//跟踪响应率 HepuTarget2(){}; ~HepuTarget2(){}; void objectToJson(string& str){ rapidjson::StringBuffer strBuf; rapidjson::Writer writer(strBuf); this->objectToJson(writer); str = strBuf.GetString(); } void objectToJson(rapidjson::Writer& writer){ writer.StartObject(); writer.Key("cmd"); writer.String(cmd.c_str()); writer.Key("param"); writer.StartObject(); writer.Key("token"); writer.String(token.c_str()); writer.Key("channelid"); writer.Int(channelid); writer.Key("trackingStatus"); writer.Int(trackingStatus); writer.Key("size"); writer.StartArray(); writer.Int(size.width); writer.Int(size.height); writer.EndArray(); writer.Key("rect"); writer.StartArray(); writer.Int(rect.x); writer.Int(rect.y); writer.Int(rect.width); writer.Int(rect.height); writer.EndArray(); writer.Key("response"); writer.Double(response); writer.EndObject(); writer.EndObject(); } bool jsonToObject(std::string& json){ rapidjson::Document doc; doc.Parse(json.c_str()); if(!doc.IsObject()){ return false; } const auto end = doc.MemberEnd(); if(end == doc.FindMember("cmd") || !doc["cmd"].IsString()){ return false; }else{ if(cmd != doc["cmd"].GetString()) return false; } if(end == doc.FindMember("param") || !doc["param"].IsObject()) { return false; }else{ if(end == doc.FindMember("token") || !doc["token"].IsString()) { return false; }else{ token = doc["token"].GetString(); } if(end == doc.FindMember("channelid") || !doc["channelid"].IsInt()) { return false; }else{ channelid = doc["channelid"].GetInt(); } if(end == doc.FindMember("trackingStatus") || !doc["trackingStatus"].IsInt()) { return false; }else{ trackingStatus = doc["trackingStatus"].GetInt(); } if(end == doc.FindMember("size") || !doc["size"].IsArray()) { return false; }else{ const auto temp = doc["size"].GetArray(); if(temp.Size() < 2) return false; size.width = temp[0].GetInt(); size.height = temp[1].GetInt();; } if(end == doc.FindMember("rect") || !doc["rect"].IsArray()) { return false; }else{ const auto temp = doc["rect"].GetArray(); if(temp.Size() < 4) return false; rect.x = temp[0].GetInt(); rect.y = temp[1].GetInt(); rect.width = temp[2].GetInt(); rect.height = temp[3].GetInt();; } if(end == doc.FindMember("response") || !doc["response"].IsDouble()) { return false; }else{ response = doc["response"].GetDouble(); } } return true; } };