首页

C#识别图片文字(tesseract OCR )

c#

2020-12-8

利用谷歌开源tesseract的dll组件,在VS平台上,用C#语言实现对图片中字符的识别,在图片较规整的情况下,可识别字母数字。

【注意事项】

关于软件的使用win7及一下的电脑上运行需要安装.net framework4.0,另外该程序对只包含文本,且文本清晰的图片识别率较高,另外随着文字的增多识别的成功率会下降。

 

该软件采用的是Tesseract及其配套的训练库来实现图片中的文字识别(包括中文)

如果读者要自己创建同样识别程序需要注意的地方有以下几点:

1、 需要文件有:Tesseract.dllchi_sim.traineddata这两个文件在该项目目录下均可以找到。

2、 项目目标处理器必须设置为x86,不然运行不通过

3、 使用时,将Tesseract.dll添加项目引用中。如果准备使用.net4.0框架主要修改app.config文件中的app.config一致。如果不想修改app.config,请将项目.net框架降低3.5版本,否则编译时出错。

4、 主要识别过程如下

Bitmap bmp = new Bitmap(textBox_Path.Text);

TesseractProcessor process = new TesseractProcessor();

process.SetPageSegMode(ePageSegMode.PSM_SINGLE_LINE);

process.Init(System.Environment.CurrentDirectory “\\”,”chi_sim”, (int)eOcrEngineMode.OEM_DEFAULT);

string result = process.Recognize(bmp);

MessageBox.Show(“识别结果为:” result);

其中process.Init函数的第一个参数为chi_sim.traineddata的路径,本项目中为软件运行目录下(记着把文件放在指定目录下,不然运行会出错的),记得最后还有反斜杠第二个参数为训练名不带扩展名的。第三个参数不用管,原封抄下就可以了。

5、 另外注意文件chi_sim.traineddata是训练库文件,如果觉得识别率不高可以自己再网上找Tesseract的训练库,替换该文件

资源下载此资源下载价格为2D币(VIP免费),请先
资源文件列表
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓.sln , 926
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓.v11.suo , 53248
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/app.config , 250
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/chi_sim.traineddata , 41427474
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/tesseract.dll , 2745856
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/╩╢▒≡║║╫╓.exe , 10240
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/╩╢▒≡║║╫╓.exe.config , 250
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/╩╢▒≡║║╫╓.pdb , 22016
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/╩╢▒≡║║╫╓.vshost.exe , 22984
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/╩╢▒≡║║╫╓.vshost.exe.config , 250
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Debug/╩╢▒≡║║╫╓.vshost.exe.manifest , 490
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/chi_sim.traineddata , 41427474
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/tesseract.dll , 2745856
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/╩╢▒≡║║╫╓.exe , 10240
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/╩╢▒≡║║╫╓.exe.config , 250
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/╩╢▒≡║║╫╓.pdb , 24064
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/╩╢▒≡║║╫╓.vshost.exe , 22984
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/╩╢▒≡║║╫╓.vshost.exe.config , 250
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/bin/Release/╩╢▒≡║║╫╓.vshost.exe.manifest , 490
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Form1.cs , 1379
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Form1.Designer.cs , 5081
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Form1.resx , 5817
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/DesignTimeResolveAssemblyReferences.cache , 1673
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 7100
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/TempPE/Properties.Resources.Designer.cs.dll , 4608
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╬─╫╓╩╢▒≡.csproj.FileListAbsolute.txt , 1823
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╬─╫╓╩╢▒≡.csproj.GenerateResource.Cache , 975
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╬─╫╓╩╢▒≡.csprojResolveAssemblyReference.cache , 7320
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.csproj.FileListAbsolute.txt , 782
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.csproj.GenerateResource.Cache , 975
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.csprojResolveAssemblyReference.cache , 8712
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.exe , 10240
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.Form1.resources , 180
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.pdb , 22016
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Debug/╩╢▒≡║║╫╓.Properties.Resources.resources , 180
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/DesignTimeResolveAssemblyReferencesInput.cache , 7105
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/TempPE/Properties.Resources.Designer.cs.dll , 4608
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╬─╫╓╩╢▒≡.csproj.FileListAbsolute.txt , 2181
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╬─╫╓╩╢▒≡.csproj.GenerateResource.Cache , 975
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╬─╫╓╩╢▒≡.csprojResolveAssemblyReference.cache , 10706
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╩╢▒≡║║╫╓.exe , 10240
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╩╢▒≡║║╫╓.Form1.resources , 180
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╩╢▒≡║║╫╓.pdb , 24064
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/obj/Release/╩╢▒≡║║╫╓.Properties.Resources.resources , 180
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Program.cs , 493
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Properties/AssemblyInfo.cs , 1364
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Properties/Resources.Designer.cs , 2864
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Properties/Resources.resx , 5612
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Properties/Settings.Designer.cs , 1112
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/Properties/Settings.settings , 249
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/tesseract.dll , 2745856
═╝╞¼╬─╫╓╩╢▒≡/╬─╫╓╩╢▒≡/╩╢▒≡║║╫╓/╬─╫╓╩╢▒≡.csproj , 3934
═╝╞¼╬─╫╓╩╢▒≡/╦╡├≈.doc , 26112
没有账号? 忘记密码?

社交账号快速登录