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 17 #include <alibabacloud/ocr/model/RecognizeCharacterResult.h> 18 #include <json/json.h> 19 20 using namespace AlibabaCloud::Ocr; 21 using namespace AlibabaCloud::Ocr::Model; 22 RecognizeCharacterResult()23RecognizeCharacterResult::RecognizeCharacterResult() : 24 ServiceResult() 25 {} 26 RecognizeCharacterResult(const std::string & payload)27RecognizeCharacterResult::RecognizeCharacterResult(const std::string &payload) : 28 ServiceResult() 29 { 30 parse(payload); 31 } 32 ~RecognizeCharacterResult()33RecognizeCharacterResult::~RecognizeCharacterResult() 34 {} 35 parse(const std::string & payload)36void RecognizeCharacterResult::parse(const std::string &payload) 37 { 38 Json::Reader reader; 39 Json::Value value; 40 reader.parse(payload, value); 41 setRequestId(value["RequestId"].asString()); 42 auto dataNode = value["Data"]; 43 auto allResultsNode = dataNode["Results"]; 44 for (auto dataNodeResultsResult : allResultsNode) 45 { 46 Data::Result resultObject; 47 if(!dataNodeResultsResult["Probability"].isNull()) 48 resultObject.probability = std::stof(dataNodeResultsResult["Probability"].asString()); 49 if(!dataNodeResultsResult["Text"].isNull()) 50 resultObject.text = dataNodeResultsResult["Text"].asString(); 51 auto textRectanglesNode = dataNodeResultsResult["TextRectangles"]; 52 if(!textRectanglesNode["Angle"].isNull()) 53 resultObject.textRectangles.angle = std::stoi(textRectanglesNode["Angle"].asString()); 54 if(!textRectanglesNode["Left"].isNull()) 55 resultObject.textRectangles.left = std::stoi(textRectanglesNode["Left"].asString()); 56 if(!textRectanglesNode["Top"].isNull()) 57 resultObject.textRectangles.top = std::stoi(textRectanglesNode["Top"].asString()); 58 if(!textRectanglesNode["Width"].isNull()) 59 resultObject.textRectangles.width = std::stoi(textRectanglesNode["Width"].asString()); 60 if(!textRectanglesNode["Height"].isNull()) 61 resultObject.textRectangles.height = std::stoi(textRectanglesNode["Height"].asString()); 62 data_.results.push_back(resultObject); 63 } 64 65 } 66 getData() const67RecognizeCharacterResult::Data RecognizeCharacterResult::getData()const 68 { 69 return data_; 70 } 71 72