HandPostureResult.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/facebody/model/HandPostureResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Facebody;
  19. using namespace AlibabaCloud::Facebody::Model;
  20. HandPostureResult::HandPostureResult() :
  21. ServiceResult()
  22. {}
  23. HandPostureResult::HandPostureResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. HandPostureResult::~HandPostureResult()
  29. {}
  30. void HandPostureResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto dataNode = value["Data"];
  37. auto allOutputsNode = dataNode["Outputs"]["Output"];
  38. for (auto dataNodeOutputsOutput : allOutputsNode)
  39. {
  40. Data::Output outputObject;
  41. if(!dataNodeOutputsOutput["HandCount"].isNull())
  42. outputObject.handCount = std::stoi(dataNodeOutputsOutput["HandCount"].asString());
  43. auto allResultsNode = dataNodeOutputsOutput["Results"]["Result"];
  44. for (auto dataNodeOutputsOutputResultsResult : allResultsNode)
  45. {
  46. Data::Output::Result resultsObject;
  47. auto handsNode = value["Hands"];
  48. if(!handsNode["Confident"].isNull())
  49. resultsObject.hands.confident = std::stof(handsNode["Confident"].asString());
  50. auto allKeyPointsNode = handsNode["KeyPoints"]["KeyPoint"];
  51. for (auto handsNodeKeyPointsKeyPoint : allKeyPointsNode)
  52. {
  53. Data::Output::Result::Hands::KeyPoint keyPointObject;
  54. if(!handsNodeKeyPointsKeyPoint["Label"].isNull())
  55. keyPointObject.label = handsNodeKeyPointsKeyPoint["Label"].asString();
  56. auto allPositionsNode = handsNodeKeyPointsKeyPoint["Positions"]["Position"];
  57. for (auto handsNodeKeyPointsKeyPointPositionsPosition : allPositionsNode)
  58. {
  59. Data::Output::Result::Hands::KeyPoint::Position positionsObject;
  60. auto allPoints = value["Points"]["Point"];
  61. for (auto value : allPoints)
  62. positionsObject.points.push_back(value.asString());
  63. keyPointObject.positions.push_back(positionsObject);
  64. }
  65. resultsObject.hands.keyPoints.push_back(keyPointObject);
  66. }
  67. auto boxNode = value["Box"];
  68. if(!boxNode["Confident"].isNull())
  69. resultsObject.box.confident = std::stof(boxNode["Confident"].asString());
  70. auto allPositions1Node = boxNode["Positions"]["Position"];
  71. for (auto boxNodePositionsPosition : allPositions1Node)
  72. {
  73. Data::Output::Result::Box::Position2 position2Object;
  74. auto allPoints3 = value["Points"]["Point"];
  75. for (auto value : allPoints3)
  76. position2Object.points3.push_back(value.asString());
  77. resultsObject.box.positions1.push_back(position2Object);
  78. }
  79. outputObject.results.push_back(resultsObject);
  80. }
  81. data_.outputs.push_back(outputObject);
  82. }
  83. auto metaObjectNode = dataNode["MetaObject"];
  84. if(!metaObjectNode["Width"].isNull())
  85. data_.metaObject.width = std::stoi(metaObjectNode["Width"].asString());
  86. if(!metaObjectNode["Height"].isNull())
  87. data_.metaObject.height = std::stoi(metaObjectNode["Height"].asString());
  88. }
  89. HandPostureResult::Data HandPostureResult::getData()const
  90. {
  91. return data_;
  92. }