123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- #pragma once
- #include <iostream>
- #include <rapidjson/document.h>
- #include <rapidjson/rapidjson.h>
- #include <rapidjson/stringbuffer.h>
- #include <rapidjson/writer.h>
- using namespace std;
- class HepuTarget2 //doc 4.7.31
- {
- private:
- public:
- using Ptr = std::shared_ptr<HepuTarget2>;
- public:
- const string cmd = "ivpClientTracking";
- string token;
- int channelid;//0:红外 1:可见光
- int trackingStatus;//跟踪状态,0:非跟踪状态;1:跟踪正常;2:跟踪不稳定;3:跟踪目标失锁;4:跟踪目标丢失;10:跟踪通信异常;其他:跟踪失败;
- typedef struct Size{
- int width;
- int height;
- };
- typedef 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<rapidjson::StringBuffer> writer(strBuf);
- this->objectToJson(writer);
- str = strBuf.GetString();
- }
- void objectToJson(rapidjson::Writer<rapidjson::StringBuffer>& 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;
- }
- };
|