android - 使用机器学习套件从位图中读取条形码信息
问题描述
我想使用我的相机从条形码中获取一些信息。当我使用从网站下载的 png 图像时它可以工作,但是当我尝试让它与我拍摄的照片一起工作时,它会输出空数组。似乎我需要对图像进行一些准备才能使其正常工作。这是我的代码:
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)
}
}
这就是我从相机获取图像的方式
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)
}
}
编辑:
我用我的手机拍了一张照片,把它缩小到 1500x1000px 并把它放在我的应用程序目录中,然后将它作为位图加载。还是行不通。
解决方案
您使用的方法只会给您返回照片的缩略图(根据https://developer.android.com/training/camera/photobasics)......这可能不足以满足您的要求。该链接还包含有关如何访问全尺寸照片的信息。
推荐阅读
- javascript - 如何在 Odoo 14 中搜索 res.partner 记录
- python - 使用 Selenium python 滚动特定的 Web 元素
- c# - asp-append='true' 添加一些随机值以在 asp dotnet core 3.1 中输入脚本标记
- json - 在 Postgres 中更新包含 JSON 数组数据的文本变量
- nginx - Kubernetes nginx 入口 https 问题
- wso2 - WS2 SP 4.4-HA 故障转移问题
- r - 如何用 4 组绘制 geom_line 以及如何在没有数据的情况下限制 x 轴
- javascript - 删除 Select2 必填字段动态
- macos - 在 mac 上阻止应用程序
- python - 将平面文件上传到 Azure 存储帐户