一款免费且离线的.NET使用的OCR,爱你又恨你!恨你来的太晚了。

PaddleOCRSharp

本项目是一个基于百度飞桨的PaddleOCR的C++代码修改并封装的.NET的类库。包含文本识别、文本检测、基于文本检测结果的统计分析的表格识别功能,同时针对小图识别不准的情况下,做了优化,提高识别准确率。项目封装极其简化,实际调用仅一行代码,极大的方便了中下游开发者的使用和降低了PaddleOCR的使用入门级别,同时提供不同的.NET框架使用,方便各个行业应用开发与部署。

其中PaddleOCR.dll文件是基于开源项目PaddleOCR的C++代码修改而成的C++动态库,基于opencv的x64编译而成的。

模型库支持轻量版(本项目)、服务器版模型库(更准确),可以自行更改模型库适用实际需求。

关于源码编译,建议采用vs2019及以上版本编译,如果遇到无法编译,请切换成release后再切换回debug即可。

本项目包含文本识别、文本检测、基于文本检测结果的统计分析的表格识别功能,同时针对小图识别不准的情况下,做了优化,提高识别准确率。项目封装极其简化,实际调用仅几行代码,极大的方便了中下游开发者的使用和降低了PaddleOCR的使用入门级别,同时提供不同的.NET框架使用,支持框架如下:

net40;net461;netstandard2.0;netcoreapp3.1;net5.0;

方便各个行业应用开发与部署。

C++示例代码

#include <iostream>
#include <Windows.h>
#include <tchar.h>
#include "string"
#include <include/Parameter.h>
#include <string.h>
using namespace std;
#pragma comment (lib,"PaddleOCR.lib")
extern "C" {
/// <summary>
/// PaddleOCREngine引擎初始化
/// </summary>
/// <param name="det_infer"></param>
/// <param name="cls_infer"></param>
/// <param name="rec_infer"></param>
/// <param name="keys"></param>
/// <param name="parameter"></param>
/// <returns></returns>
__declspec(dllimport) int* Initialize(char* det_infer, char* cls_infer, char* rec_infer, char* keys, OCRParameter parameter);
/// <summary>
/// 文本检测
/// </summary>
/// <param name="engine"></param>
/// <param name="imagefile"></param>
/// <param name="pOCRResult">返回结果</param>
/// <returns></returns>
__declspec(dllimport) int Detect(int* engine, char* imagefile, LpOCRResult* pOCRResult);
/// <summary>
/// 释放引擎对象
/// </summary>
/// <param name="engine"></param>
__declspec(dllimport) void FreeEngine(int* engine);
/// <summary>
/// 释放文本识别结果对象
/// </summary>
/// <param name="pOCRResult"></param>
__declspec(dllimport) void FreeDetectResult(LpOCRResult pOCRResult);
}; std::wstring string2wstring(const std::string& s)
{
int len;
int slength = (int)s.length() + 1;
len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, 0, 0);
wchar_t* buf = new wchar_t[len];
MultiByteToWideChar(CP_ACP, 0, s.c_str(), slength, buf, len);
std::wstring r(buf);
delete[] buf;
return r;
} int main()
{
LpOCRResult lpocrreult;
OCRParameter parameter;
/*parameter.enable_mkldnn = false;*/
char path[MAX_PATH]; GetCurrentDirectoryA(MAX_PATH, path); string cls_infer(path);
cls_infer += "\\inference\\ch_ppocr_mobile_v2.0_cls_infer";
string rec_infer(path);
rec_infer += "\\inference\\ch_PP-OCRv2_rec_infer";
string det_infer(path);
det_infer += "\\inference\\ch_PP-OCRv2_det_infer";
string ocrkeys(path);
ocrkeys += "\\inference\\ppocr_keys.txt";
string imagefile(path);
imagefile += "\\test.jpg"; int* pEngine = Initialize(const_cast<char*>(det_infer.c_str()),
const_cast<char*>(cls_infer.c_str()),
const_cast<char*>(rec_infer.c_str()),
const_cast<char*>(ocrkeys.c_str()),
parameter); int cout = Detect(pEngine, const_cast<char*>(imagefile.c_str()), &lpocrreult);
std::wcout.imbue(std::locale("chs"));
for (size_t i = 0; i < cout; i++)
{
wstring ss = (WCHAR*)(lpocrreult->pOCRText[i].ptext);
std::wcout << ss;
}
FreeDetectResult(lpocrreult);
FreeEngine(pEngine);
std::cin.get();
}

.NET示例代码

OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
if (ofd.ShowDialog() != DialogResult.OK) return;
var imagebyte = File.ReadAllBytes(ofd.FileName);
Bitmap bitmap = new Bitmap(new MemoryStream(imagebyte)); OCRModelConfig config = null;
OCRParameter oCRParameter = null;
OCRResult ocrResult = new OCRResult();
using (PaddleOCREngine engine = new PaddleOCREngine(config, oCRParameter))
{
ocrResult = engine.DetectText(bmp);
}
if (ocrResult != null)
{
MessageBox.Show(ocrResult.Text,"识别结果");
}

微信公众号

PaddleOCRSharp项目地址: 
码云:https://gitee.com/raoyutian/paddle-ocrsharp
github:https://github.com/raoyutian/PaddleOCRSharp

QQ群:318860399

最新文章

  1. python之信用卡ATM(第五天)
  2. easyui datagrid中关联combox
  3. hdwiki中插件开发指南
  4. kettle 数据库连接中断重置
  5. TFS上使用Beyond Compare来比较源码
  6. MySQL高可用性大杀器之MHA | 火丁笔记
  7. Web文件管理:elFinder.Net(支持FTP)
  8. hadoop SQL使用
  9. IOC原理分析
  10. 使用Eclipse/MyEclipse开发Java程序
  11. WPF 圖表控件 MetroChart
  12. 【1】hadoop搭建常用的Linux命令收集
  13. Redis入门简述
  14. 黑洞有毛 or 黑洞无毛:4星|《环球科学》2019年03月号
  15. C++ 容器操作
  16. vue中$set的用法
  17. C#排队处理DEMO
  18. C#提高-------------------Assembly和Module的使用-------反射内涵
  19. ubuntu 16.04使用软件中心升级软件后桌面显示空白
  20. SpringMVC -- 梗概--源码--贰--mvc:annotation-driven

热门文章

  1. 转:Intent 操作常用URI代码示例
  2. pf4j及pf4j-spring
  3. GDAL重投影重采样像元配准对齐
  4. CF41C Email address 题解
  5. CF1438A Specific Tastes of Andre 题解
  6. Django的Form表单验证
  7. C++ 智能指针(shared_ptr/weak_ptr)原理分析
  8. 【九度OJ】题目1185:特殊排序 解题报告
  9. 【LeetCode】437. Path Sum III 解题报告(Python)
  10. 【LeetCode】456. 132 Pattern 解题报告(Python)