#pragma once #include #include #include #include #include #include using namespace std; class Point { public: int keyPointIndex; int x; int y; public: Point() {} ~Point() {} bool jsonToObject(const rapidjson::Value& object){ const auto end = object.MemberEnd(); if(end == object.FindMember("keyPointIndex") || !object["keyPointIndex"].IsInt()){ return false; }else{ keyPointIndex = object["keyPointIndex"].GetInt(); } if(end == object.FindMember("point") || !object["point"].IsObject()){ return false; }else{ const rapidjson::Value& obj = object["point"]; const auto end1 = obj.MemberEnd(); if(end1 == obj.FindMember("x") || !obj["x"].IsInt()){ return false; }else{ x = ((float)obj["x"].GetInt() / 574) * 1920; } if(end1 == obj.FindMember("y") || !obj["y"].IsInt()){ return false; }else{ y = ((float)obj["y"].GetInt() / 396) * 1080; } } return true; } }; class InferRange { public: vector m_points; public: InferRange() {} ~InferRange() {} bool jsonToObject(const std::string& json){ rapidjson::Document doc; if (doc.Parse(json.c_str()).HasParseError()) { return false; } if(doc.IsArray()) { const rapidjson::Value& objs = doc; for(int i = 0; i < (int)objs.Size(); i++){ Point point; if(!point.jsonToObject(objs[i])){ return false; } m_points.push_back(point); } }else{ return false; } return true; } };