You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.4 KiB
C++

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#pragma once
#include <vector>
#include "OCRToolBox.h"
#include <opencv2/opencv.hpp>
#include <onnxruntime_cxx_api.h>
namespace uns
{
class EasyOCR_Detector
{
private:
const float lowText = 0.4f;
const float textThreshold = 0.7f;
const float linkThreshold = 0.4f;
private:
const OrtApi* ort;
Ort::Env ort_env;
Ort::Session* ort_cpu_session;
Ort::SessionOptions ort_session_options;
bool ort_inited;
std::wstring model_path;
IONames input_names, output_names;
IONamesStorage input_ns, output_ns;
private:
cv::Mat NormalizeMeanVariance(const cv::Mat& in);
void AdjustResultCoordinates(EOCRD_Rects& polys, float ratioW, float ratioH, float ratioNet = 2.0f);
void ResizeAspectRatio(const cv::Mat& src, cv::Mat& dst, float squareSize, float magRatio, float& ratio, cv::Size& heatmapSize);
bool GetDetBoxesCore(const cv::Mat& textmap, const cv::Mat& linkmap, float textThresh, float linkThresh, float lowText, EOCRD_Rects& boxes, cv::Mat& labels, std::vector<int>& mapper, bool estimateNumChars);
public:
EasyOCR_Detector();
EasyOCR_Detector(const EasyOCR_Detector&) = delete;
public:
bool Init();
bool UnInit();
bool RecheckModelInfo();
/// <summary>
/// EasyOCR 文本检测函数
/// </summary>
/// <param name="image">待检测的图像三通道BGR图像</param>
/// <returns>检测到的矩形框</returns>
EOCRD_Rects operator()(const cv::Mat& image);
};
}