// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <include/ocr_cls.h>
#include <include/ocr_det.h>
#include <include/ocr_rec.h>

namespace PaddleOCR {

	class PPOCR {
	public:
		explicit PPOCR();
		~PPOCR();

		std::vector<OCRPredictResult> ocr(const cv::Mat& img);
		bool  Initialize(std::string detectionModelDir, std::string classifierModelDir, std::string recognizerModelDir, std::string labelDir);
		void  SetParameters(std::string limit_type,
			std::string det_db_score_mode,
			bool is_scale,
			double det_db_thresh,
			double det_db_box_thresh,
			double det_db_unclip_ratio,
			bool use_dilation,
			int cls_batch_num,
			double cls_thresh,
			int rec_batch_num);
		void  GetParameters(std::string& limit_type,
			std::string& det_db_score_mode,
			bool& is_scale,
			double& det_db_thresh,
			double& det_db_box_thresh,
			double& det_db_unclip_ratio,
			bool& use_dilation,
			int& cls_batch_num,
			double& cls_thresh,
			int& rec_batch_num);
	protected:
		std::unique_ptr<Detector> detector_ = nullptr;
		std::unique_ptr<Classifier> classifier_ = nullptr;
		std::unique_ptr<Recognizer> recognizer_ = nullptr;
		std::recursive_mutex	_mutex;

		std::string _limit_type;
		std::string _det_db_score_mode;
		bool _is_scale;
		double _det_db_thresh;
		double _det_db_box_thresh;
		double _det_db_unclip_ratio;
		bool _use_dilation;
		int _cls_batch_num;
		double _cls_thresh;
		int _rec_batch_num;
	};

} // namespace PaddleOCR
