RecognizeTaxiInvoiceResult.cc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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/ocr/model/RecognizeTaxiInvoiceResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ocr;
  19. using namespace AlibabaCloud::Ocr::Model;
  20. RecognizeTaxiInvoiceResult::RecognizeTaxiInvoiceResult() :
  21. ServiceResult()
  22. {}
  23. RecognizeTaxiInvoiceResult::RecognizeTaxiInvoiceResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. RecognizeTaxiInvoiceResult::~RecognizeTaxiInvoiceResult()
  29. {}
  30. void RecognizeTaxiInvoiceResult::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 allInvoicesNode = dataNode["Invoices"]["Invoice"];
  38. for (auto dataNodeInvoicesInvoice : allInvoicesNode)
  39. {
  40. Data::Invoice invoiceObject;
  41. if(!dataNodeInvoicesInvoice["RotateType"].isNull())
  42. invoiceObject.rotateType = std::stoi(dataNodeInvoicesInvoice["RotateType"].asString());
  43. auto allItemsNode = dataNodeInvoicesInvoice["Items"]["Item"];
  44. for (auto dataNodeInvoicesInvoiceItemsItem : allItemsNode)
  45. {
  46. Data::Invoice::Item itemsObject;
  47. if(!dataNodeInvoicesInvoiceItemsItem["Text"].isNull())
  48. itemsObject.text = dataNodeInvoicesInvoiceItemsItem["Text"].asString();
  49. auto itemRoiNode = value["ItemRoi"];
  50. if(!itemRoiNode["Angle"].isNull())
  51. itemsObject.itemRoi.angle = std::stof(itemRoiNode["Angle"].asString());
  52. auto centerNode = itemRoiNode["Center"];
  53. if(!centerNode["X"].isNull())
  54. itemsObject.itemRoi.center.x = std::stof(centerNode["X"].asString());
  55. if(!centerNode["Y"].isNull())
  56. itemsObject.itemRoi.center.y = std::stof(centerNode["Y"].asString());
  57. auto sizeNode = itemRoiNode["Size"];
  58. if(!sizeNode["H"].isNull())
  59. itemsObject.itemRoi.size.h = std::stof(sizeNode["H"].asString());
  60. if(!sizeNode["W"].isNull())
  61. itemsObject.itemRoi.size.w = std::stof(sizeNode["W"].asString());
  62. invoiceObject.items.push_back(itemsObject);
  63. }
  64. auto invoiceRoiNode = value["InvoiceRoi"];
  65. if(!invoiceRoiNode["H"].isNull())
  66. invoiceObject.invoiceRoi.h = std::stof(invoiceRoiNode["H"].asString());
  67. if(!invoiceRoiNode["W"].isNull())
  68. invoiceObject.invoiceRoi.w = std::stof(invoiceRoiNode["W"].asString());
  69. if(!invoiceRoiNode["X"].isNull())
  70. invoiceObject.invoiceRoi.x = std::stof(invoiceRoiNode["X"].asString());
  71. if(!invoiceRoiNode["Y"].isNull())
  72. invoiceObject.invoiceRoi.y = std::stof(invoiceRoiNode["Y"].asString());
  73. data_.invoices.push_back(invoiceObject);
  74. }
  75. }
  76. RecognizeTaxiInvoiceResult::Data RecognizeTaxiInvoiceResult::getData()const
  77. {
  78. return data_;
  79. }