#pragma once #include "ONNXOCRTypes.h" #include "ONNXEngine.h" #include #include #include namespace ANSCENTER { namespace onnxocr { class ONNXOCRRecognizer : public BasicOrtHandler { public: explicit ONNXOCRRecognizer(const std::string& onnx_path, unsigned int num_threads = 1); ~ONNXOCRRecognizer() override = default; // Load character dictionary (must be called before Recognize) bool LoadDictionary(const std::string& dictPath); // Recognize text from a single cropped text image TextLine Recognize(const cv::Mat& croppedImage); // Batch recognition for multiple cropped images std::vector RecognizeBatch(const std::vector& croppedImages); private: Ort::Value transform(const cv::Mat& mat) override; Ort::Value transformBatch(const std::vector& images) override; // CTC greedy decode TextLine CTCDecode(const float* outputData, int seqLen, int numClasses); std::vector keys_; int imgH_ = kRecImgH; int imgMaxW_ = kRecImgMaxW; std::mutex _mutex; }; } // namespace onnxocr } // namespace ANSCENTER