CompareImageFacesResult.cc 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/imm/model/CompareImageFacesResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Imm;
  19. using namespace AlibabaCloud::Imm::Model;
  20. CompareImageFacesResult::CompareImageFacesResult() :
  21. ServiceResult()
  22. {}
  23. CompareImageFacesResult::CompareImageFacesResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. CompareImageFacesResult::~CompareImageFacesResult()
  29. {}
  30. void CompareImageFacesResult::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 faceANode = value["FaceA"];
  37. if(!faceANode["FaceId"].isNull())
  38. faceA_.faceId = faceANode["FaceId"].asString();
  39. auto faceAttributesNode = faceANode["FaceAttributes"];
  40. auto faceBoundaryNode = faceAttributesNode["FaceBoundary"];
  41. if(!faceBoundaryNode["Left"].isNull())
  42. faceA_.faceAttributes.faceBoundary.left = std::stoi(faceBoundaryNode["Left"].asString());
  43. if(!faceBoundaryNode["Top"].isNull())
  44. faceA_.faceAttributes.faceBoundary.top = std::stoi(faceBoundaryNode["Top"].asString());
  45. if(!faceBoundaryNode["Width"].isNull())
  46. faceA_.faceAttributes.faceBoundary.width = std::stoi(faceBoundaryNode["Width"].asString());
  47. if(!faceBoundaryNode["Height"].isNull())
  48. faceA_.faceAttributes.faceBoundary.height = std::stoi(faceBoundaryNode["Height"].asString());
  49. auto faceBNode = value["FaceB"];
  50. if(!faceBNode["FaceId"].isNull())
  51. faceB_.faceId = faceBNode["FaceId"].asString();
  52. auto faceAttributes1Node = faceBNode["FaceAttributes"];
  53. auto faceBoundary2Node = faceAttributes1Node["FaceBoundary"];
  54. if(!faceBoundary2Node["Left"].isNull())
  55. faceB_.faceAttributes1.faceBoundary2.left = std::stoi(faceBoundary2Node["Left"].asString());
  56. if(!faceBoundary2Node["Top"].isNull())
  57. faceB_.faceAttributes1.faceBoundary2.top = std::stoi(faceBoundary2Node["Top"].asString());
  58. if(!faceBoundary2Node["Width"].isNull())
  59. faceB_.faceAttributes1.faceBoundary2.width = std::stoi(faceBoundary2Node["Width"].asString());
  60. if(!faceBoundary2Node["Height"].isNull())
  61. faceB_.faceAttributes1.faceBoundary2.height = std::stoi(faceBoundary2Node["Height"].asString());
  62. if(!value["SetId"].isNull())
  63. setId_ = value["SetId"].asString();
  64. if(!value["Similarity"].isNull())
  65. similarity_ = std::stof(value["Similarity"].asString());
  66. }
  67. float CompareImageFacesResult::getSimilarity()const
  68. {
  69. return similarity_;
  70. }
  71. CompareImageFacesResult::FaceA CompareImageFacesResult::getFaceA()const
  72. {
  73. return faceA_;
  74. }
  75. std::string CompareImageFacesResult::getSetId()const
  76. {
  77. return setId_;
  78. }
  79. CompareImageFacesResult::FaceB CompareImageFacesResult::getFaceB()const
  80. {
  81. return faceB_;
  82. }