【发布时间】:2019-03-07 15:24:18
【问题描述】:
我正在开发一个 Android 应用程序来检测 PDF 文件中的文本。
首先,我尝试使用 Google Cloud Vision API。 但它需要 OAuth 2.0。 所以我把它改成了 Firebase ML Kit。
但是当我运行 'fromFilePath' 方法时,发生了 NPE。
val file = getPdfFile()
Log.d(TAG, "file.length: ${file.length()}") // File size is printed correctly!
// NPE occurred while below code running
val image = FirebaseVisionImage.fromFilePath(context, Uri.fromFile(file))
// Because already NPE occurred, I cannot reach out to below code.
val detector = FirebaseVision.getInstance()
.cloudDocumentTextRecognizer
Process: com.youknow.redact, PID: 13122 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
Firebase ML 套件似乎不支持 PDF 文件,对吧?
有什么好的解决办法吗?
是否无法使用 Firebase ML 套件识别 PDF 文件中的文本?
我尝试测试更多文件格式:JPG、TIFF
一切都是一样的,只是输入文件被改变了。 JPG 工作正常,但 TIFF 有同样的问题。
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference
at com.google.android.gms.internal.firebase_ml.zzox.zza(Unknown Source)
at com.google.firebase.ml.vision.common.FirebaseVisionImage.fromFilePath(Unknown Source)
【问题讨论】:
标签: android firebase firebase-mlkit