C# OCR AspriseOcr测试使用图像文字中英文识别
生活随笔
收集整理的這篇文章主要介紹了
C# OCR AspriseOcr测试使用图像文字中英文识别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
OCR AspriseOcr測試使用中英文識別:因為使用AspriseOcr是需要商業授權碼的,故使用網上破解dll包進行測試,測試的結果并不理想,可能是因為版本太低所致。如果真的需要做好OCR應用建議購買其授權碼。
官網地址:http://asprise.com/
應用場景
- 圖像掃描:對圖片進行文字識別
- 文件掃描:對PDF文件進行文字識別
- 條碼掃描:對二維碼條碼進行掃描識別
測試示例
注意:需要下載的DLL分別是AspriseOCR.dll、DevIL.dll、ILU.dll將其放在生成的bin/Debug生成目錄下,然后就可以測試了,網上有人說需要.net 2.0這個是謬傳,我用的是.net framwork 4.5 ,DLL包不用放在注冊表里去,放在可執行目錄即可,程序運行時會自動加載,因為使用的是DllImport方式導入。
定義接口:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace OCR {interface ImageRecognitionInterface{/// <summary>/// 識別圖像/// </summary>/// <param name="imgPath"></param>/// <returns></returns>string Recognize(string imgPath);} }編寫工具類和實現:
using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks;namespace OCR.ImageRecognition {/// <summary>/// AspriseOCR/// </summary>/// DLL包引用:AspriseOCR.dll、DevIL.dll、ILU.dll/// 下載地址:http://asprise.com/product/ocr/download.php?lang=csharppublic class AspriseOCR:ImageRecognitionInterface{[DllImport("AspriseOCR.dll", EntryPoint = "OCR", CallingConvention = CallingConvention.Cdecl)]public static extern IntPtr OCR(string file, int type);[DllImport("AspriseOCR.dll", EntryPoint = "OCRpart", CallingConvention = CallingConvention.Cdecl)]static extern IntPtr OCRpart(string file, int type, int startX, int startY, int width, int height);[DllImport("AspriseOCR.dll", EntryPoint = "OCRBarCodes", CallingConvention = CallingConvention.Cdecl)]static extern IntPtr OCRBarCodes(string file, int type);[DllImport("AspriseOCR.dll", EntryPoint = "OCRpartBarCodes", CallingConvention = CallingConvention.Cdecl)]static extern IntPtr OCRpartBarCodes(string file, int type, int startX, int startY, int width, int height);/// <summary>/// 識別圖像/// </summary>/// <param name="imgPath"></param>/// <returns></returns>public string Recognize(string imgPath){try{int startX = 0, startY = 0;Image image = Image.FromFile(imgPath);return Marshal.PtrToStringAnsi(OCRpart(imgPath, -1, startX, startY, image.Width, image.Height));}catch (Exception ex){Console.WriteLine("識別圖像錯誤:"+ex.Message);}return "";}} }測試效果
這里通過解析中英文能力來測試
英文識別
中文識別
可見,效果不是很理想,還是要購買其正規渠道的產品才行。
示例和包下載
網上的分比較貴,不建議去下載,因為沒什么用,我這里分享一個大家可以做測試使用。
鏈接:https://pan.baidu.com/s/1Lo3lSnHVvYCfDp-tf9oLnQ
密碼:fmai
AspriseOcr也支持Java圖像識別:參考http://zxs19861202.iteye.com/blog/1749780
總結
以上是生活随笔為你收集整理的C# OCR AspriseOcr测试使用图像文字中英文识别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rust石头壁炉_《腐蚀》RUST生存攻
- 下一篇: VScode突然之间连接服务器显示不断重