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/RecognizePassportMRZResult.h>
18 #include <json/json.h>
19 
20 using namespace AlibabaCloud::Ocr;
21 using namespace AlibabaCloud::Ocr::Model;
22 
RecognizePassportMRZResult()23 RecognizePassportMRZResult::RecognizePassportMRZResult() :
24 	ServiceResult()
25 {}
26 
RecognizePassportMRZResult(const std::string & payload)27 RecognizePassportMRZResult::RecognizePassportMRZResult(const std::string &payload) :
28 	ServiceResult()
29 {
30 	parse(payload);
31 }
32 
~RecognizePassportMRZResult()33 RecognizePassportMRZResult::~RecognizePassportMRZResult()
34 {}
35 
parse(const std::string & payload)36 void RecognizePassportMRZResult::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 allRegionsNode = dataNode["Regions"]["Region"];
44 	for (auto dataNodeRegionsRegion : allRegionsNode)
45 	{
46 		Data::Region regionObject;
47 		if(!dataNodeRegionsRegion["Name"].isNull())
48 			regionObject.name = dataNodeRegionsRegion["Name"].asString();
49 		if(!dataNodeRegionsRegion["RecognitionScore"].isNull())
50 			regionObject.recognitionScore = std::stof(dataNodeRegionsRegion["RecognitionScore"].asString());
51 		if(!dataNodeRegionsRegion["Content"].isNull())
52 			regionObject.content = dataNodeRegionsRegion["Content"].asString();
53 		if(!dataNodeRegionsRegion["DetectionScore"].isNull())
54 			regionObject.detectionScore = std::stof(dataNodeRegionsRegion["DetectionScore"].asString());
55 		auto allBandBoxes = value["BandBoxes"]["BandBox"];
56 		for (auto value : allBandBoxes)
57 			regionObject.bandBoxes.push_back(value.asString());
58 		data_.regions.push_back(regionObject);
59 	}
60 
61 }
62 
getData() const63 RecognizePassportMRZResult::Data RecognizePassportMRZResult::getData()const
64 {
65 	return data_;
66 }
67 
68