Let’s see how to improve OCR accuracy in a PDF image.
In this first example, watch how the image looks without applying the multiplication I just talked about:.
BEFORE |
REGION |
VALUE |
IMAGE |
85,320,46,10 |
INH5O730B |
|
83,320,70,40 |
INR50730S VONx D180J7V021 |
![](https://dw1.s81c.com//IMWUC/MessageImages/a58b725e05f843f6948f931d1b4e207d.png) |
617,319,44,13 |
s.woo |
![](https://dw1.s81c.com//IMWUC/MessageImages/e42b909e0558408b9697f2069045cc9d.png) |
470,318,53,12 |
M123W030 |
![](https://dw1.s81c.com//IMWUC/MessageImages/b31acfa508a24e9dbf4bde9d3691db46.png) |
Now, look at the images again, notice how larger and easier to visualize they are now that we multiplied the DPI by 2:
AFTER |
REGION |
VALUE |
IMAGE |
170,640,92,20 |
INR507308 |
|
166,640,140,80 |
INR507308 VBN: D180J7V021 |
![](https://dw1.s81c.com//IMWUC/MessageImages/1330da5f75964cd79fa04dffe8115ae4.png) |
1234,638,88,26 |
5,997.00 |
![](https://dw1.s81c.com//IMWUC/MessageImages/0af50c64ee1b4c62b5a43377d78c046c.png) |
940,636,106,24 |
3912390000 |
![](https://dw1.s81c.com//IMWUC/MessageImages/a454327ef1a94768be0c5eeb8a13aaf7.png) |
This way, your bot will be more assertive When obtaining data from image documents, bringing more reliability to the automation process.
Now, let’s see how to do this in practice. Look at the steps to configure this mapping.:
Map the region in the image to get the DPI coordinates, in this case [85,320,46,10].
![](https://dw1.s81c.com//IMWUC/MessageImages/fa1a88756c15445d9400db66354432c2.png)
Let’s store this value in a variable {$_region}, and in order to organize our code better, we’ll use a subroutine to perform the multiplication whenever we need it. The input for this routine will be the region DPI coordinates we get from the mapping and the PDF’s page. Its output will be the variable ${_text}, with the text obtained from the PDF image.
![](https://dw1.s81c.com//IMWUC/MessageImages/55f14afcfc71459cb4c111c4d1ff7df7.png)
This is how our subroutine ended up. You can download it at:
Library ![](https://dw1.s81c.com//IMWUC/MessageImages/b0a73c5eb7db4e46b34c9e026292e273.png)
And here, how was the "Get PDF Region Text" command inside the subroutine.
![](https://dw1.s81c.com//IMWUC/MessageImages/7a7807919f894410839b99b42380c7a0.png)
Here’s the explanation on the main commands of the subroutine. You can download it at:
Line: 20\ splitString --text "${_region}" --delimiteroption "CustomDelimiter" --customdelimiter "," _points=value
take the region and convert it to a 4-point list
Line: 23\ evaluate --expression "${_point} * 2" --comment "multiply the point by 2" _point=value
multiply the point by 2
Line: 24\ concatTexts --text "${_newRegion}" --value "${_point}," --comment "concatenate the result creating a new reference" _newRegion=value
concatenate the points to create the new region
Line: 26\ getRegex --text "${_newRegion}" --regexPattern "(.+)\\," --regexOptions "0" --groupnumber 1 --comment "remove the last comma" _newRegion=value
remove the last comma
Line: 28\ setVar --name "${_region}" --value "${_newRegion}"
assign region text variable to region type variable
Line: 29\ pdfRegionText --language "en-US" --region "${_region}" --useocr--ocrprovider "Abbyy" --page ${_page} --dpix 220 --dpiy 220 --file ${pdf} _text=value
execute the command for the new region in the PDF using DPI 220
In the IBM RPA enhancement ideas portal, an idea was posted about having a field in IBM RPA Studio where you can insert the DPI and have the tool perform all of these calculations automatically. You can access this idea and vote for it at:
Have a field to inform the OCR DPI | Digital Business Automation Ideas (ibm.com).I hope this has been insightful.
Until next time!