DetectFaceAttributesResult.cc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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/cloudauth/model/DetectFaceAttributesResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Cloudauth;
  19. using namespace AlibabaCloud::Cloudauth::Model;
  20. DetectFaceAttributesResult::DetectFaceAttributesResult() :
  21. ServiceResult()
  22. {}
  23. DetectFaceAttributesResult::DetectFaceAttributesResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DetectFaceAttributesResult::~DetectFaceAttributesResult()
  29. {}
  30. void DetectFaceAttributesResult::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. if(!dataNode["ImgWidth"].isNull())
  38. data_.imgWidth = std::stoi(dataNode["ImgWidth"].asString());
  39. if(!dataNode["ImgHeight"].isNull())
  40. data_.imgHeight = std::stoi(dataNode["ImgHeight"].asString());
  41. auto allFaceInfos = value["FaceInfos"]["FaceAttributesDetectInfo"];
  42. for (auto value : allFaceInfos)
  43. {
  44. Data::FaceAttributesDetectInfo faceAttributesDetectInfoObject;
  45. auto faceRectNode = value["FaceRect"];
  46. if(!faceRectNode["Top"].isNull())
  47. faceAttributesDetectInfoObject.faceRect.top = std::stoi(faceRectNode["Top"].asString());
  48. if(!faceRectNode["Left"].isNull())
  49. faceAttributesDetectInfoObject.faceRect.left = std::stoi(faceRectNode["Left"].asString());
  50. if(!faceRectNode["Width"].isNull())
  51. faceAttributesDetectInfoObject.faceRect.width = std::stoi(faceRectNode["Width"].asString());
  52. if(!faceRectNode["Height"].isNull())
  53. faceAttributesDetectInfoObject.faceRect.height = std::stoi(faceRectNode["Height"].asString());
  54. auto faceAttributesNode = value["FaceAttributes"];
  55. if(!faceAttributesNode["Age"].isNull())
  56. faceAttributesDetectInfoObject.faceAttributes.age = std::stoi(faceAttributesNode["Age"].asString());
  57. if(!faceAttributesNode["Glasses"].isNull())
  58. faceAttributesDetectInfoObject.faceAttributes.glasses = faceAttributesNode["Glasses"].asString();
  59. if(!faceAttributesNode["Facetype"].isNull())
  60. faceAttributesDetectInfoObject.faceAttributes.facetype = faceAttributesNode["Facetype"].asString();
  61. if(!faceAttributesNode["Blur"].isNull())
  62. faceAttributesDetectInfoObject.faceAttributes.blur = std::stof(faceAttributesNode["Blur"].asString());
  63. if(!faceAttributesNode["Ethnicity"].isNull())
  64. faceAttributesDetectInfoObject.faceAttributes.ethnicity = faceAttributesNode["Ethnicity"].asString();
  65. auto genderNode = faceAttributesNode["Gender"];
  66. if(!genderNode["Score"].isNull())
  67. faceAttributesDetectInfoObject.faceAttributes.gender.score = std::stof(genderNode["Score"].asString());
  68. if(!genderNode["Value"].isNull())
  69. faceAttributesDetectInfoObject.faceAttributes.gender.value = genderNode["Value"].asString();
  70. auto smilingNode = faceAttributesNode["Smiling"];
  71. if(!smilingNode["Value"].isNull())
  72. faceAttributesDetectInfoObject.faceAttributes.smiling.value = std::stof(smilingNode["Value"].asString());
  73. if(!smilingNode["Threshold"].isNull())
  74. faceAttributesDetectInfoObject.faceAttributes.smiling.threshold = std::stof(smilingNode["Threshold"].asString());
  75. auto headposeNode = faceAttributesNode["Headpose"];
  76. if(!headposeNode["PitchAngle"].isNull())
  77. faceAttributesDetectInfoObject.faceAttributes.headpose.pitchAngle = std::stof(headposeNode["PitchAngle"].asString());
  78. if(!headposeNode["RollAngle"].isNull())
  79. faceAttributesDetectInfoObject.faceAttributes.headpose.rollAngle = std::stof(headposeNode["RollAngle"].asString());
  80. if(!headposeNode["YawAngle"].isNull())
  81. faceAttributesDetectInfoObject.faceAttributes.headpose.yawAngle = std::stof(headposeNode["YawAngle"].asString());
  82. data_.faceInfos.push_back(faceAttributesDetectInfoObject);
  83. }
  84. if(!value["Success"].isNull())
  85. success_ = value["Success"].asString() == "true";
  86. if(!value["Code"].isNull())
  87. code_ = value["Code"].asString();
  88. if(!value["Message"].isNull())
  89. message_ = value["Message"].asString();
  90. }
  91. std::string DetectFaceAttributesResult::getMessage()const
  92. {
  93. return message_;
  94. }
  95. DetectFaceAttributesResult::Data DetectFaceAttributesResult::getData()const
  96. {
  97. return data_;
  98. }
  99. std::string DetectFaceAttributesResult::getCode()const
  100. {
  101. return code_;
  102. }
  103. bool DetectFaceAttributesResult::getSuccess()const
  104. {
  105. return success_;
  106. }