Reputation: 3582
I want to get some info from barcode using my camera. It works when I use png image downloaded from site, but when I try to get it work with a photo I took, it outputs me the empty array. Seems like I need to make some preps with the image in order to make it work. Here is my code:
fun getTheBarCode(bitmap: Bitmap) {
val options = FirebaseVisionBarcodeDetectorOptions.Builder()
.setBarcodeFormats(
FirebaseVisionBarcode.FORMAT_AZTEC)
.build()
val detector = FirebaseVision.getInstance().getVisionBarcodeDetector(options)
val bm = BitmapFactory.decodeResource(getResources(), R.drawable.barcode) //this is the place where I can load my downloaded barcode to make everything work!
val newBitmap = Bitmap.createScaledBitmap(bitmap, 300, 500, false)
val image = FirebaseVisionImage.fromBitmap(newBitmap)
photoImage.setImageBitmap(newBitmap)
detector.detectInImage(image)
.addOnSuccessListener {
Log.d("Success", "Success")
//empty array here, when I take picture.
}
.addOnFailureListener {
Log.d("Failed", it.message)
}
}
This is how I get the image from the camera
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == CAMERA_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
val photo = data.extras.get("data") as Bitmap
getTheBarCode(photo)
}
}
Edit:
I've take a picture with my phone, scale it down to 1500x1000px and put it inside my app directory, then loaded it as a bitmap. Still not working.
Upvotes: 2
Views: 1311
Reputation: 10330
The approach you're using will only give you back thumbnail of photo (as per https://developer.android.com/training/camera/photobasics) ...that may not be sufficient for what you're trying to do. That link also contains info on how to get access to full size photo.
Upvotes: 1