DetectObjectResult.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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/objectdet/model/DetectObjectResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Objectdet;
  19. using namespace AlibabaCloud::Objectdet::Model;
  20. DetectObjectResult::DetectObjectResult() :
  21. ServiceResult()
  22. {}
  23. DetectObjectResult::DetectObjectResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DetectObjectResult::~DetectObjectResult()
  29. {}
  30. void DetectObjectResult::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["Height"].isNull())
  38. data_.height = std::stoi(dataNode["Height"].asString());
  39. if(!dataNode["Width"].isNull())
  40. data_.width = std::stoi(dataNode["Width"].asString());
  41. auto allElementsNode = dataNode["Elements"]["Element"];
  42. for (auto dataNodeElementsElement : allElementsNode)
  43. {
  44. Data::Element elementObject;
  45. if(!dataNodeElementsElement["Score"].isNull())
  46. elementObject.score = std::stof(dataNodeElementsElement["Score"].asString());
  47. if(!dataNodeElementsElement["Type"].isNull())
  48. elementObject.type = dataNodeElementsElement["Type"].asString();
  49. auto allBoxes = value["Boxes"]["Box"];
  50. for (auto value : allBoxes)
  51. elementObject.boxes.push_back(value.asString());
  52. data_.elements.push_back(elementObject);
  53. }
  54. }
  55. DetectObjectResult::Data DetectObjectResult::getData()const
  56. {
  57. return data_;
  58. }