OCR.Space extension

Hello everybody,
for my project I needed to convert images to text. I read the forum tutorials, but at the end I decided to write an extension.
For this purpose I used the API of ocr.space.
First step You have to register to have your free api key.

fromfile
To get the text from a file in your phone
objectLocation: the file path in your phone
apiKey: your Api Key provided by OCRSpace
language: Language used for OCR (on ocr.space website you find the possible values)
fileType: supported image file formats (on ocr.space website you find the possible values)
scale: true or false, this can improve the OCR result
ocrEngine: 1,2 or 3 see specifications on Free OCR API

fromurl
To get the text from a URL
url: the file position in the web
apiKey: your Api Key provided by OCRSpace
language: Language used for OCR (on ocr.space website you find the possible values)

ocrresponse
If the responseCode is Ok you will find the OCR result on parsedText

here is an example of how to perform OCR with URL and File

Source Code:
OCRSpace.txt (12.2 KB)
Extension:
OCRSpace.aix (17.8 KB)
Sample Project:
OCR.aia (22.6 KB)

The updated version you can find in post #23 here OCR.Space extension - #23 by Marco_Perrone

How works the sample project:
Select Language (for FILE and URL), File Type and OCR Engine (only for FILE)
If You want an OCR from URL write the URL in the Text Box and then click on "Get URL OCR"
If You want an OCR from File take a pic with some text and then click on "Get FILE OCR"
Try scale On or OFF or different OCR Engine to see the difference

I hope You find useful

Best Regards

Marco Perrone

10 Likes

Very nice Marco!

25,000 free scans per month is generous from OCRSpace and the file size limit of 1MB is fairly good too.

1 Like

Any comments from anyone that has been using this extension ?

You can sign up for the API and give the extension a try. :slight_smile:

Ciao,
as @Gordon_Lu says, the better way is to try, but here a video with a test


Best Regards
Marco

2 Likes

I had tried it but didnt seem to be working thats why I asked if anyone had any comments.

Hi @S11,
I don't know what You did,
Did You register on ocr.space to have your apikey?
Did You try my sample adding your apikey?
As You can see in my video I can use the extension without problem.
Best Regards
Marco

with the OCR call in it the app crashes, if i remove the ocr call it doesnt it just displays teh path to the file with was 72kb

Yes I registered and received the apiKey

The exstension create a log file if there is an exception, search for FileStackLog.txt.
So I can understand what happens (I hope).

FileStackLog.txt (18.0 KB)

The log says:
java.lang.NullPointerException: Attempt to invoke interface method 'void com.android.okhttp.internal.http.HttpStream.writeRequestHeaders(com.android.okhttp.Request)' on a null object reference
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:606)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:475)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:411)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getErrorStream(HttpURLConnectionImpl.java:154)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getErrorStream(DelegatingHttpsURLConnection.java:98)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getErrorStream(HttpsURLConnectionImpl.java:30)
at OCRSpace.OCRSpace.PerformOCR(OCRSpace.java:278)
at OCRSpace.OCRSpace.OCRFromFile_Exec(OCRSpace.java:131)
at OCRSpace.OCRSpace$1.run(OCRSpace.java:99)
at java.lang.Thread.run(Thread.java:919)

I suppose this is related to path that could be wrong or permission denied.
Could I see the path value?
On my sample I save the image on the Pictures folder.
With my sample are You able to perform OCR?

Any suggestion from the path and permission experts, am I on the right way?

Ciao
Marco

This worked for me on Android 10 and 13 with companion app

filePath:
/storage/emulated/0/Android/data/edu.mit.appinventor.aicompanion3/files/ctiImage.jpg

Note: slash at beginning of saveAs filename, full path given for objectLocation, and fileType = JPG not jpg

I had already tried both JPG and jpg.
Looks like the path may be the issue, ill try later and update on results.

Is these extension support marathi language?

Check if the language is listed here.

Hi @gopal_gopal
I searched on Free OCR API and on language I did not find reference to marathi language.
But if You use ocrEngine 3 with OCRFromFile You can use:
Hindi = hin
Kannada = kan
Telugu = tel
Tamil = tam
I hope this can be useful this for You?
Best Regards
Marco

1 Like

I already read ocr space docs, but Thank you for spending time to reply me :hugs:.

Hi Marco,
I'm trying to use your extension for receipt recognition and it works!
But unfortunately you didn't include in the OCRFromFile call two important parameters that are present in the OCR API and could drastically improve the OCR quality: IsTable and DetectOrientation.
Is it possible to add these parameters?
Thank you
Alex