B4A Library 1D and 2D Barcode Scanner with ZXING - another Barcode Scanner that is 100% embedded in B4A

The attached project wraps the ZXING part of this Github project. I have not tested all the barcode formats but it should scan the following types:

BarcodeFormat.UPC_A
BarcodeFormat.UPC_E
BarcodeFormat.EAN_13
BarcodeFormat.EAN_8
BarcodeFormat.RSS_14
BarcodeFormat.CODE_39
BarcodeFormat.CODE_93
BarcodeFormat.CODE_128
BarcodeFormat.ITF
BarcodeFormat.CODABAR
BarcodeFormat.QR_CODE
BarcodeFormat.DATA_MATRIX
BarcodeFormat.PDF_417

Please take note of the xml files in the /Objects/res/layout and Objects/res/values folders of the B4A project should you start a new project from scratch.

Posting the following:
1. B4A project demonstrating the Barcode Scanner
2. B4A library files - copy them to your additional library folder
3. You also need android-support.v4.jar and core-3.2.1.jar to be in your additional library folder. I have zipped them together and you can download them from this link:
https://www.dropbox.com/s/h9ts6cjfoo5et6h/core-3.2.1.zip?dl=0

You can use it in portrait mode and landscape mode by changing the B4A project's attribute and the code in the Designer:
#SupportedOrientations: portrait

B4X:
zx1.Left = 2%x
zx1.Top = 5%y
zx1.Width = 96%x
zx1.Height = 80%y

b1.Left = 2%x
b1.Top = zx1.Bottom + 2%y
b1.Width = 15%x
b1.Height = 10%y

b2.Left = 45%x
b2.Top = zx1.Bottom + 2%y
b2.Width = 15%x
b2.Height = 10%y

b3.Left = 83%x
b3.Top = zx1.Bottom + 2%y
b3.Width = 15%x
b3.Height = 10%y

1.png



2.png

Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: ZxingBarcodeScanner
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private zx1 As ZxingBarcodeScanner
    Private b1 As Button
    Private b2 As Button
    Private b3 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")

    zx1.LaserColor = Colors.Yellow
    zx1.MaskColor = Colors.ARGB(150, 0, 0, 200)
    zx1.BorderColor = Colors.Magenta
    zx1.BorderStrokeWidth = 5
    zx1.BorderLineLength = 40
    zx1.Visible = False

End Sub

Sub Activity_Resume


End Sub

Sub Activity_Pause (UserClosed As Boolean)
    zx1.Visible = False
    zx1.stopScanner

End Sub


Sub b1_Click

    zx1.toggleFlash

End Sub

Sub b2_Click

    zx1.Visible = True
    zx1.startScanner

End Sub

Sub b3_Click

    zx1.Visible = False
    zx1.stopScanner

End Sub

Sub zx1_scan_result (scantext As String, scanformat As String)

    Log ("B4A scan text = " & scantext)
    Log ("B4A scan format = " & scanformat)


End Sub

The library:

ZxingBarcodeScanner
Author:
Github: Dushyanth Maguluru, Wrapped by: Johan Schoeman
Version: 1
ZxingBarcodeScanner
Events:

  • scan_result (scantext As String, scanformat As String)
Fields:
  • ba As BA
Methods:
  • BringToFront
  • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
  • Initialize (EventName As String)
  • Invalidate
  • Invalidate2 (arg0 As Rect)
  • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • IsInitialized As Boolean
  • RemoveView
  • RequestFocus As Boolean
  • SendToBack
  • SetBackgroundImage (arg0 As Bitmap)
  • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
  • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
  • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
  • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
  • handleResult (rawResult As Result)
  • startScanner
  • stopScanner
  • toggleFlash
Permissions:
  • android.permission.CAMERA
  • android.permission.FLASHLIGHT
Properties:
  • Background As Drawable
  • BorderColor As Int [write only]
  • BorderLineLength As Int [write only]
  • BorderStrokeWidth As Int [write only]
  • Color As Int [write only]
  • Enabled As Boolean
  • Height As Int
  • LaserColor As Int [write only]
  • Left As Int
  • MaskColor As Int [write only]
  • Tag As Object
  • Top As Int
  • Visible As Boolean
  • Width As Int
 

Attachments

  • ZxingBarcodeScannerLibFiles.zip
    22.5 KB · Views: 2,675
  • b4aZxingBarcodeScanner.zip
    9.9 KB · Views: 2,544
Last edited:

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

"Brightness" by the fudge's formula will be 0 if all rrr, ggg, bbb are 0 - i.e. total black.

And 1 if all rrr, ggg, bbb are 255 - i.e. total white.

On a really sunny day outside I have measured up to about .85

There seem to be any number of formulas for brightness - I only picked the one in the fudge because the website I referenced suggested it originated in Photoshop.

You could get it to be 0 - 255 by not dividing by 255, or get it to be a % by multiplying by 100.

For our purposes the exactness of the formula shouldn't matter that much as long as it approximates reality (whatever that is) and the auto-flash threshold is appropriate.

Regards...

PS I feel if you manage to do this you will have the Rolls Royce of barcode library/ies.

PPS Is it possible to find the (Java?) code of the camera app to find out how it turns on auto flash?
 

Johan Schoeman

Expert
Licensed User
Longtime User
I would appreciate your response/s...

Try with the attached project and library - have added control of the flash via the perceived brightness of the frame that gets captured for extraction of a barcode.

B4X:
    zx1.AutoTorchModeLux = False          'ADDED 5 MARCH 2016
   
    zx1.AutoTorchModeBrightness = True    'ADDED 6 MARCH


Code for using the following can cause a clash if not used correctly - leaving it up to you to handle it accordingly in your B4A cocde
zx1.AutoTorchModeBrightness = True/False and zx1.AutoTorchModeLux = True/False and zx1.toggleFlash

zx1.toggleFlash is to control the flash manually (toggle on/off) - in this case the two Booleans should be set to False


B4X:
Sub zx1_ambient_light_changed (ambientLight As Float)             'ADDED 5 MARCH 2016
   
'    Log ("Ambient Light Lux Value = " & ambientLight)             'ADDED 5 MARCH 2016
   
End Sub   


Sub zx1_brightness_changed (brightness As Double)                 'ADDED 6 MARCH 2016
    Log("Brightness = " & brightness)
    If brightness < 0.30 Then zx1.brightnessTurnFlashOn
    If brightness > 0.35 Then zx1.brightnessTurnFlashOff
   
End Sub

zx1.brightnessTurnFlashOn and zx1.brightnessTurnFlashOff will only take effect if zx1.AutoTorchModeBrightness = True

The calculated/perceived brightness values are returned to the B4A project via an Event - use these values to decide when you want to switch on/off the torch and also handle possible flashing of the torch in your B4A code when the values hover around the limits that you test for.

Try and let me know. Only posting the B4A project and the updated B4A lib files (not the other jars) - have not changed the version
 

Attachments

  • ZxingBarcodeScannerBrightLibFiles.zip
    27.6 KB · Views: 447
  • b4aZxingBarcodeScannerBright.zip
    10.3 KB · Views: 415

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,
Try and let me know.
Well you did ask - I excuse the length and detail of the following by suggesting I am a potential serious user of this library (although maybe a lowest-common-denominator one:)).

o Java bug? - looks like there is a Java-ish bug which is easy to reproduce - just modify the zx1_brightness_changed sub in the b4aZxingBarcodeScanner example as follows then compile and run:
B4X:
Sub zx1_brightness_changed (brightness As Double)                 'ADDED 6 MARCH 2016
    Log("Brightness = " & brightness)
    If brightness < 0.30 Then zx1.brightnessTurnFlashOn
    If brightness > 0.35 Then zx1.brightnessTurnFlashOff

    'Add this
    Label1.Text = NumberFormat2(brightness, 1, 3, 3, False)

End Sub
I managed to work around this with a Globals variable to hold the brightness supplied by zx1_brightness_changed and a timer.

o Comment 1 - the LowerLuxLimit/UpperLuxLimit/AutoTorchModeLux "features" are confusing, and totally irrelevant as they are with respect to the light conditions on the wrong side of the phone.

If someone wants to reproduce what the native ZXing app does (why I don't know) they can easily do so with Phone.PhoneSensors.TYPE_LIGHT (I did it some time ago in about 10 minutes).

o Comment 2 - the brightnessTurnFlashOn/brightnessTurnFlashOff "features" are confusing relative to toggelFlash.

o Comment 3 - AutoTorchModeBrightness seems you have to set this once for the duration of the app instances life.

o Comment 4 - toggleFlash is deficient - you have to maintain your own torch state flag which is tedious - particularly with the other torch on/off controls.

o Suggestion - get rid of all the torch stuff and replace with something like:

BrightnessMode - a simple get/set property that just turns on or off a "brightness stream" to a ..._brightness_changed event. Make sure it can be turned on/off whenever.

TorchState - a simple get/set property that just turns the torch on or off - but also gives the torch state if needed.

These cover all the requirements and are bog-simple to understand.

Johan, my apologies again, I seem to be channelling my days as a software architect...

BTW - if you did the TorchState thing you would just replace toggleFlash with TorchState = Not(TorchState) - but always know the torch state.
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
o Java bug? - looks like there is a Java-ish bug which is easy to reproduce - just modify the zx1_brightness_changed sub in the b4aZxingBarcodeScanner example as follows then compile and run:
B4X:
Sub zx1_brightness_changed (brightness As Double)                 'ADDED 6 MARCH 2016
    Log("Brightness = " & brightness)
    If brightness < 0.30 Then zx1.brightnessTurnFlashOn
    If brightness > 0.35 Then zx1.brightnessTurnFlashOff

    'Add this
    Label1.Text = NumberFormat2(brightness, 1, 3, 3, False)

End Sub

That was solved here https://www.b4x.com/android/forum/threads/solved-strange-error.64329/ but I have not posted the updated library files yet. Still requires some panel beating based on your other comments. Will post updated library files once we have found a working solution for using the brightness to control the torch with
 

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

I did a bit of research on YUV - have a look at the new tricked up CameraEx example attached, particularly the Camera1_Preview sub I have added which gives ability to do real time brightness (with same results as first trick/fudge):
B4X:
Sub Camera1_Preview(Data() As Byte)
    'Data is apparently YUV, the first 2/3rds of which is Y (luma component - brightness)
    'See https://www.b4x.com/android/forum/threads/camera-image-data-access-overview.43589/#post-265241
    'Y is 1 byte per pixel and is signed - so must be converted to unsigned, see:
    'https://www.b4x.com/android/forum/threads/unsigned-variable-types.30911/#post-179784
   
    If DateTime.Now - last_brightness < 1000 Then Return
   
    last_brightness = DateTime.Now
   
    Dim iii As Long
    Dim brightness As Double
   
    For iii = 0 To Data.Length * 2 / 3 - 1
        brightness = brightness + Bit.And(0xFF, Data(iii))
    Next
   
    'Average
    brightness = brightness / iii / 255
   
    Log(DateTime.Now & " " & brightness)
   
End Sub
Regards...
 

Attachments

  • JKCameraEx2.zip
    13.2 KB · Views: 374

Johan Schoeman

Expert
Licensed User
Longtime User
Johan,

Well you did ask - I excuse the length and detail of the following by suggesting I am a potential serious user of this library (although maybe a lowest-common-denominator one:)).

o Java bug? - looks like there is a Java-ish bug which is easy to reproduce - just modify the zx1_brightness_changed sub in the b4aZxingBarcodeScanner example as follows then compile and run:
B4X:
Sub zx1_brightness_changed (brightness As Double)                 'ADDED 6 MARCH 2016
    Log("Brightness = " & brightness)
    If brightness < 0.30 Then zx1.brightnessTurnFlashOn
    If brightness > 0.35 Then zx1.brightnessTurnFlashOff

    'Add this
    Label1.Text = NumberFormat2(brightness, 1, 3, 3, False)

End Sub
I managed to work around this with a Globals variable to hold the brightness supplied by zx1_brightness_changed and a timer.

o Comment 1 - the LowerLuxLimit/UpperLuxLimit/AutoTorchModeLux "features" are confusing, and totally irrelevant as they are with respect to the light conditions on the wrong side of the phone.

If someone wants to reproduce what the native ZXing app does (why I don't know) they can easily do so with Phone.PhoneSensors.TYPE_LIGHT (I did it some time ago in about 10 minutes).

o Comment 2 - the brightnessTurnFlashOn/brightnessTurnFlashOff "features" are confusing relative to toggelFlash.

o Comment 3 - AutoTorchModeBrightness seems you have to set this once for the duration of the app instances life.

o Comment 4 - toggleFlash is deficient - you have to maintain your own torch state flag which is tedious - particularly with the other torch on/off controls.

o Suggestion - get rid of all the torch stuff and replace with something like:

BrightnessMode - a simple get/set property that just turns on or off a "brightness stream" to a ..._brightness_changed event. Make sure it can be turned on/off whenever.

TorchState - a simple get/set property that just turns the torch on or off - but also gives the torch state if needed.

These cover all the requirements and are bog-simple to understand.

Johan, my apologies again, I seem to be channelling my days as a software architect...

BTW - if you did the TorchState thing you would just replace toggleFlash with TorchState = Not(TorchState) - but always know the torch state.

Here is an update. Please note that I have added the new B4A library files to /Files folder of the attached B4A project. Copy them from there to your additional library folder. You would still need the other two jars that I have posted a Dropbox link to in Post #1 of this thread.

A note or two about this update:
1. The frame that was captured by the library makes a byte array of YUV data available.
2. I have converted the Y channel (i.e the brightness) to have values from 0 to 255 - 0 being pitch black and 255 being totally white.
3. I have extracted every 10th value from the Y channel to calculate an average brightness of the frame that was captured for possible barcode extraction to calculate the average brightness of the frame - I can not see a deterioration in the performance of the scanner as a result of the additional code that I have added to the library.
4. A B4A event is raised that brings back the average frame brightness for every frame that was captured for possible barcode extraction.
5. You can use this brightness value to for eg turn on/off the torch while the scanner is active.
6. How you use this brightness value is up to you. You need to define your own B4A code to control the switching on/off of the torch. To prevent excessive swings I would suggest building a Low Pass Filter into the code of the B4A event to knock down those spikes when a sudden change occurs from dark to light or vice versa. My simple sample code to control the flash looks as follows:

B4X:
Sub zx1_brightness_changed (bright As Int )                        'ADDED 6 MARCH 2016
'    Log("bright = " & bright)                                      'this is the average brightness of the frame that was captured for possible barcode extraction
    flag = flag + 1
    l1.Text = "Brigtness = " & bright
    If flag = 30 Then                                              'I only want to use the average brightness of every 30th frame to calculate a running brigtness average
        flag = 0                                                   'reset the count to zero for the next 30 frames
        If bright < 150 Then                                       'discard excessive high brigness values
            runningavg = (runningavg + bright) / 2
'            Log("runningavg brightness = " & runningavg)
            If runningavg < 70 Then
                If Not(zx1.isFlashOn) Then zx1.TurnFlashOn
            Else if runningavg > 115 Then
                If zx1.isFlashOn Then zx1.TurnFlashOff
            End If   
        End If   
    End If   

   
End Sub

There are 4 methods related to the torch - for flexibility purposes (use them which ever way might suite you)
1. toggleFlash
2. TurnFlashOn
3. TurnFlashOff
4. isFlashOn

I have used them all in the sample project for demonstration purposes.

So,
1. start the app
2. point is to a dark area - the torch should eventually switch on
3. point it to a light area - the torch will eventually switch off

Posting the B4A project only - as mentioned earlier:
1. please note that I have added the new B4A library files to /Files folder of the attached B4A project. Copy them from there to your additional library folder.
2. You also need android-support.v4.jar and core-3.2.1.jar to be in your additional library folder. I have zipped them together and you can download them from this link:https://www.dropbox.com/s/h9ts6cjfoo5et6h/core-3.2.1.zip?dl=0
 

Attachments

  • b4aZxingBarcodeScannerBrightness.zip
    37.9 KB · Views: 434

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

What a bright idea!

I have downloaded and run your new library and example.

The brightness stream is just what the Dr ordered - you're giving a brightness on every frame? and performance is not impacted? - marvellous!

Unfortunately, I appear to have a bug:

(1) get the zx1_brightness_changed code to turn torch on by going into a dark corner.
(2) with torch on, scan a barcode - torch goes out.
(3) stay in dark corner - torch will not come back on again.
(4) if you alter zx1_scan_result sub:
B4X:
Sub zx1_scan_result (scantext As String, scanformat As String)

    Log ("B4A scan text = " & scantext)
    Log ("B4A scan format = " & scanformat)
    l2.Text = scantext & " (type = " & scanformat & ")"

    Log("isFlashOn " & zx1.isflashon)

End Sub
the Log statement will indicate the torch is on when in fact it is off - and this then screws all the torch control up.

Also I find it is a lot harder to get a scan detected in comparison to the native ZXing app - seems to be some sort of focus problem - for reference, I'm using the ZXing app with these settings:

http://www.my24-7laundry.com/customer-app-android-samsungS5.htm

Thanks again...
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Johan,

What a bright idea!

I have downloaded and run your new library and example.

The brightness stream is just what the Dr ordered - you're giving a brightness on every frame? and performance is not impacted? - marvellous!

Unfortunately, I appear to have a bug:

(1) get the zx1_brightness_changed code to turn torch on by going into a dark corner.
(2) with torch on, scan a barcode - torch goes out.
(3) stay in dark corner - torch will not come back on again.
(4) if you alter zx1_scan_result sub:
B4X:
Sub zx1_scan_result (scantext As String, scanformat As String)

    Log ("B4A scan text = " & scantext)
    Log ("B4A scan format = " & scanformat)
    l2.Text = scantext & " (type = " & scanformat & ")"

    Log("isFlashOn " & zx1.isflashon)

End Sub
the Log statement will indicate the torch is on when in fact it is off - and this then screws all the torch control up.

Also I find it is a lot harder to get a scan detected in comparison to the native ZXing app - seems to be some sort of focus problem - for reference, I'm using the ZXing app with these settings:

http://www.my24-7laundry.com/customer-app-android-samsungS5.htm

Thanks again...
It is your bright idea Jack - I am only trying to impliment it. Will sort out the logic in the torch on/off. As for the harder to detect issue - please see if you find a difference between using it in portrait and landscape modes.

The auto focus is handles by the original project and not the wrapper. Will see if I can find something in the code to perhaps change the interval of the auto focus.
 

JackKirk

Well-Known Member
Licensed User
Longtime User
It is your bright idea Jack
Sometimes the ideas are a lot easier to come by than the implementation - I'm having no luck on the B4I front, see:

https://www.b4x.com/android/forum/threads/save-ibarcode-preview-as-a-bitmap.64405/

As for the harder to detect issue - please see if you find a difference between using it in portrait and landscape modes.
Not quite sure what you mean by "see if you find a difference between using it in portrait and landscape modes". Do you mean for portrait mode just to turn the phone so that the barcode is at 90deg to scanner line? In the past I have played with the ZXing settings and allowed it to rotate between portrait and landscape - portrait was abysmal in comparison with landscape (which is what I read elsewhere at the time).
The auto focus is handles by the original project and not the wrapper. Will see if I can find something in the code to perhaps change the interval of the auto focus.
Experimenting further with both ZXing app and your library - it seems to me that the ZXing app changes focus a little slower - which I'm guessing would mean it has a greater chance of doing a detect.

Happy scanning...

Afterthought - if you find some "focus change speed" parameter would it be worth exposing it? - apparently my Android app is compatible with (literally) more than 9000 devices.
 
Last edited:

JackKirk

Well-Known Member
Licensed User
Longtime User

JackKirk

Well-Known Member
Licensed User
Longtime User
Not quite sure what you mean by "see if you find a difference between using it in portrait and landscape modes". Do you mean for portrait mode just to turn the phone so that the barcode is at 90deg to scanner line? In the past I have played with the ZXing settings and allowed it to rotate between portrait and landscape - portrait was abysmal in comparison with landscape (which is what I read elsewhere at the time).
Johan,

Your mention of portrait mode was nagging me.

I responded as above because I had been playing around with your example to see how I would insert it into my app.

I had discovered that you have the example constrained to landscape mode - hence my response because there did not appear to be a proper portrait option.

Now looking at your initial post in this thread I see how to set up portrait mode.

I should have looked more, prattled less...
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Johan,

Looking even closer, it seems the focusing behaviour is quite different - I made a short video...

https://youtu.be/s5WvgcfVM7w
Jack, the default auto focus time is set to 1 second in the original code. I will add some code so that it can be set from within a B4A project. The 1 second in the original code is probably too short an interval.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Sometimes the ideas are a lot easier to come by than the implementation - I'm having no luck on the B4I front, see:

https://www.b4x.com/android/forum/threads/save-ibarcode-preview-as-a-bitmap.64405/


Not quite sure what you mean by "see if you find a difference between using it in portrait and landscape modes". Do you mean for portrait mode just to turn the phone so that the barcode is at 90deg to scanner line? In the past I have played with the ZXing settings and allowed it to rotate between portrait and landscape - portrait was abysmal in comparison with landscape (which is what I read elsewhere at the time).

Experimenting further with both ZXing app and your library - it seems to me that the ZXing app changes focus a little slower - which I'm guessing would mean it has a greater chance of doing a detect.

Happy scanning...

Afterthought - if you find some "focus change speed" parameter would it be worth exposing it? - apparently my Android app is compatible with (literally) more than 9000 devices.
New library files attached that allows setting the auto focus interval from within the B4A code. It will (hopefully) also sort out the logic of the torch. Add this to your B4A code to change the autofocus interval:
B4X:
zx1.AutoFocusInterval = 5000

The default value for the autofocus interval is 1000ms (thus, if you don't specify it in your B4A code it will use a default value of 1000ms)
 

Attachments

  • ZxingBarcodeScanner11Mar16.zip
    27.5 KB · Views: 391

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

Installed the new library from post #33 and ran it against your last example of post #26.

Unfortunately:

(1) The torch control bug I reported at post #27 is still there and reproducible as per that post.
(2) The AutoFocusInterval property works but not as we would want:
  • It lengthens the time between autofocus attempts, not the amount of time it stays in focus.
  • The ZXing native app seems to spend a lot of time in focus every autofocus cycle.
  • By contrast, the autofocussing mechanism in your library seems to just zip thru the "in focus" point - my little video in post #30 illustrates this quite clearly.
  • Is there some sort of "in focus dwell" timing in your library?
Sorry to be the bearer of bad news...
 

JackKirk

Well-Known Member
Licensed User
Longtime User
Johan,

I'm like an old dog with a very tattered bone...

I tried your ZBAR alternative and it seems to behave similarly to the ZXing library.

Another thing I have noticed is that when I fill the barcode preview area with the barcode - a fairly natural thing to do I might add - i.e. phone about 50-75mm from barcode - both ZBAR and ZXing library never focus - whereas ZXing native app has no problems.

Also it seems that the ZXing native app can focus when the phone is placed at a range of distances from the barcode whereas the ZBAR and ZXing libraries seem to have 1 "sweetspot".

Do they all ultimately use the same focussing code? - does it have adjustable parameters???????

-----------------------------------------------

FYI, with the ZXing native app there are a couple of settings (see my post #27) that I have turned on (I don't remember why) that are under the rather ominous heading of "Device Bug Workarounds:" :

No continuous focus (Use only standard focus mode)
No exposure
No metering
No barcode scene mode

Playing around with them it appears (at least for my Samsung S5) that [No metering] must be checked and [No continuous focus] is helpful - couldn't see any benefit from the other 2.

Might be worth checking out?

-----------------------------------------------

Questions, questions ...

EDIT:

Did a bit of googling and came across:

http://osdir.com/ml/zxing/2012-11/msg00360.html
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Johan,

I'm like an old dog with a very tattered bone...

I tried your ZBAR alternative and it seems to behave similarly to the ZXing library.

Another thing I have noticed is that when I fill the barcode preview area with the barcode - a fairly natural thing to do I might add - i.e. phone about 50-75mm from barcode - both ZBAR and ZXing library never focus - whereas ZXing native app has no problems.

Also it seems that the ZXing native app can focus when the phone is placed at a range of distances from the barcode whereas the ZBAR and ZXing libraries seem to have 1 "sweetspot".

Do they all ultimately use the same focussing code? - does it have adjustable parameters???????

-----------------------------------------------

FYI, with the ZXing native app there are a couple of settings (see my post #27) that I have turned on (I don't remember why) that are under the rather ominous heading of "Device Bug Workarounds:" :

No continuous focus (Use only standard focus mode)
No exposure
No metering
No barcode scene mode

Playing around with them it appears (at least for my Samsung S5) that [No metering] must be checked and [No continuous focus] is helpful - couldn't see any benefit from the other 2.

Might be worth checking out?

-----------------------------------------------

Questions, questions ...

EDIT:

Did a bit of googling and came across:

http://osdir.com/ml/zxing/2012-11/msg00360.html
Jack, attached a new B4A project and new B4A library files:
1. The torch should now be sorted out
2. Select the focus mode that will suite you best (5 options to choose from)
B4X:
zx1.FocusMode = zx1.FOCUS_MODE_CONTINUOUS_PICTURE
3. I have borrowed the following from Zxing and changed the CameraPreview class of the original Github project (for ZXING only) to accommodate them:
B4X:
setFocusArea
setVideoStabilization
setBestPreviewFPS
setBestExposure
The above methods are not exposed to B4A - they are hard coded in the CameraPreview class

I did not add setMetering as it makes the pic too dark when the torch is on and one tries to scan a barcode (especially from a computer/device screen). Unless the torch logic is still problematic I am not going to make any further changes to this project. The original project has now changed beyond recognition and my initial intention was to merely wrap the original project so that it could be used inside B4A (i.e not being started via an intent) allowing you to set the look of your activity to whatever you want it to look like. I don't want to rewrite the Zxing project. The CameraPreview class is not the original Zxing class - seems to me that everyone that builds a project around the Zxing core creates their own CameraPreview class that does not include all of the features in the original Zxing CameraConfigurationUtils class.

The brightness feature is a "bright" addition - thanks to you and thanks for all your advise to sort it out!

Please let me have your feedback on the additions i.e does it make a difference / no difference. If none then it will be a futile exercise to add it to the ZBAR project.
 

Attachments

  • b4aZxingBarcodeScanner12032016.zip
    10.6 KB · Views: 356
  • ZxingBarcodeScannerLib12032016.zip
    30.5 KB · Views: 356
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Attached library (change) requested by @JackKirk - killed the sound that is generated by the lib upon a successful scan (you can add a sound via the B4A code if you want to "make a sound"
 

Attachments

  • ZxingBarcodeScannerSoundKilled.zip
    30.4 KB · Views: 349

Johan Schoeman

Expert
Licensed User
Longtime User
Attached library (change) also requested by @JackKirk - killed all the Java Logs (in the original code) and removed dependency on colors.xml and strings.xml (they are no longer required in the /Objects/res/values folder of the B4A project)
 

Attachments

  • ZxingBarcodeScannerLogColorStringKilled.zip
    29.5 KB · Views: 420
Top