Files
ANSCORE/modules/ANSOCR/ANSONNXOCR/ONNXOCRRecognizer.h

41 lines
1.1 KiB
C++

#pragma once
#include "ONNXOCRTypes.h"
#include "ONNXEngine.h"
#include <vector>
#include <string>
#include <mutex>
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<TextLine> RecognizeBatch(const std::vector<cv::Mat>& croppedImages);
private:
Ort::Value transform(const cv::Mat& mat) override;
Ort::Value transformBatch(const std::vector<cv::Mat>& images) override;
// CTC greedy decode
TextLine CTCDecode(const float* outputData, int seqLen, int numClasses);
std::vector<std::string> keys_;
int imgH_ = kRecImgH;
int imgMaxW_ = kRecImgMaxW;
std::mutex _mutex;
};
} // namespace onnxocr
} // namespace ANSCENTER