cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
afmc2238
Helper I
Helper I

Failed to Extract Text with OCR with Tesseract Engine

I am currently trying to extract a small bit of text from a scanned pdf file.  I am using the "Extract Text with OCR" action and get the error below every time. I have tried either reading all of the text from the fall or a subregion with the same result. I have confirmed that the Tesseract connector is on my local machine.  I've also tried this with "Create Tesseract OCR engine" as the prior action (even though I believe that is no longer needed) with the same result. 

 

2021-06-16_16h34_34.png

 

Parameter is not valid.: Robin.Core.ActionException: Failed to extract text with OCR ---> System.ArgumentException: Parameter is not valid.
   at System.Drawing.Bitmap..ctor(String filename)
   at Robin.Modules.OCR.Utilities.Utilities.GetImageForOCR(OCRSource source, SourceScanMode sourceScanMode, Nullable`1 scanRegionX1, Nullable`1 scanRegionY1, Nullable`1 scanRegionX2, Nullable`1 scanRegionY2, IEnumerable`1 imagesToFind, Int32 tolerance, Boolean waitForImage, Boolean timeoutSet, Nullable`1 timeout, Nullable`1 searchRegionImageX1, Nullable`1 searchRegionImageY1, Nullable`1 searchRegionImageX2, Nullable`1 searchRegionImageY2, Action suspendSecureScreen, Action restoreSecureScreen, String imageFilepath, IImageFinder imageFinder)
   at Robin.Modules.OCR.Actions.ExtractTextWithOCRBase.Execute(ActionContext context)
   --- End of inner exception stack trace ---
   at Robin.Modules.OCR.Actions.ExtractTextWithOCRBase.Execute(ActionContext context)
   at Robin.Runtime.Engine.ActionRunner.RunAction(String action, Dictionary`2 inputArguments, Dictionary`2 outputArguments, IActionStatement statement)

I would greatly appreciate some help with this! 

30 REPLIES 30

Pavel_NaNoi_0-1636974383946.png

This is what my OCR looks like for the method I just showed you, I don't use X or Y coordinates in mine so that may be the issue? Otherwise I honestly have no clue, maybe you need to re-install power automate desktop, perhaps something got corrupted during the update.

Hi Pavel,

 

Thank you for your reply, base on your suggestion OCR capture whole image in one variable method, I found some technical problem in my case. You know the OCR will capture all text in one variable and we can review the variable in the edit mode. I found differ image order, the DEL number will stored in differ line in the variable. How can I retrieve the right value by search the begin text DELxxxxxx in the variable e.g Ocrtext . Sometime it will mix with other text and sometime it will show individually.  

 

henryhvb5_0-1637044251345.png

henryhvb5_1-1637044457391.png

Thank you very much

 

 

You have to use the "Parse Text" activity with a regular expression, here's how I did it:

Pavel_NaNoi_0-1637056578804.png

this will always get you text that has DEL followed by multiple numbers.

Hi Pavel,

 

Thank you for your suggestion, the flow is working fine. 

I can start the load test.

 

Thank you very much Pavel, you are the expert of PAD. 

Pavel_NaNoi
Resolver III
Resolver III

No problem,

 

Enjoy! ^^

Hi Pavel,

 

Thank you for your advice in my OCR flow, but I got another problem is the performance is not fast enough, as my flow require to open the image and capture in the foreground window. I have try to run in disk option, but return the following error:

Microsoft.Flow.RPA.Desktop.Robin.SDK.ActionException: Failed to extract text with OCR ---> System.ArgumentException: Parameter is not valid.
at System.Drawing.Bitmap..ctor(String filename)
at Microsoft.Flow.RPA.Desktop.Modules.OCR.Utilities.Utilities.GetImageForOCR(OCRSource source, SourceScanMode sourceScanMode, Nullable`1 scanRegionX1, Nullable`1 scanRegionY1, Nullable`1 scanRegionX2, Nullable`1 scanRegionY2, IEnumerable`1 imagesToFind, Int32 tolerance, Boolean waitForImage, Boolean timeoutSet, Nullable`1 timeout, Nullable`1 searchRegionImageX1, Nullable`1 searchRegionImageY1, Nullable`1 searchRegionImageX2, Nullable`1 searchRegionImageY2, Action suspendSecureScreen, Action restoreSecureScreen, String imageFilepath, IImageFinder imageFinder)
at Microsoft.Flow.RPA.Desktop.Modules.OCR.Actions.ExtractTextWithOCRBase.Execute(ActionContext context)
--- End of inner exception stack trace ---
at Microsoft.Flow.RPA.Desktop.Modules.OCR.Actions.ExtractTextWithOCRBase.Execute(ActionContext context)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.ActionRunner.RunAction(String action, Dictionary`2 inputArguments, Dictionary`2 outputArguments, IActionStatement statement)

 

I don't know how can I run and capture at the background

Hmm, in the "Take Screenshot" action, make sure it saves as a BMP, if that doesn't work, use JPG or PNG as below:

Pavel_NaNoi_0-1637624928375.png

 

If that doesn't work, send me a screenshot of your flow once again, I'll see what else I can find.

Hi Pavel,

 

Thank you for your advice, it is not a good option to save a screenshot and then store on disk and OCR the image on disk. This practice is almost same as I capture the open pdf image at the foreground by OCR directly. If I can capture text directly at the background from the disk without requiring to transfer format, it will save many time in a loop for several hundreds of pdf image files. I have go through the community with the similar topic. Some member facing the same problem as me, still require to transfer image format to BMP or Jpg. But this is not guarantee the OCR can capture text from disk. Hope Microsoft can fix the error and limitation on the OCR extract text from disk option.  

It shouldn't make several hundreds of image files, because you will be saving to the same file each loop, in other words it will be overwritten in each iteration of the loop because the image file name is the same, thus in a for loop this shouldn't be an issue. Try doing a loop 2 times and see if it makes another image file, I'm fairly certain it won't.

Hi Pavel, 

 

My existing flow is can loop hundred of PDF image and capture the invoice number in the foreground, then the PDF file will closed and then rename the file to invoice number. At last when the loop is finish, all the invoice number which is stored in the list will write to the excel file.

 

If the OCR part can scan at the background without require to open in foreground to capture, then it can save several second in each file. The existing flow require around 4.5 second for each capture. That's why the screenshot imge to BMP suggestion is not a good solution in my case, the run time is almost the same as my original design. 

Wait I just realized, you have actual PDF files right? why not just use the Extract Text from PDF action instead of bothering with OCR? that is instant and just needs a parse.

 

Otherwise I'm not sure how else I can help, since OCR is just inherently slow, the most you can do is change the size of the area it reads to speed it up via x and y coordinates.

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

New Process Advisor Capabilities carousel.png

Read the blog for the latest news

Read the latest about new experiences and capabilities in the Power Automate product blog.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (3,235)