DetectFaceAttributesResult.cc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 allFaceInfosNode = dataNode["FaceInfos"]["FaceAttributesDetectInfo"];
  42. for (auto dataNodeFaceInfosFaceAttributesDetectInfo : allFaceInfosNode)
  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["Facequal"].isNull())
  64. faceAttributesDetectInfoObject.faceAttributes.facequal = std::stof(faceAttributesNode["Facequal"].asString());
  65. if(!faceAttributesNode["Integrity"].isNull())
  66. faceAttributesDetectInfoObject.faceAttributes.integrity = std::stoi(faceAttributesNode["Integrity"].asString());
  67. if(!faceAttributesNode["Respirator"].isNull())
  68. faceAttributesDetectInfoObject.faceAttributes.respirator = faceAttributesNode["Respirator"].asString();
  69. if(!faceAttributesNode["AppearanceScore"].isNull())
  70. faceAttributesDetectInfoObject.faceAttributes.appearanceScore = std::stof(faceAttributesNode["AppearanceScore"].asString());
  71. auto genderNode = faceAttributesNode["Gender"];
  72. if(!genderNode["Score"].isNull())
  73. faceAttributesDetectInfoObject.faceAttributes.gender.score = std::stof(genderNode["Score"].asString());
  74. if(!genderNode["Value"].isNull())
  75. faceAttributesDetectInfoObject.faceAttributes.gender.value = genderNode["Value"].asString();
  76. auto smilingNode = faceAttributesNode["Smiling"];
  77. if(!smilingNode["Value"].isNull())
  78. faceAttributesDetectInfoObject.faceAttributes.smiling.value = std::stof(smilingNode["Value"].asString());
  79. if(!smilingNode["Threshold"].isNull())
  80. faceAttributesDetectInfoObject.faceAttributes.smiling.threshold = std::stof(smilingNode["Threshold"].asString());
  81. auto headposeNode = faceAttributesNode["Headpose"];
  82. if(!headposeNode["PitchAngle"].isNull())
  83. faceAttributesDetectInfoObject.faceAttributes.headpose.pitchAngle = std::stof(headposeNode["PitchAngle"].asString());
  84. if(!headposeNode["RollAngle"].isNull())
  85. faceAttributesDetectInfoObject.faceAttributes.headpose.rollAngle = std::stof(headposeNode["RollAngle"].asString());
  86. if(!headposeNode["YawAngle"].isNull())
  87. faceAttributesDetectInfoObject.faceAttributes.headpose.yawAngle = std::stof(headposeNode["YawAngle"].asString());
  88. data_.faceInfos.push_back(faceAttributesDetectInfoObject);
  89. }
  90. if(!value["Success"].isNull())
  91. success_ = value["Success"].asString() == "true";
  92. if(!value["Code"].isNull())
  93. code_ = value["Code"].asString();
  94. if(!value["Message"].isNull())
  95. message_ = value["Message"].asString();
  96. }
  97. std::string DetectFaceAttributesResult::getMessage()const
  98. {
  99. return message_;
  100. }
  101. DetectFaceAttributesResult::Data DetectFaceAttributesResult::getData()const
  102. {
  103. return data_;
  104. }
  105. std::string DetectFaceAttributesResult::getCode()const
  106. {
  107. return code_;
  108. }
  109. bool DetectFaceAttributesResult::getSuccess()const
  110. {
  111. return success_;
  112. }