添加项目文件。
parent
f04e32f737
commit
78be0daf80
@ -0,0 +1,195 @@
|
||||
/* Copyright (C) 2011 阙荣文
|
||||
*
|
||||
* 这是一个开源免费软件,您可以自由的修改和发布.
|
||||
* 禁止用作商业用途.
|
||||
*
|
||||
* 联系原作者: querw@sina.com
|
||||
*/
|
||||
|
||||
// ATW.h: interface for the CBase64 class.
|
||||
// by Ted.Que - Que's C++ Studio
|
||||
// 2010-11-12
|
||||
// 转换字符编码
|
||||
#include "ATW.h"
|
||||
|
||||
|
||||
std::string __do_w_to_a_utf8(const wchar_t* pwszText, UINT uCodePage)
|
||||
{
|
||||
// 空指针输入
|
||||
if (pwszText == NULL) return "";
|
||||
|
||||
// 无法计算需要的长度.
|
||||
int nNeedSize = WideCharToMultiByte(uCodePage, 0, pwszText, -1, NULL, 0, NULL, NULL);
|
||||
if (0 == nNeedSize) return "";
|
||||
|
||||
// 分配空间,转换.
|
||||
char* pRet = new char[nNeedSize + 1]; // 虽然返回WideCharToMultiByte的长度是包含 null 字符的长度, 还是多+一个字符.
|
||||
memset(pRet, 0, nNeedSize + 1);
|
||||
|
||||
std::string strRet("");
|
||||
if (0 == WideCharToMultiByte(uCodePage, 0, pwszText, -1, pRet, nNeedSize, NULL, NULL))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
strRet = pRet;
|
||||
}
|
||||
|
||||
delete[]pRet;
|
||||
return strRet;
|
||||
}
|
||||
|
||||
std::wstring __do_a_utf8_to_w(const char* pszText, UINT uCodePage)
|
||||
{
|
||||
// 空指针
|
||||
if (pszText == NULL) return L"";
|
||||
|
||||
// 计算长度
|
||||
int nNeedSize = MultiByteToWideChar(uCodePage, 0, pszText, -1, NULL, 0);
|
||||
if (0 == nNeedSize) return L"";
|
||||
|
||||
// 分配空间,转换
|
||||
std::wstring strRet(L"");
|
||||
wchar_t* pRet = new wchar_t[nNeedSize + 1];
|
||||
memset(pRet, 0, (nNeedSize + 1) * sizeof(wchar_t));
|
||||
if (0 == MultiByteToWideChar(uCodePage, 0, pszText, -1, pRet, nNeedSize))
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
strRet = pRet;
|
||||
}
|
||||
delete[]pRet;
|
||||
return strRet;
|
||||
}
|
||||
|
||||
std::string WtoA(const std::wstring& strText)
|
||||
{
|
||||
return __do_w_to_a_utf8(strText.c_str(), CP_ACP);
|
||||
}
|
||||
|
||||
std::string WtoA(const wchar_t* pwszText)
|
||||
{
|
||||
return __do_w_to_a_utf8(pwszText, CP_ACP);
|
||||
}
|
||||
|
||||
std::wstring AtoW(const std::string& strText)
|
||||
{
|
||||
return __do_a_utf8_to_w(strText.c_str(), CP_ACP);
|
||||
}
|
||||
|
||||
std::wstring AtoW(const char* pszText)
|
||||
{
|
||||
return __do_a_utf8_to_w(pszText, CP_ACP);
|
||||
}
|
||||
|
||||
std::string WtoUTF8(const std::wstring& strText)
|
||||
{
|
||||
return __do_w_to_a_utf8(strText.c_str(), CP_UTF8);
|
||||
}
|
||||
|
||||
std::string WtoUTF8(const wchar_t* pwszText)
|
||||
{
|
||||
return __do_w_to_a_utf8(pwszText, CP_UTF8);
|
||||
}
|
||||
|
||||
std::wstring UTF8toW(const std::string& strText)
|
||||
{
|
||||
return __do_a_utf8_to_w(strText.c_str(), CP_UTF8);
|
||||
}
|
||||
|
||||
std::wstring UTF8toW(const char* pszText)
|
||||
{
|
||||
return __do_a_utf8_to_w(pszText, CP_UTF8);
|
||||
}
|
||||
|
||||
std::string UTF8toA(const std::string& src)
|
||||
{
|
||||
return WtoA(UTF8toW(src));
|
||||
}
|
||||
|
||||
std::string UTF8toA(const char* src)
|
||||
{
|
||||
return WtoA(UTF8toW(src));
|
||||
}
|
||||
|
||||
std::string AtoUTF8(const std::string& src)
|
||||
{
|
||||
return WtoUTF8(AtoW(src));
|
||||
}
|
||||
|
||||
std::string AtoUTF8(const char* src)
|
||||
{
|
||||
return WtoUTF8(AtoW(src));
|
||||
}
|
||||
/*
|
||||
UTF-8 编码最多可以有6个字节
|
||||
|
||||
1字节 0xxxxxxx
|
||||
2字节 110xxxxx 10xxxxxx
|
||||
3字节 1110xxxx 10xxxxxx 10xxxxxx
|
||||
4字节 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
5字节 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
6字节 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
|
||||
|
||||
*/
|
||||
|
||||
// 返回值说明:
|
||||
// 0 -> 输入字符串符合UTF-8编码规则
|
||||
// -1 -> 检测到非法的UTF-8编码首字节
|
||||
// -2 -> 检测到非法的UTF-8字节编码的后续字节.
|
||||
|
||||
int IsTextUTF8(const char* pszSrc)
|
||||
{
|
||||
const unsigned char* puszSrc = (const unsigned char*)pszSrc; // 一定要无符号的,有符号的比较就不正确了.
|
||||
// 看看有没有BOM表示 EF BB BF
|
||||
if (puszSrc[0] != 0 && puszSrc[0] == 0xEF &&
|
||||
puszSrc[1] != 0 && puszSrc[1] == 0xBB &&
|
||||
puszSrc[2] != 0 && puszSrc[2] == 0xBF)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 如果没有 BOM标识
|
||||
bool bIsNextByte = false;
|
||||
int nBytes = 0; // 记录一个字符的UTF8编码已经占用了几个字节.
|
||||
const unsigned char* pCur = (const unsigned char*)pszSrc; // 指针游标用无符号字符型. 因为高位为1, 如果用 char 型, 会变为负数,不利于编程时候的比较操作.
|
||||
|
||||
while (pCur[0] != 0)
|
||||
{
|
||||
if (!bIsNextByte)
|
||||
{
|
||||
bIsNextByte = true;
|
||||
if ((pCur[0] >> 7) == 0) { bIsNextByte = false; nBytes = 1; bIsNextByte = false; } // 最高位为0, ANSI 兼容的.
|
||||
else if ((pCur[0] >> 5) == 0x06) { nBytes = 2; } // 右移5位后是 110 -> 2字节编码的UTF8字符的首字节
|
||||
else if ((pCur[0] >> 4) == 0x0E) { nBytes = 3; } // 右移4位后是 1110 -> 3字节编码的UTF8字符的首字节
|
||||
else if ((pCur[0] >> 3) == 0x1E) { nBytes = 4; } // 右移3位后是 11110 -> 4字节编码的UTF8字符的首字节
|
||||
else if ((pCur[0] >> 2) == 0x3E) { nBytes = 5; } // 右移2位后是 111110 -> 5字节编码的UTF8字符的首字节
|
||||
else if ((pCur[0] >> 1) == 0x7E) { nBytes = 6; } // 右移1位后是 1111110 -> 6字节编码的UTF8字符的首字节
|
||||
else
|
||||
{
|
||||
nBytes = -1; // 非法的UTF8字符编码的首字节
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((pCur[0] >> 6) == 0x02) // 首先,后续字节必须以 10xxx 开头
|
||||
{
|
||||
nBytes--;
|
||||
if (nBytes == 1) bIsNextByte = false; // 当 nBytes = 1时, 说明下一个字节应该是首字节.
|
||||
}
|
||||
else
|
||||
{
|
||||
nBytes = -2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 下跳一个字符
|
||||
pCur++;
|
||||
}
|
||||
|
||||
if (nBytes == 1) return 0;
|
||||
else return nBytes;
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2011 阙荣文
|
||||
*
|
||||
* 这是一个开源免费软件,您可以自由的修改和发布.
|
||||
* 禁止用作商业用途.
|
||||
*
|
||||
* 联系原作者: querw@sina.com
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
1. 实现USC的压缩,Unicode <-> UTF-8.
|
||||
2. 实现多字节码 <-> Unicode
|
||||
|
||||
对于Unicode字符串,用 wstring 存储.
|
||||
对于非Unicode字符串用 string 存储. ANSI, GB2312 都一样
|
||||
对于UTF-8串,也用 string 存储, UTF-8的编码串中不会有null出现.
|
||||
*/
|
||||
|
||||
/*
|
||||
不要使用ATL 中的 USES_CONVERSION; A2W, A2T, W2A 等的宏, 由于这些宏都调用 alloca() 函数在函数栈中分配内存.
|
||||
虽然非常方便,函数返回后自动回收, 但是有溢出的危险, 函数栈只有 1M 的大小.
|
||||
|
||||
以下的函数使用的空间都是在堆中分配的,比较安全.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#if defined(_WIN32) || defined(WIN32)
|
||||
#include "Windows.h"
|
||||
#endif
|
||||
|
||||
#if defined(_UNICODE) || defined(UNICODE)
|
||||
#define TtoA WtoA
|
||||
#define AtoT AtoW
|
||||
#define WtoT(a) (a)
|
||||
#define TtoW(a) (a)
|
||||
typedef std::wstring _tstring;
|
||||
#else
|
||||
#define TtoA(a) (a)
|
||||
#define AtoT(a) (a)
|
||||
#define WtoT WtoA
|
||||
#define TtoW AtoW
|
||||
typedef std::string _tstring;
|
||||
#endif
|
||||
|
||||
std::string WtoA(const wchar_t* pwszSrc);
|
||||
std::string WtoA(const std::wstring &strSrc);
|
||||
|
||||
std::wstring AtoW(const char* pszSrc);
|
||||
std::wstring AtoW(const std::string &strSrc);
|
||||
|
||||
std::string WtoUTF8(const wchar_t* pwszSrc);
|
||||
std::string WtoUTF8(const std::wstring &strSrc);
|
||||
|
||||
std::wstring UTF8toW(const char* pszSrc);
|
||||
std::wstring UTF8toW(const std::string &strSr);
|
||||
|
||||
std::string AtoUTF8(const char* src);
|
||||
std::string AtoUTF8(const std::string &src);
|
||||
|
||||
std::string UTF8toA(const char* src);
|
||||
std::string UTF8toA(const std::string &src);
|
||||
|
||||
// 检测一个以 null 结尾的字符串是否是UTF-8, 如果返回0, 也只表示这个串刚好符合UTF8的编码规则.
|
||||
// 返回值说明:
|
||||
// 1 -> 输入字符串符合UTF-8编码规则
|
||||
// -1 -> 检测到非法的UTF-8编码首字节
|
||||
// -2 -> 检测到非法的UTF-8字节编码的后续字节.
|
||||
int IsTextUTF8(const char* pszSrc);
|
Binary file not shown.
@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{166232a4-c250-4aae-9d41-f22ed3fb9585}</ProjectGuid>
|
||||
<RootNamespace>EasyOCRCPP</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<IncludePath>F:\vcpkg\installed\x64-windows\include\opencv4;$(IncludePath)</IncludePath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IncludePath>F:\vcpkg\installed\x64-windows\include\opencv4;$(IncludePath)</IncludePath>
|
||||
<CopyLocalProjectReference>true</CopyLocalProjectReference>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ATW.cpp" />
|
||||
<ClCompile Include="EasyOCR-CPP.cpp" />
|
||||
<ClCompile Include="EasyOCR_Detector.cpp" />
|
||||
<ClCompile Include="EasyOCR_Recognizer.cpp" />
|
||||
<ClCompile Include="OCRCharset.cpp" />
|
||||
<ClCompile Include="OCRConfig.cpp" />
|
||||
<ClCompile Include="OCRToolBox.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ATW.h" />
|
||||
<ClInclude Include="EasyOCR_Detector.h" />
|
||||
<ClInclude Include="EasyOCR_Recognizer.h" />
|
||||
<ClInclude Include="OCRCharset.h" />
|
||||
<ClInclude Include="OCRConfig.h" />
|
||||
<ClInclude Include="OCRToolBox.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
@ -0,0 +1,60 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="EasyOCR-CPP.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ATW.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OCRCharset.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EasyOCR_Detector.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OCRConfig.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OCRToolBox.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="EasyOCR_Recognizer.cpp">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="ATW.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OCRCharset.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EasyOCR_Detector.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OCRConfig.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OCRToolBox.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="EasyOCR_Recognizer.h">
|
||||
<Filter>头文件</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace uns
|
||||
{
|
||||
class OCRCharset
|
||||
{
|
||||
private:
|
||||
static std::map<int, std::wstring> en_charmap;
|
||||
static std::map<int, std::wstring> ch_en_charmap;
|
||||
|
||||
public:
|
||||
OCRCharset() = delete;
|
||||
OCRCharset(const OCRCharset&) = delete;
|
||||
|
||||
public:
|
||||
static std::wstring GetChar(int index);
|
||||
static std::wstring GetString(const std::vector<int>& indexs);
|
||||
};
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
#include "OCRConfig.h"
|
||||
|
||||
uns::OCRConfig uns::G_OCRConfig;
|
||||
|
||||
uns::OCRConfig::OCRConfig()
|
||||
{
|
||||
language = CharsetType::EN;
|
||||
gpu_usage = GPUUsage::PreferGPU;
|
||||
}
|
||||
|
||||
uns::OCRConfig::OCRConfig(const std::wstring& detect_model, const std::wstring& reco_model, CharsetType language, GPUUsage gpu)
|
||||
{
|
||||
gpu_usage = gpu;
|
||||
this->language = language;
|
||||
detect_model_path = detect_model;
|
||||
recognize_model_path = reco_model;
|
||||
}
|
||||
|
||||
uns::OCRConfig::GPUUsage uns::OCRConfig::GetGPUUsage() const
|
||||
{
|
||||
return gpu_usage;
|
||||
}
|
||||
|
||||
uns::OCRConfig::CharsetType uns::OCRConfig::GetLanguage() const
|
||||
{
|
||||
return language;
|
||||
}
|
||||
|
||||
std::wstring uns::OCRConfig::GetDetectModelPath() const
|
||||
{
|
||||
return detect_model_path;
|
||||
}
|
||||
|
||||
std::wstring uns::OCRConfig::GetRecognizeModelPath() const
|
||||
{
|
||||
return recognize_model_path;
|
||||
}
|
||||
|
||||
void uns::OCRConfig::SetGPUUsage(GPUUsage usage)
|
||||
{
|
||||
gpu_usage = usage;
|
||||
}
|
||||
|
||||
void uns::OCRConfig::SetLanguage(CharsetType type)
|
||||
{
|
||||
language = type;
|
||||
}
|
||||
|
||||
void uns::OCRConfig::SetDetectModelPath(const std::wstring& path)
|
||||
{
|
||||
detect_model_path = path;
|
||||
}
|
||||
|
||||
void uns::OCRConfig::SetRecognizeModelPath(const std::wstring& path)
|
||||
{
|
||||
recognize_model_path = path;
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
#include "OCRToolBox.h"
|
||||
#include "OCRConfig.h"
|
||||
|
||||
bool uns::OCRToolBox::CheckFile(const std::wstring& file)
|
||||
{
|
||||
namespace fs = std::filesystem;
|
||||
try
|
||||
{
|
||||
if (file.empty())
|
||||
return false;
|
||||
if (!fs::exists(file))
|
||||
return false;
|
||||
if (!fs::is_regular_file(file))
|
||||
return false;
|
||||
auto perms = fs::status(file).permissions();
|
||||
return ((perms & fs::perms::owner_read) != fs::perms::none && (perms & fs::perms::owner_write) != fs::perms::none);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void uns::OCRToolBox::InitOrtSessionOptions(Ort::SessionOptions& se_opt)
|
||||
{
|
||||
se_opt.SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL);
|
||||
se_opt.EnableCpuMemArena(); // 启用内存池
|
||||
se_opt.EnableMemPattern(); // 启用内存模式优化
|
||||
}
|
||||
|
||||
bool uns::OCRToolBox::AutoSelectEP(const OrtApi* ort, Ort::SessionOptions& se_opt, bool& fallback_to_cpu)
|
||||
{
|
||||
fallback_to_cpu = false;
|
||||
if (G_OCRConfig.GetGPUUsage() == OCRConfig::GPUUsage::CPUOnly)
|
||||
return true;
|
||||
try
|
||||
{
|
||||
OrtStatusPtr status = OrtSessionOptionsAppendExecutionProvider_CUDA(se_opt, 0);
|
||||
if (status)
|
||||
{
|
||||
ort->ReleaseStatus(status);
|
||||
if (G_OCRConfig.GetGPUUsage() == OCRConfig::GPUUsage::ForceGPU)
|
||||
return false;
|
||||
se_opt = Ort::SessionOptions(); //Reset Session Options (Fallback to CPU)
|
||||
fallback_to_cpu = true;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return true; //GPU Enable Successful
|
||||
}
|
||||
catch (const Ort::Exception&)
|
||||
{
|
||||
se_opt = Ort::SessionOptions(); //Reset Session Options (Fallback to CPU)
|
||||
fallback_to_cpu = true;
|
||||
return true;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void uns::OCRToolBox::GetInputOutputNames(Ort::Session* ort_session, IONames& input_names, IONamesStorage& input_ns, IONames& output_names, IONamesStorage& output_ns)
|
||||
{
|
||||
input_ns.clear();
|
||||
output_ns.clear();
|
||||
input_names.clear();
|
||||
output_names.clear();
|
||||
|
||||
if (ort_session == nullptr)
|
||||
return;
|
||||
|
||||
auto input_name_alloc = ort_session->GetInputNameAllocated(0, Ort::AllocatorWithDefaultOptions());
|
||||
std::string input_name = input_name_alloc.get();
|
||||
input_ns = { input_name };
|
||||
for (auto& name : input_ns)
|
||||
input_names.push_back(name.c_str());
|
||||
|
||||
auto output_name_alloc = ort_session->GetOutputNameAllocated(0, Ort::AllocatorWithDefaultOptions());
|
||||
std::string output_name = output_name_alloc.get();
|
||||
output_ns = { output_name };
|
||||
for (auto& name : output_ns)
|
||||
output_names.push_back(name.c_str());
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <filesystem>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <onnxruntime_cxx_api.h>
|
||||
|
||||
namespace uns
|
||||
{
|
||||
using VecInt = std::vector<int>;
|
||||
using VecFloat = std::vector<float>;
|
||||
using IONames = std::vector<const char*>;
|
||||
using IONamesStorage = std::vector<std::string>;
|
||||
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 OCRToolBox
|
||||
{
|
||||
public:
|
||||
static bool CheckFile(const std::wstring& file);
|
||||
static void InitOrtSessionOptions(Ort::SessionOptions& se_opt);
|
||||
static bool AutoSelectEP(const OrtApi* ort, Ort::SessionOptions& se_opt, bool& fallback_to_cpu);
|
||||
static void GetInputOutputNames(Ort::Session* ort_session, IONames& input_names, IONamesStorage& input_ns, IONames& output_names, IONamesStorage& output_ns);
|
||||
};
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue