Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scanner improvements - added the logic from original zxing android project to set the best camera settings #789

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

vkalyanapu
Copy link

I added improvements for scanner for android library

  1. Set the default focus area
  2. Set the best exposure and metering area to the middle of the device (a rectangular area in the middle)
  3. use that area to crop the actual image taken from device to decode the barcode image (lessen the processing time, this improvement is more than 1/4 compared to the original processing time.)
  4. This code is based on the original zxing android project changes.

Improvement for scanning
Scanner improvement for auto focus. Setting the auto focus to rectangle
Updated credits for the file
@knocte
Copy link
Contributor

knocte commented Nov 15, 2018

Your PR states the what but not the why. Why are these changes needed? What do they accomplish?

@vkalyanapu
Copy link
Author

Your PR states the what but not the why. Why are these changes needed? What do they accomplish?

The issue is with the scanner performance on certain chemical resistant papers. It takes a significant amount of the time (~10 - 30 secs) to scan a barcode. This is reproducible all the time. This degraded behavior makes app unusable. I compared the google's zxing - play store app vs app using Redth/zxing library, zxing's app is scanning on the mark while my app using Redth/zxing library is below par and sometimes not scanning the barcode at all, which makes app unusable.

@knocte
Copy link
Contributor

knocte commented Nov 19, 2018

@vkalyanapu that's a much better description! can you add it to the commit messages too? otherwise in the future only the what would be discovered by git blame, and not the why :)

foreach (var fpsRange in parameters.SupportedPreviewFpsRange)
{
if (fpsRange[0] <= selectedFps[0] && fpsRange[1] > selectedFps[1])
if (fpsRange[1] > selectedFps[1] || fpsRange[1] == selectedFps[1] && fpsRange[0] < selectedFps[0])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you walk through the logic here please? I'm thinking it might help to use some more parenthesis and add some comments in the code here to explain it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the suggestion from - #395 (comment)

I agree that the line 306 needs an improvement -
Basically the issue with old line - 253 is that it is selecting the bottom value in the range.

New line should be something like =>
if (fpsRange[1] >= selectedFps[1] && fpsRange[0] < selectedFps[0])

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

if (fpsRange[0] < selectedFps[0] && fpsRange[1] >= selectedFps[1])

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is kind of interesting. Probably this issue is right and should pick something with a range from the lowest to the highest.

I think your idea for the logic is probably ok:

if (fpsRange[1] >= selectedFps[1] && fpsRange[0] < selectedFps[0])

This should loop through and keep looking for the widest range... In the case of #395 this logic would end up choosing the 15000,30000 which I think is a good result.

Copy link
Owner

@Redth Redth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the general ideas here, but I'm a bit hesitant to make the center framing the default. I'm not sure in practice if this is ideal or not. I lean towards yes, but there may be some who expect scanning to work outside of this middle frame. I'm also wondering if the ratios and min/max settings are ideal for this or not.

I'm thinking we should at least have a setting to disable the scanning only inside the frame.

@Redth Redth changed the base branch from master to dev December 13, 2018 15:04
@vkalyanapu
Copy link
Author

I agree, there should be a configuration parameter to set the range. And default will scan entire screen.

@Redth
Copy link
Owner

Redth commented Dec 13, 2018

@vkalyanapu are you able to fix that one line of logic as discussed as well as create some sort of configuration parameter(s) for the frame size/range?

@vkalyanapu
Copy link
Author

I need to work on the configuration parameter yet.

@GiampaoloGabba
Copy link

Trying this pull request and the scanning performance in Android is much better.
Great work so far.

GiampaoloGabba added a commit to GiampaoloGabba/ZXing.Net.Mobile that referenced this pull request Apr 30, 2019
else if (Build.VERSION.SdkInt >= BuildVersionCodes.IceCreamSandwich &&
supportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousPicture))
parameters.FocusMode = Camera.Parameters.FocusModeContinuousPicture;
else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeContinuousVideo))
parameters.FocusMode = Camera.Parameters.FocusModeContinuousVideo;
else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeAuto))
parameters.FocusMode = Camera.Parameters.FocusModeAuto;
else if (supportedFocusModes.Contains(Camera.Parameters.FocusModeFixed))
parameters.FocusMode = Camera.Parameters.FocusModeFixed;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing order of focus selection has completely broke scanner autofocus on my device (Vernee thor).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants