這幾天研究了下ORC 文字識別,大概了解了三種識別方式:
1、通過微軟的控件調用Microsoft Office Document Imaging。
2、是通過AspriseOCR 調用
3、是Tesseract ORC
本人剛接觸編程不久,基本功不好,走了很多彎路,先把自己的一些體會寫下來,留着以后復習用
先講 AspriseOCR 調用,這個是官網免費版,就是調用的時候會彈出對話框,讓你訪問官網
看了官網的SDK,欺負我E文不好,大概能看懂就行
下載
實例文件和API類庫
http://asprise.com/royalty-free-library/c%23-sharp.net-ocr-for-windows-mac-linux-download.html
新建一個c#項目:
導入asprise-ocr-api 這個項目
把里面的 demo文件夾中 aocr.dll, aocr_x64.dll 復制到項目的跟目錄下
在自己新建的代碼中添加如下代碼:
using asprise_ocr_api; AspriseOCR.SetUp(); AspriseOCR ocr = new AspriseOCR(); ocr.StartEngine("eng", AspriseOCR.SPEED_FASTEST); string s = ocr.Recognize("C:\path\img.jpg", -1, -1, -1, -1, -1, AspriseOCR.RECOGNIZE_TYPE_ALL, AspriseOCR.OUTPUT_FORMAT_PLAINTEXT); Console.WriteLine("OCR Result: " + s); // process more images here ... ocr.StopEngine();
項目完成
--------------------------------------------------------------------------------------------------------------------------------------------
華麗的分隔符
下面講破解版的asprise 的使用
先從網上下載 破解文件,包含三個文件:AspriseOCR.dll、DevIL.dll、ILU.dll。
把這3個文件復制 生成可執行文件的跟目錄下,在項目屬性----生成-----目標平台 設置 x86平台,否者一直報錯。!!!! .Net 2.0 平台
其中需要使用的3個dll是AspriseOCR.dll、DevIL.dll、ILU.dll。
需要注意的是這幾個.dll是vc寫的引用要在程序中用DllImport引用,關鍵代碼:
在類的開頭引入如下代碼:
[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);
調用代碼很簡單只有一句:
MessageBox.Show(Marshal.PtrToStringAnsi(OCRpart(img_path, -1, startX, startY, width, height)));
其中img_path:為圖片路徑,startX、startY坐標均為0即可,width、height圖片的寬和高。
破解方法教程參考:http://m.blog.csdn.net/blog/scys1217/19809855