-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[Bug report] NullPointerException
when reading QR code from specific image
#569
Comments
Thanks for the report! Can you share your image with zhouyiself@gmail.com? |
@zhouyiself Sure. The image has been sent. |
This happened to me too, will it be considered a d fixed soon? |
Contacted @AlexV525 by email. Please share the image with me to reproduce this issue. Thanks! |
@AlexV525 Hi, I didn't see your image in the email list. |
|
The root cause is the input Bitmap config is not ARGB_8888, and our engine only supports config ARGB_8888 for Bitmap underneath: https://developer.android.com/reference/android/graphics/Bitmap.Config It works well for streaming mode, i.e. LivePreviewActivity and CameraXLivePreviewActivity We'll consider converting Bitmap config to ARGB_8888 if not internally to fix this issue in later releases. Thanks for reporting this bug! |
BTW, the original input Bitmap config is RGBA_F16 |
|
https://developer.android.com/reference/android/graphics/Bitmap#getConfig() could be used to get the config from bitmap? |
Yes, and it requires a memory allocation to read the actual data in IIRC. |
Workaround with an actual allocation: val mlImage: InputImage
val shouldConvertBitmap: Boolean
var decodedBitmap: Bitmap? = null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
// Decode the bitmap without memory allocation.
val options = BitmapFactory.Options().apply { inJustDecodeBounds = true }
BitmapFactory.decodeFile(path, options)
shouldConvertBitmap = options.outConfig != Bitmap.Config.ARGB_8888
} else {
val bitmap = BitmapFactory.decodeFile(path)
shouldConvertBitmap = bitmap.config != Bitmap.Config.ARGB_8888
// Cache the decoded bitmap.
decodedBitmap = bitmap
}
mlImage = if (shouldConvertBitmap) {
val bitmap = decodedBitmap ?: BitmapFactory.decodeFile(path)
val copiedBitmap = bitmap.copy(Bitmap.Config.ARGB_8888, false)
// Recycle the original bitmap.
bitmap.recycle()
InputImage.fromBitmap(copiedBitmap, 0)
} else {
InputImage.fromFilePath(this, Uri.fromFile(File(path)))
}
// Recycle the decoded bitmap if it exists.
decodedBitmap?.recycle() |
@miworking3 @SilverDestiny This also happened on iOS, so iOS should provide the same ability to convert if images are not |
iOS workaround (I don't use unwrapping here, feel free to modify if it's worth in your code): var image: UIImage? = UIImage.init(contentsOfFile: path)
if (image == nil) {
// Throw something.
}
let fileExtension = URL(fileURLWithPath: path).pathExtension.lowercased()
// Convert all PNG to JPEG to avoid unsupported formats from ML Kit.
if (fileExtension == "png") {
let imageData = image!.jpegData(compressionQuality: 1)
image = UIImage(data: imageData!)
if (image == nil) {
// Throw something.
}
}
let visionImage = VisionImage(image: image!)
visionImage.orientation = image!.imageOrientation |
The latest ML Kit release fixed this issue: https://developers.google.com/ml-kit/release-notes#december_6_2022 |
Describe the bug
When I was trying to read a specific image file that contains a valid QR code, the scanner throws an NPE or is unable to read the data.
To Reproduce
The image contains some personal private info, if it's applicable, please leave an email address then I can send the original image.
Example Steps to reproduce the behavior in the sample app:
SDK Info:
Smartphone:
The text was updated successfully, but these errors were encountered: