Sicos1977 / TesseractOCR

A .net library to work with Google's Tesseract
161 stars 20 forks source link

DllNotFoundException: Failed to find library 'leptonica-1.83.1.dll' for platform x64 #44

Closed rsherman726 closed 10 months ago

rsherman726 commented 1 year ago

I downloaded the Tesseract Web Demo and ran it and I get this error. DllNotFoundException: Failed to find library 'leptonica-1.83.1.dll' for platform x64

I have been wrestling with this error for a week. I did see the Leptonica dll in both the x64 and x86 directories of the projects packages folder. Even tried this: Assembly.LoadFrom(@"C:\Users\Admin\Source\Repos\TesseractWebDemo\packages\TesseractOCR.5.3.5\x64\leptonica-1.83.1.dll"); But it has its own error. Also tried reinstalling the VC Redist x86 & x64 which did not help. What do you think is the solution?

LeoLovemary commented 1 year ago

You should copy the x64 folder to the same folder with the exe. image

rsherman726 commented 1 year ago

This is an asp.net application, there is a bin folder containing all the dlls and I tried copying the dlls into the bin folder and I still get that error.

LeoLovemary commented 1 year ago

I create asp.net application with x86 as below,it can work,so I do not know why?sorry! image image

rsherman726 commented 1 year ago

Thanks I got it working. I used itextsharp to read the pdf and convert the Pages to an image and then to a memory stream. I did notice that not all PDFs where readable from Itextsharp. Do all PDFs contain images?

LeoLovemary commented 1 year ago

I used itextsharp before.but I know that not all pages of pdf contain images,maybe they contain only text in pages.If you want to convert the page to an image,you can consider using the library ghostscript or mupdf.This is my suggestion.

rsherman726 commented 1 year ago

I used GhostScript to convert the PDFs to PNG and PDF gets read correctly. I have an new issue. Do you know about using a config file? something like this: string customConfigPath = Server.MapPath(@"~/tessdata/configs/") + "digits";

Page.Engine.SetVariable("configfile", customConfigPath);

Not working. Is there a certain was to tell the engine to use a config file?

rsherman726 commented 1 year ago

OK, I figured that out too. Now I need to figure out how to extract data from a HCFA form CMS 1500 Medical Claim form.

LeoLovemary commented 1 year ago

Sorry,I do not know and use the HCFA form CMS 1500 Medical Claim form.You can consider the https://github.com/Sicos1977/TesseractOCR#iterate-through-the-layout-of-a-page to ocr and extract data,you can use the positon of the text to generate a form。 If the HCFA form CMS 1500 Medical Claim form is pdf format ,it maybe contains the text,then you can use itext7 to extract text directly. You can use the method of GetTextFromPage or GetAcroForm that I just know a little and I did not use it,so I can't give the example.

rsherman726 commented 1 year ago

Users are going to scan this form and I will need to OCR the scanned documents. I need tesseract to ignore the underlying form and extract only user entered text. I saw something about using templates or something.

LeoLovemary commented 1 year ago

If the positon of user entered text is fixed,you can use the methond of SetRectangle to ocr, it may be faster than ocring all the page. Or you can ocr the all the page,then use the BoundingBox methond to fix the positon.

rsherman726 commented 1 year ago

I am going to use a boxfile with bounding boxes to map where data is but it is not working. I Put the box file in the tessdata directory and used this code: string boxString = File.ReadAllText(Server.MapPath(@"~/tessdata/") + "boxfile.box"); // or provide your box string... TesseractOCR.Pix.Image TessImage = TesseractOCR.Pix.Image.LoadFromMemory(ms); using (var pPage = engine.Process(TessImage, boxString, TesseractOCR.Enums.PageSegMode.Auto))

Not affecting the results.

LeoLovemary commented 1 year ago

I did not use boxString or boxfile.box. public Page Process(Image image, Rect region, PageSegMode? pageSegMode = null); the second argument is the Rect. this is my code to ocr all the page: var engine = new Engine(@"tessdata", Language.English, EngineMode.Default); var img = TesseractOCR.Pix.Image.LoadFromFile("z.png"); var page = engine.Process(img); MessageBox.Show(page.Text); this picture and the result are below: z image If you want to ocr the part ,you can get the postion first as: image this code is: var engine = new Engine(@"tessdata", Language.English, EngineMode.Default); var img = TesseractOCR.Pix.Image.LoadFromFile("z.png"); Rect rect = new Rect(0, 0, 366, 48);//Rect(int x, int y, int width, int height) var page = engine.Process(img,rect , TesseractOCR.Enums.PageSegMode.Auto); MessageBox.Show(page.Text); the result is: image that is all my work to make success.

rsherman726 commented 1 year ago

I wanted to break the page down to like 18 rectangles. How do you do that without bounding box?

LeoLovemary commented 1 year ago

I don't find the highly efficient method to ocr rectangles.But you can use the methond as below: Rect rect = new Rect(0, 0, 366, 48); var page = engine.Process(img,rect , TesseractOCR.Enums.PageSegMode.Auto); MessageBox.Show(page.Text); page.Dispose();//you should dispose,or you may get the error: System.InvalidOperationException: Only one image can be processed at once. Please make sure you dispose of the page once your finished with it Rect rect1 = new Rect(11, 53, 549, 98); var page1 = engine.Process(img, rect1, TesseractOCR.Enums.PageSegMode.Auto); MessageBox.Show(page1.Text); page1.Dispose(); and rect2,rect3,page2,page3 so on .

rsherman726 commented 1 year ago

There will only be one page per document for the OCR scan. The rectangle as I see it was for the whole page, the bounding boxes were to only pick up text in those boxes and no where else. That's why I wanted to use bounding boxes.

LeoLovemary commented 1 year ago

I don't understand,sorry,as I know,https://github.com/Sicos1977/TesseractOCR#iterate-through-the-layout-of-a-page ,in this webpage: iterate-through-the-layout-of-a-page,it can get all boxs,then you can choose what you want. If this is not what you want to get,then you can ask the author,I just know a little about TesseractOCR.