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.
89 lines
2.4 KiB
C++
89 lines
2.4 KiB
C++
#pragma once
|
|
#include <map>
|
|
#include <vector>
|
|
#include <string>
|
|
#include <opencv2/core/core.hpp>
|
|
|
|
#ifdef LIBEASYOCRCPP_EXPORTS
|
|
#define LIBEASYOCRCPP_API _declspec(dllexport)
|
|
#else
|
|
#define LIBEASYOCRCPP_API _declspec(dllimport)
|
|
#ifdef _DEBUG
|
|
#pragma comment(lib, "LibEasyOCR-CPPd.lib")
|
|
#else
|
|
#pragma comment(lib, "LibEasyOCR-CPP.lib")
|
|
#endif
|
|
#endif
|
|
|
|
namespace uns
|
|
{
|
|
namespace easyocr
|
|
{
|
|
enum class LIBEASYOCRCPP_API GPUUsage
|
|
{
|
|
ForceGPU,
|
|
PreferGPU,
|
|
CPUOnly
|
|
};
|
|
|
|
enum class LIBEASYOCRCPP_API CharsetType
|
|
{
|
|
EN,
|
|
EN_CH
|
|
};
|
|
|
|
using EOCR_Result = std::pair<std::wstring, float>;
|
|
using EOCR_ResultSet = std::map<size_t, EOCR_Result>;
|
|
using EOCRD_Rects = std::vector<std::vector<cv::Point2f>>;
|
|
}
|
|
|
|
class LIBEASYOCRCPP_API OCRConfig
|
|
{
|
|
public:
|
|
OCRConfig();
|
|
OCRConfig(const OCRConfig& obj) = delete;
|
|
OCRConfig(const std::wstring& detect_model, const std::wstring& reco_model, easyocr::CharsetType language, easyocr::GPUUsage gpu = easyocr::GPUUsage::PreferGPU);
|
|
|
|
public:
|
|
easyocr::GPUUsage GetGPUUsage() const;
|
|
easyocr::CharsetType GetLanguage() const;
|
|
|
|
std::wstring GetDetectModelPath() const;
|
|
std::wstring GetRecognizeModelPath() const;
|
|
|
|
public:
|
|
void SetGPUUsage(easyocr::GPUUsage usage);
|
|
void SetLanguage(easyocr::CharsetType type);
|
|
void SetDetectModelPath(const std::wstring& path);
|
|
void SetRecognizeModelPath(const std::wstring& path);
|
|
};
|
|
|
|
class LIBEASYOCRCPP_API EasyOCR_CPP
|
|
{
|
|
public:
|
|
static OCRConfig& GlobalOCRConfig();
|
|
static void SetRecognitionModel(const std::wstring& reco_model, easyocr::CharsetType language);
|
|
|
|
static bool CleanupOCR();
|
|
static bool InitDetectionModel();
|
|
static bool InitRecognitionModel();
|
|
|
|
static easyocr::EOCRD_Rects Detect(const cv::Mat& img);
|
|
static easyocr::EOCR_Result Recognize(const cv::Mat& img);
|
|
static easyocr::EOCR_ResultSet Recognize(const cv::Mat& img, const easyocr::EOCRD_Rects& rects);
|
|
|
|
static easyocr::EOCR_ResultSet FullAuto(const cv::Mat& img);
|
|
};
|
|
|
|
class LIBEASYOCRCPP_API EOCR_SupportTools
|
|
{
|
|
public:
|
|
static std::string WtoA(const std::wstring& wstr);
|
|
static std::wstring AtoW(const std::string& str);
|
|
static std::string AtoUTF8(const std::string& str);
|
|
static std::string UTF8toA(const std::string& utf8);
|
|
|
|
static cv::Mat ReadImage(const std::string& file, bool blur = false, int blur_size = 3);
|
|
static cv::Mat ReadImage(const std::wstring& file, bool blur = false, int blur_size = 3);
|
|
};
|
|
} |