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=csharp public 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 ""; } } }
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); } }
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方式導入。
定義接口:
編寫工具類和實現:
測試效果
這里通過解析中英文能力來測試
英文識別
中文識別
可見,效果不是很理想,還是要購買其正規渠道的產品才行。
示例和包下載
網上的分比較貴,不建議去下載,因為沒什么用,我這里分享一個大家可以做測試使用。
鏈接:https://pan.baidu.com/s/1Lo3lSnHVvYCfDp-tf9oLnQ
密碼:fmai
AspriseOcr也支持Java圖像識別:參考http://zxs19861202.iteye.com/blog/1749780
參考網站:
https://blog.csdn.net/boonya/article/details/81197376