B4A Library Barcode reader based on Google Play Services Vision

Discussion in 'Additional libraries, classes and official updates' started by Erel, Feb 18, 2018.

  1. Erel

    Erel Administrator Staff Member Licensed User

    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:
    Code:
    <meta-data
        android:name=
    "com.google.android.gms.vision.DEPENDENCIES"
        android:value=
    "barcode" />
     

    Attached Files:

    Last edited: Oct 7, 2018
  2. FrankDev

    FrankDev Active Member Licensed User

    hi
    that's really great!!!!! :)
     
    Last edited: Feb 18, 2018
  3. AHilton

    AHilton Active Member Licensed 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: Feb 18, 2018
    Beja and Erel like this.
  4. Erel

    Erel Administrator Staff Member Licensed User

    Good. The advantage of this implementation is that the barcode detection is decoupled from the camera functionality. So you can use it together with CameraEx as in this example or with Camera2 and you have full control over the camera itself.
     
  5. FrankDev

    FrankDev Active Member Licensed 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
     

    Attached Files:

  6. Erel

    Erel Administrator Staff Member Licensed User

    Try this:
    Convert the preview data to a jpeg data (there is such a method in CameraEx) and then load it to a bitmap.
    Crop the bitmap and pass it to frameBuilder with:
    Code:
    frameBuilder.RunMethod("setBitmap"Array(YourBitmap)) 'instead of the setImageData line
     
    FrankDev likes this.
  7. FrankDev

    FrankDev Active Member Licensed User

    better than expected ;)
     
  8. incendio

    incendio Well-Known Member Licensed User

    Hi,

    Tested on Jelly Bean & Lolipop, but nothing happen. Already set to read all format.
    Code:
    CreateDetector (Array("ALL_FORMATS"))
    Is there minimum OS for this to run?
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Don't set it to all formats. Start with one specific format.

    What is the output of this line:
    Code:
    Log("Is detector operational: " & operational)
     
  10. incendio

    incendio Well-Known Member Licensed 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
    Code:
    CreateDetector (Array("ALL_FORMATS","CODE_128","CODE_93"))
    2) Worked OK with this code
    Code:
    CreateDetector (Array("CODE_39"))
    After 2nd phase, change codes to
    Code:
    CreateDetector (Array("ALL_FORMATS"))
    still worked OK

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

    Erel Administrator Staff Member Licensed User

    Not sure why it doesn't work however there is no reason to add ALL_FORMATS with other types.
     
  12. Beja

    Beja Expert Licensed 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
     
  13. FrankDev

    FrankDev Active Member Licensed 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 likes this.
  14. Beja

    Beja Expert Licensed 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
     
  15. DonManfred

    DonManfred Expert Licensed User

    the engine is part of Google Vision (installed on Android) and does not need to connect to somewhere... As far as i know!
     
    Beja and FrankDev like this.
  16. Beja

    Beja Expert Licensed User

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

    Erel Administrator Staff Member Licensed 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:
    Code:
    <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.
     
    Beja, lemonisdead and DonManfred like this.
  18. jo1234

    jo1234 Member Licensed 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
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this question.
     
  20. Micholl

    Micholl Member Licensed 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice