B4A Library Barcode reader based on Google Play Services Vision

Status
Not open for further replies.
Better solution: https://www.b4x.com/android/forum/threads/160725/#content

This is not really a library. It is a modification to CameraEx example that adds barcode detection based on Google Play Services Vision. It uses JavaObject to create the detector and detect barcodes in the Preview event.

You should call CreateDetector with the formats you want to detect. Fewer codes will yield faster detections.
List of formats is available here: https://developers.google.com/andro...d/gms/vision/barcode/Barcode#constant-summary
The implementation is quite simplistic as it is done on the main thread. It works good on Nexus 5X. I haven't tested it on low end devices.

Note that you should add this code to the manifest editor:
B4X:
<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="barcode" />
 

Attachments

  • BarcodeCamera.zip
    13.6 KB · Views: 2,731
Last edited:

AHilton

Active Member
Licensed User
Longtime User
Impressive.

I threw about 7 of the harder types of barcodes I could quickly find at it; 14 devices (Nexus's, Old Galaxy Notes, New-ish Tabs, an old Toshiba tablet, Motorola phones); rounded, crumpled, dirty, various angles and distances and speeds panning across them; and multiple barcodes in the same preview and different types of barcodes at different scales in the same preview 'shot', too. With the exception of the auto-focus not working on some of the devices that I know have that capability (I just uncommented the btnFocus_Click sub and hit the button for it to focus on those), it worked really quite well.

I just called CreateDetector with "ALL_FORMATS". It was plenty fast enough and allowed capturing multiple barcode types at the same time.

[edit] Turns out it wasn't capturing those 'at the same time' but it was capturing each barcode in the preview window so quickly that it looked like it was doing that. Still impressive. I just tried some really horrendous barcodes (broken, very dirty, mostly obscured, very dense) and it did a good job with those, too.

With the multitude of barcode readers on the forum with various and overlapping issues, this is one I'll be testing more. There are a couple of my apps that could use an upgrade and my current B4A project will need this coming up in the Summer.
 
Last edited:

FrankDev

Active Member
Licensed User
Longtime User
Hi

Is it possible to restrict the barcode detection range?

How I understand it will be managed by
Camera1_Preview (data () As Byte)
the image data is used and in this area the barcodes
searched.

Is it possible to crop this data? i. e. to use an area of the whole preview (see image (detection area) and search for barcodes there.

Best regards
Frank
 

Attachments

  • detection.jpg
    detection.jpg
    66.9 KB · Views: 1,513

incendio

Well-Known Member
Licensed User
Longtime User
Hi,

Tested on Jelly Bean & Lolipop, but nothing happen. Already set to read all format.
B4X:
CreateDetector (Array("ALL_FORMATS"))

Is there minimum OS for this to run?
 

incendio

Well-Known Member
Licensed User
Longtime User
Hi,

My Barcode is Code 39. Output for Is detector operational always true, no matter what format used.

1) Nothing happen with this code
B4X:
 CreateDetector (Array("ALL_FORMATS","CODE_128","CODE_93"))

2) Worked OK with this code
B4X:
 CreateDetector (Array("CODE_39"))

After 2nd phase, change codes to
B4X:
 CreateDetector (Array("ALL_FORMATS"))
still worked OK

Changed again to code on 1st phase, didn't worked.
 

Beja

Expert
Licensed User
Longtime User
All,
Away from my pc these days so can't test. Please pardon a couple of questions:
1. Does it need to connect to online Google services site? It's blocked over here.
2. Does it also read QR codes?

Best regards. B
 

FrankDev

Active Member
Licensed User
Longtime User
@Beja
>Does it need to connect to online Google services site? It's blocked over here.<
no.
Wifi + Sim off.
it works :)

>Does it also read QR codes?<
yes :)
 

Beja

Expert
Licensed User
Longtime User
@Beja
>Does it need to connect to online Google services site? It's blocked over here.<
no.
Wifi + Sim off.
it works :)

>Does it also read QR codes?<
yes :)

Thanks Frank, but I am just wondering why's the need for Wi-Fi if doesn't need to use online Google services.. If it sends any request or query to Google.com/bla bla bla, then it wouldn't work here
 

DonManfred

Expert
Licensed User
Longtime User
Thanks Frank, but I am just wondering why's the need for Wi-Fi if doesn't need to use online Google services.. If it sends any request or query to Google.com/bla bla bla, then it wouldn't work here
the engine is part of Google Vision (installed on Android) and does not need to connect to somewhere... As far as i know!
 

Beja

Expert
Licensed User
Longtime User
the engine is part of Google Vision (installed on Android) and does not need to connect to somewhere... As far as i know!

So no need to connect to Wi-Fi? Or I am missing something.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
It doesn't require an internet connection. It might need to download information on the first run though it didn't require anything when I tested it.
See this link: https://developers.google.com/visio...rial#querying_the_detector_operational_status

I haven't added it to the example project however you should add this to the manifest editor:
B4X:
<meta-data
    android:name="com.google.android.gms.vision.DEPENDENCIES"
    android:value="barcode" />

This tells the OS that it should download the barcode library during installation.
 

jo1234

Active Member
Licensed User
Longtime User
That's a great and flexible way to read barcodes! Thanks a lot!

Is it possible to restict the size of the preview images?
I would like to use only half of the screen for the preview, not the complete screen. If I simply shrink the preview panel the image gets distorted.

I could take the full-screen panel, cover half of it and then try to do as you have suggested above, i.e. take the full-size preview, convert it to jpeg, crop it and then analyze only the half of the picture that is actually visible on screen.
But restricting the initial full screen preview images to half screen size would be much easier.

thanks,
Johannes
 

Micholl

Member
Licensed User
Longtime User
Hello Erel,
is there a way to identify / markup recognised barcodes in the preview?
At the moment no one can be sure which barcodes are recognised.

Thank you,

Michael
 
Status
Not open for further replies.
Top