SearchFaceResult.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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/SearchFaceResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Facebody;
  19. using namespace AlibabaCloud::Facebody::Model;
  20. SearchFaceResult::SearchFaceResult() :
  21. ServiceResult()
  22. {}
  23. SearchFaceResult::SearchFaceResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. SearchFaceResult::~SearchFaceResult()
  29. {}
  30. void SearchFaceResult::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 allMatchListNode = dataNode["MatchList"]["MatchListItem"];
  38. for (auto dataNodeMatchListMatchListItem : allMatchListNode)
  39. {
  40. Data::MatchListItem matchListItemObject;
  41. if(!dataNodeMatchListMatchListItem["QualitieScore"].isNull())
  42. matchListItemObject.qualitieScore = std::stof(dataNodeMatchListMatchListItem["QualitieScore"].asString());
  43. auto allFaceItemsNode = dataNodeMatchListMatchListItem["FaceItems"]["FaceItemsItem"];
  44. for (auto dataNodeMatchListMatchListItemFaceItemsFaceItemsItem : allFaceItemsNode)
  45. {
  46. Data::MatchListItem::FaceItemsItem faceItemsObject;
  47. if(!dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["EntityId"].isNull())
  48. faceItemsObject.entityId = dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["EntityId"].asString();
  49. if(!dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["FaceId"].isNull())
  50. faceItemsObject.faceId = dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["FaceId"].asString();
  51. if(!dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["Score"].isNull())
  52. faceItemsObject.score = std::stof(dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["Score"].asString());
  53. if(!dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["ExtraData"].isNull())
  54. faceItemsObject.extraData = dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["ExtraData"].asString();
  55. if(!dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["DbName"].isNull())
  56. faceItemsObject.dbName = dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["DbName"].asString();
  57. if(!dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["Confidence"].isNull())
  58. faceItemsObject.confidence = std::stof(dataNodeMatchListMatchListItemFaceItemsFaceItemsItem["Confidence"].asString());
  59. matchListItemObject.faceItems.push_back(faceItemsObject);
  60. }
  61. auto locationNode = value["Location"];
  62. if(!locationNode["Width"].isNull())
  63. matchListItemObject.location.width = std::stoi(locationNode["Width"].asString());
  64. if(!locationNode["Height"].isNull())
  65. matchListItemObject.location.height = std::stoi(locationNode["Height"].asString());
  66. if(!locationNode["Y"].isNull())
  67. matchListItemObject.location.y = std::stoi(locationNode["Y"].asString());
  68. if(!locationNode["X"].isNull())
  69. matchListItemObject.location.x = std::stoi(locationNode["X"].asString());
  70. data_.matchList.push_back(matchListItemObject);
  71. }
  72. if(!value["Code"].isNull())
  73. code_ = value["Code"].asString();
  74. if(!value["Message"].isNull())
  75. message_ = value["Message"].asString();
  76. }
  77. std::string SearchFaceResult::getMessage()const
  78. {
  79. return message_;
  80. }
  81. SearchFaceResult::Data SearchFaceResult::getData()const
  82. {
  83. return data_;
  84. }
  85. std::string SearchFaceResult::getCode()const
  86. {
  87. return code_;
  88. }