Android Question Barcode scanner parameters ?

vmag

Active Member
Hello.
Here is a simple and good example of a barcode scanner.
Is it possible to control the scan parameters?
For example, enable image inversion to recognize white QR codes on a black background.
Thanks.
 

vmag

Active Member
QR codes are small and inverted 1 cm side
 

Attachments

  • QR1.jpg
    13.9 KB · Views: 88
  • QR2.jpg
    14.2 KB · Views: 83
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
QR codes are small and inverted 1 cm side
How do you expect anyone can answer here? You are NOT providing any code you are using.
Create a small project showing the issue if you expect to get help.

There is nothing in the Example you linked which saves an Image.
Especially not a 1cm small one.

B4X:
Private Sub CreateDetector (Codes As List)
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim builder As JavaObject
    builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
    Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
    Dim barcodeStatic As JavaObject
    barcodeStatic.InitializeStatic(barcodeClass)
    Dim format As Int
    For Each formatName As String In Codes
        format = Bit.Or(format, barcodeStatic.GetField(formatName))
    Next
    builder.RunMethod("setBarcodeFormats", Array(format))
    detector = builder.RunMethod("build", Null)
    Dim operational As Boolean = detector.RunMethod("isOperational", Null)
    If operational = False Then
        toast.Show("Failed to create detector")
    End If
    btnStartStop.Enabled = operational
End Sub

Private Sub Camera1_Preview (data() As Byte)
    If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
        'Dim n As Long = DateTime.Now
        Dim frameBuilder As JavaObject
        Dim bb As JavaObject
        bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
        frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
        Dim cs As CameraSize = camEx.GetPreviewSize
        frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height,  842094169))
        Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
        Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
        LastPreview = DateTime.Now
        Dim Matches As Int = SparseArray.RunMethod("size", Null)
        If Matches > 0 Then
            Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(0))
            Dim raw As String = barcode.GetField("rawValue")
            FoundBarcode(raw)
        End If
    End If
End Sub
 
Last edited:
Upvote 0

vmag

Active Member
How do you expect anyone can answer here? You are NOT providing any code you are using.
The first word in the message is a link to the finished project, which I am interested in from the point of view of parameter settings, here is this link in full.
Your procedures are in this project too, of course their contents are different.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Your procedures are in this project too, of course their contents are different.
I copied the code i posted from the project you linked. It´s not my code.
I just showed you that there is nothing which saves an image in this code.

How are you creating these 1cm images? It is not the code you linked.
 
Upvote 0

vmag

Active Member
How are you creating these 1cm images?
I made these pictures in adobe Photoshop in order to make it clear what we are talking about. This is the marking of cigarettes - white dots on a black background and this is the only DataMatrix that is not readable by this example, I suspect that due to the inversion of the Data Matrix, so I asked how to solve this problem
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
if you want to invert an image, invert it. the detector decodes a frame. period.

a problematic frame (poor focus, bad orientation, size, etc) must be dealt with
before being passed to the detector. the most the detector does in this regard is
to binarize the frame and to allow for minimal misalignment to facilitate decoding.
pre-processing is a completely separate matter from decoding.

you can either take a picture of a barcode with your camera, manipulate it
according to your needs and pass the result to the detector (this is the usual
course of action), or you can alter your camera settings as best you can to
present a decodable frame to the detector (which uses a live frame as opposed
to a static bitmap).

there is nothing stopping you from finding image processing libraries and combining
them with the detector to produce a nice barcode scanning app. if you want everything
handed to you, there are plenty of barcode scanning apps on play.
 
Upvote 0

Johan Schoeman

Expert
Licensed User
Longtime User


It can/should scan inverted QR, datamatrix etc. Have not tested it in a very long time. You might have to add Runtime Permissions for the camera if it is not already included - cannot remember
 
Upvote 0

vmag

Active Member
Thank you very much! This is what I need, scans everything.
I have already got out of the situation - I bought a USB - Type C adapter and connected a regular 2D scanner to the phone.
Now there will be two options: a phone camera and a 2D scanner. Thanks! Thanks! Thanks!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…