Assigned
Status Update
Comments
ce...@amazon.corp-partner.google.com <ce...@amazon.corp-partner.google.com> #2
Need to mention, the original supported preview size list order is from high to low, then it always choose the highest preview size, to better adapt current algorithm, I sort the size from low to high with below code:
supportedPreviewSizes.sort(Comparator.comparingInt(Camera.Size::hashCode));
supportedPreviewSizes.sort(Comparator.comparingInt(Camera.Size::hashCode));
ra...@google.com <ra...@google.com> #3
Thank you for reporting this issue. For us to further investigate this issue, please provide the following additional information:
Device used
Which device did you use to reproduce this issue?
Android bug report (to be captured after reproducing the issue)
For steps to capture a bug report, please refer:https://developer.android.com/studio/debug/bug-report#bugreportdevice
Alternate method
Navigate to “Developer options”, ensure “USB debugging” is enabled, then enable “Bug report shortcut”. Capture bug report by holding the power button and selecting the “Take bug report” option.
Note: Please upload the bug report to google drive and share the folder to android-bugreport@google.com, then share the link here.
Device used
Which device did you use to reproduce this issue?
Android bug report (to be captured after reproducing the issue)
For steps to capture a bug report, please refer:
Alternate method
Navigate to “Developer options”, ensure “USB debugging” is enabled, then enable “Bug report shortcut”. Capture bug report by holding the power button and selecting the “Take bug report” option.
Note: Please upload the bug report to google drive and share the folder to android-bugreport@google.com, then share the link here.
ce...@amazon.corp-partner.google.com <ce...@amazon.corp-partner.google.com> #4
I tested the case on Tablet, the case is setup wifi through scan QR code.
In this log, the android version is 12, and I removed the preview size list sort and keep the logic same as AOSP, only add some debug log.
log snippet:
Line 3262: 10-25 22:23:45.328 26095 27588 E QrCamera: getBestPreviewSize winRatio w = 720, h = 540, ratio = 0.75
Line 3263: 10-25 22:23:45.328 26095 27588 E QrCamera: getBestPreviewSize supported w = 1920, h = 1080, ratio = 0.5625, bw = 1.0, rw = 0.25
Line 3266: 10-25 22:23:45.328 26095 27588 E QrCamera: getBestPreviewSize best choice w = 1920, h = 1080
Line 3268: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1600, h = 1200, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3271: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1600, h = 896, ratio = 0.56, bw = 0.25, rw = 0.25333333333333324
Line 3273: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1280, h = 960, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3275: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1280, h = 720, ratio = 0.5625, bw = 0.25, rw = 0.25
Line 3278: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1024, h = 768, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3280: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1024, h = 576, ratio = 0.5625, bw = 0.25, rw = 0.25
Line 3282: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 960, h = 720, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3284: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 640, h = 480, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3286: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 320, h = 240, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3288: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 176, h = 144, ratio = 0.8181818181818182, bw = 0.25, rw = 0.09090909090909098
Line 3292: 10-25 22:23:45.329 26095 27588 E QrCamera: preview size w = 1920, h = 1080
debug code snippet:
private Size getBestPreviewSize(Camera.Parameters parameters) {
final double minRatioDiffPercent = 0.1;
final Size windowSize = mScannerCallback.getViewSize();
final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
Log.e(TAG, "getBestPreviewSize winRatio w = " + windowSize.getWidth()
+ ", h = " + windowSize.getHeight() + ", ratio = " + winRatio);
double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
double ratio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize supported w = " + size.width + ", h = " +
size.height + ", ratio = " + ratio +
", bw = " + (Math.abs(bestChoiceRatio - winRatio) / winRatio) +
", rw = " + (Math.abs(ratio - winRatio) / winRatio));
if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
&& (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
|| Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
bestChoice = new Size(size.width, size.height);
bestChoiceRatio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize best choice w = " + size.width
+ ", h = " + size.height);
}
}
return bestChoice;
}
In this log, the android version is 12, and I removed the preview size list sort and keep the logic same as AOSP, only add some debug log.
log snippet:
Line 3262: 10-25 22:23:45.328 26095 27588 E QrCamera: getBestPreviewSize winRatio w = 720, h = 540, ratio = 0.75
Line 3263: 10-25 22:23:45.328 26095 27588 E QrCamera: getBestPreviewSize supported w = 1920, h = 1080, ratio = 0.5625, bw = 1.0, rw = 0.25
Line 3266: 10-25 22:23:45.328 26095 27588 E QrCamera: getBestPreviewSize best choice w = 1920, h = 1080
Line 3268: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1600, h = 1200, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3271: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1600, h = 896, ratio = 0.56, bw = 0.25, rw = 0.25333333333333324
Line 3273: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1280, h = 960, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3275: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1280, h = 720, ratio = 0.5625, bw = 0.25, rw = 0.25
Line 3278: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1024, h = 768, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3280: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 1024, h = 576, ratio = 0.5625, bw = 0.25, rw = 0.25
Line 3282: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 960, h = 720, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3284: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 640, h = 480, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3286: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 320, h = 240, ratio = 0.75, bw = 0.25, rw = 0.0
Line 3288: 10-25 22:23:45.329 26095 27588 E QrCamera: getBestPreviewSize supported w = 176, h = 144, ratio = 0.8181818181818182, bw = 0.25, rw = 0.09090909090909098
Line 3292: 10-25 22:23:45.329 26095 27588 E QrCamera: preview size w = 1920, h = 1080
debug code snippet:
private Size getBestPreviewSize(Camera.Parameters parameters) {
final double minRatioDiffPercent = 0.1;
final Size windowSize = mScannerCallback.getViewSize();
final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
Log.e(TAG, "getBestPreviewSize winRatio w = " + windowSize.getWidth()
+ ", h = " + windowSize.getHeight() + ", ratio = " + winRatio);
double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
for (Camera.Size size : parameters.getSupportedPreviewSizes()) {
double ratio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize supported w = " + size.width + ", h = " +
size.height + ", ratio = " + ratio +
", bw = " + (Math.abs(bestChoiceRatio - winRatio) / winRatio) +
", rw = " + (Math.abs(ratio - winRatio) / winRatio));
if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
&& (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
|| Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
bestChoice = new Size(size.width, size.height);
bestChoiceRatio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize best choice w = " + size.width
+ ", h = " + size.height);
}
}
return bestChoice;
}
ce...@amazon.corp-partner.google.com <ce...@amazon.corp-partner.google.com> #5
Here is my optimized algorithm, then it will select the highest preview size with the ratio very close to window ratio, please help to estimate if it meet your original design.
private Size getBestPreviewSize(Camera.Parameters parameters) {
final double minRatioDiffPercent = 0.1;
final int minPreviewSize = 960 * 720; //can be overlay
final Size windowSize = mScannerCallback.getViewSize();
final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
Log.e(TAG, "getBestPreviewSize winRatio w = " + windowSize.getWidth()
+ ", h = " + windowSize.getHeight() + ", ratio = " + winRatio);
double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
supportedPreviewSizes.sort(Comparator.comparingInt(Camera.Size::hashCode));
for (Camera.Size size : supportedPreviewSizes) {
double ratio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize supported w = " + size.width + ", h = " +
size.height + ", ratio = " + ratio +
", bw = " + (Math.abs(bestChoiceRatio - winRatio) / winRatio) +
", rw = " + (Math.abs(ratio - winRatio) / winRatio));
if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
//&& (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
//|| Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
&& size.height * size.width >= minPreviewSize
&& Math.abs(ratio - winRatio) <= Math.abs(bestChoiceRatio - winRatio)) {
bestChoice = new Size(size.width, size.height);
bestChoiceRatio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize best choice w = " + size.width
+ ", h = " + size.height);
}
}
return bestChoice;
private Size getBestPreviewSize(Camera.Parameters parameters) {
final double minRatioDiffPercent = 0.1;
final int minPreviewSize = 960 * 720; //can be overlay
final Size windowSize = mScannerCallback.getViewSize();
final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
Log.e(TAG, "getBestPreviewSize winRatio w = " + windowSize.getWidth()
+ ", h = " + windowSize.getHeight() + ", ratio = " + winRatio);
double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
supportedPreviewSizes.sort(Comparator.comparingInt(Camera.Size::hashCode));
for (Camera.Size size : supportedPreviewSizes) {
double ratio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize supported w = " + size.width + ", h = " +
size.height + ", ratio = " + ratio +
", bw = " + (Math.abs(bestChoiceRatio - winRatio) / winRatio) +
", rw = " + (Math.abs(ratio - winRatio) / winRatio));
if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
//&& (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
//|| Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
&& size.height * size.width >= minPreviewSize
&& Math.abs(ratio - winRatio) <= Math.abs(bestChoiceRatio - winRatio)) {
bestChoice = new Size(size.width, size.height);
bestChoiceRatio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize best choice w = " + size.width
+ ", h = " + size.height);
}
}
return bestChoice;
ra...@google.com <ra...@google.com> #6
We have shared this with our product and engineering team and will update this issue with more information as it becomes available.
ce...@amazon.corp-partner.google.com <ce...@amazon.corp-partner.google.com> #7
any update?
Description
In my case, the device size ratio is 4:3, while the selected preview size ratio is 16:9, then in the image crop, about half of the image will be discard, then lead to a QR code decode failure.
Android version: android 14
log snippet:
10-24 07:09:25.714 10379 11511 E QrCamera: getBestPreviewSize winRatio w = 479, h = 479, ratio = 1.0
10-24 07:09:25.714 10379 11511 E QrCamera: getBestPreviewSize supported w = 176, h = 144, ratio = 0.8181818181818182, bw = 1.0, rw = 0.18181818181818177
10-24 07:09:25.714 10379 11511 E QrCamera: getBestPreviewSize best choice w = 176, h = 144
10-24 07:09:25.714 10379 11511 E QrCamera: getBestPreviewSize supported w = 320, h = 240, ratio = 0.75, bw = 0.18181818181818177, rw = 0.25
10-24 07:09:25.714 10379 11511 E QrCamera: getBestPreviewSize best choice w = 320, h = 240
10-24 07:09:25.714 10379 11511 E QrCamera: getBestPreviewSize supported w = 640, h = 480, ratio = 0.75, bw = 0.25, rw = 0.25
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 640, h = 480
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 960, h = 720, ratio = 0.75, bw = 0.25, rw = 0.25
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 960, h = 720
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 1024, h = 576, ratio = 0.5625, bw = 0.25, rw = 0.4375
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 1024, h = 768, ratio = 0.75, bw = 0.25, rw = 0.25
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 1024, h = 768
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 1280, h = 720, ratio = 0.5625, bw = 0.25, rw = 0.4375
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 1280, h = 720
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 1280, h = 960, ratio = 0.75, bw = 0.4375, rw = 0.25
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 1280, h = 960
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 1600, h = 896, ratio = 0.56, bw = 0.25, rw = 0.43999999999999995
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 1600, h = 896
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize supported w = 1600, h = 1200, ratio = 0.75, bw = 0.43999999999999995, rw = 0.25
10-24 07:09:25.715 10379 11511 E QrCamera: getBestPreviewSize best choice w = 1600, h = 1200
10-24 07:09:25.716 10379 11511 E QrCamera: getBestPreviewSize supported w = 1920, h = 1080, ratio = 0.5625, bw = 0.25, rw = 0.4375
10-24 07:09:25.716 10379 11511 E QrCamera: getBestPreviewSize best choice w = 1920, h = 1080
10-24 07:09:25.716 10379 11511 E QrCamera: getBestPreviewSize supported w = 2560, h = 1440, ratio = 0.5625, bw = 0.4375, rw = 0.4375
10-24 07:09:25.716 10379 11511 E QrCamera: getBestPreviewSize best choice w = 2560, h = 1440
10-24 07:09:25.716 10379 11511 E QrCamera: preview size set w = 2560, h = 1440
debug code snippet:
private Size getBestPreviewSize(Camera.Parameters parameters) {
final double minRatioDiffPercent = 0.1;
final Size windowSize = mScannerCallback.getViewSize();
final double winRatio = getRatio(windowSize.getWidth(), windowSize.getHeight());
Log.e(TAG, "getBestPreviewSize winRatio w = " + windowSize.getWidth()
+ ", h = " + windowSize.getHeight() + ", ratio = " + winRatio);
double bestChoiceRatio = 0;
Size bestChoice = new Size(0, 0);
List<Camera.Size> supportedPreviewSizes = parameters.getSupportedPreviewSizes();
supportedPreviewSizes.sort(Comparator.comparingInt(Camera.Size::hashCode));
for (Camera.Size size : supportedPreviewSizes) {
double ratio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize supported w = " + size.width + ", h = " +
size.height + ", ratio = " + ratio +
", bw = " + (Math.abs(bestChoiceRatio - winRatio) / winRatio) +
", rw = " + (Math.abs(ratio - winRatio) / winRatio));
if (size.height * size.width > bestChoice.getWidth() * bestChoice.getHeight()
&& (Math.abs(bestChoiceRatio - winRatio) / winRatio > minRatioDiffPercent
|| Math.abs(ratio - winRatio) / winRatio <= minRatioDiffPercent)) {
bestChoice = new Size(size.width, size.height);
bestChoiceRatio = getRatio(size.width, size.height);
Log.e(TAG, "getBestPreviewSize best choice w = " + size.width
+ ", h = " + size.height);
}
}
return bestChoice;
}