Android Question OCR using Google Play Services?

drgottjr

Expert
Licensed User
Longtime User
very stripped down. tested just now on pixel 3a, b4a12.2, sdk31
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Thank you, it 's a good base to start with. In particular the preview is not distorted as on some earlier OCR implementations I've tried on the forum that use third party or deprecated android APIs..

ocrdetector needs to be a process global or it stops working after a device rotation,
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
probably one of many "needs to be's". i stripped everything out and rebuilt as needed to get it running for you.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi, I'm interested to the same subject.
Where's the code you both refer to?

BTW, my final goal is to have the camera recognize OCR and qrcode. The latter is already working. Now I would like to add OCR capabilities so to have OCR for one data field and qrcode for a different one. I guess that I would need to have two instances of the camera object on the same B4xPage.
Another point would be to restrict the area of OCR capture because there are a lot of items on the page and I need to read just a number out of it.

TIA
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thank you @agraham
Do you think my project to make OCR and QrCode coexist is feasible? Would you design it as I described above? Any other hint/suggestion?

Thanks again for the code
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Thanks anyway.
I'll post an update once I'll have something functional to show.

udg
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
they don't happen at the same time; you do one, then you do the other (that is, you either process sequentially or pass the processing off to an async thread). it's no big deal. they're separate api's. the real issue involves cropping. ocr will try to grab anything that looks like "text" wherever it appears in the image. barcode is trained to look for certain rigid patterns. barcode will give up rather than give you garbage. ocr is all too happy to return whatever it sees (unless you restrict its view). and if you're thinking about translation from ocr, that's doable too.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Agreed. Is there a way to reduce the window captured by the camera when in OCR mode? Eventually a superimposed rectangle large enough to accomodate the correct reading and exclude all the surrounding text? Having a white mask over the original paper would be too cumbersome.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
even with a superimposed frame, you might fail to capture both the ocr and the qr code you want. (i'm guessing you want the text that surrounds a qr code and the
qr code at the same time). but, yes, you can pass the "cropped" part of the image to the ocr processor and the full image to the barcode processor. (it's what i use
for some cases.) the barcode processor will only look for a barcode (in this case a qr code), so, in theory, you shouldn't have to worry about extraneous text.
the barcode processor will ignore it. although, you should be aware that barcode scanning works better and faster if the barcode is in the center of the image and
the image isn't cluttered. you run the risk of a failed scan (as i mentioned previously, barcode processor does not guess. the rules are very strict. ocr, on the other
hand can be fooled into recognizing as text any series of dots that might be construed as text in some universe. whereas a barcode scanner is either legible or not,
ocr will give you text where there is none. some processors use a dictionary to expedite processing, and this can fall into that trap: sometimes guessing works,
sometimes it doesn't.

both barcode and ocr give you bounding boxes in addition to whatever they are supposed to extract. it's a tool to work with if you're trying to concentrate on some
text or barcode located in a partricular part of the image. ocr was designed to handle book scanning. desktop publishing is a problem for it; stuff is all over the page.
without a bounding box, you wouldn't know which block of text goes where.

check out images below. image with a lot of barcodes. i put up a little pre-cropping frame, capture the barcode of interest and then get the ocr (note, it correctly
extracts the text above the barcode, but it thinks the barcode itself is also text...)
 

Attachments

  • 1.png
    1.png
    175.1 KB · Views: 20
  • 2.png
    2.png
    86.1 KB · Views: 18
  • 3.png
    3.png
    172.8 KB · Views: 17
  • 4.png
    4.png
    138.5 KB · Views: 15
  • 5.png
    5.png
    122.8 KB · Views: 18
Upvote 0

udg

Expert
Licensed User
Longtime User
Writing from mobile,sorry.
My case is simpler. I have two tickets. One showing a qrcode that I already read and decode.
Second ticket is full of data printed not 100% clearly. I have to isolate just a number on that ticket. So a small bounding rectangle to help the user to select that number would be ok.
I will make use of UI items to select mode qrcode/ocr for the camera.
Eventualy two instances of the camera object, no problem.
 
Upvote 0
Top