I am unable to get textrecognizer to work either on emulator or on a device.
Detailed emulation log below:
E E0000 00:00:1724073964.320499 26206 tflite_wrapper.cc:768] INTERNAL: RET_CHECK failure (intelligence/mobile_acceleration/support_library/tflite_wrapper.cc:768) delegate_plugin_ Could not create XNNPack plugin. Have you linked in the XNNPack_plugin target?
Stack trace:
2024-08-19 18:56:04.320 26089-26206 native com.example.cameraimagetotext E E0000 00:00:1724073964.320511 26206 tflite_detector_client_with_shape_cache.cc:193] Failure during initialization of interpreter.
2024-08-19 18:56:04.315 26089-26207 libc com.example.cameraimagetotext W Access denied finding property "ro.hardware.chipname"
2024-08-19 18:56:04.315 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.315292 26207 resource_manager.cc:23] Number of optimal threads: 1
2024-08-19 18:56:04.315 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.315438 26206 text_detector_thread_pool_context.cc:38] Compute manager max in flight region detector overwrite: 1
2024-08-19 18:56:04.315 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.315488 26206 common_util.h:41] Resizing Thread Pool: ocr_det_0 to 3
2024-08-19 18:56:04.315 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.315826 26207 text_classifier.cc:32] Creating classifier TfliteTextClassifier
2024-08-19 18:56:04.315 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.315864 26207 common_util.h:41] Resizing Thread Pool: ocr_segm to 3
2024-08-19 18:56:04.316 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:04.317 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:04.317 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.317149 26206 tflite_detector_client_with_shape_cache.cc:76] Interpreter threads: 1
2024-08-19 18:56:04.320 26089-26206 native com.example.cameraimagetotext E E0000 00:00:1724073964.320499 26206 tflite_wrapper.cc:768] INTERNAL: RET_CHECK failure (intelligence/mobile_acceleration/support_library/tflite_wrapper.cc:768) delegate_plugin_ Could not create XNNPack plugin. Have you linked in the XNNPack_plugin target?
Stack trace:
2024-08-19 18:56:04.320 26089-26206 native com.example.cameraimagetotext E E0000 00:00:1724073964.320511 26206 tflite_detector_client_with_shape_cache.cc:193] Failure during initialization of interpreter.
2024-08-19 18:56:04.320 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.320514 26206 compute_resource_manager.cc:196] remove resource 0 from compute resource list
2024-08-19 18:56:04.320 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.320694 26206 tflite_detector_client_base.cc:352] Resizing interpreter pool to 4
2024-08-19 18:56:04.320 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.320901 26207 tflite_lstm_client_base.cc:371] Resizing interpreter pool to 4
2024-08-19 18:56:04.325 26089-26207 tflite com.example.cameraimagetotext I Initialized TensorFlow Lite runtime.
2024-08-19 18:56:04.326 26089-26206 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.327 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.328 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.332 26089-26206 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.332 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.335 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.336 26089-26207 libc com.example.cameraimagetotext W Access denied finding property "ro.hardware.chipname"
2024-08-19 18:56:04.336 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.336 26089-26206 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.337 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.339 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.341 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.341 26089-26206 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.341 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.341755 26206 multi_pass_line_recognition_mutator.cc:342] Preloading recognizers.
2024-08-19 18:56:04.342 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.342363 26207 tflite_model_pooled_runner.cc:625] Loading mlkit-google-ocr-models/gocr/layout/line_splitting_custom_ops/model.tflite
2024-08-19 18:56:04.343 26089-26216 native com.example.cameraimagetotext I I0000 00:00:1724073964.342624 26216 tflite_model_pooled_runner.cc:625] Loading mlkit-google-ocr-models/gocr/gocr_models/line_recognition_legacy_mobile/Latn_ctc/optical/conv_model.fb
2024-08-19 18:56:04.344 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.344147 26207 tflite_model_pooled_runner.cc:836] Resizing interpreter pool to 1
2024-08-19 18:56:04.344 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:04.344 26089-26216 native com.example.cameraimagetotext I I0000 00:00:1724073964.344669 26216 tflite_model_pooled_runner.cc:636] Loading mlkit-google-ocr-models/gocr/gocr_models/line_recognition_legacy_mobile/Latn_ctc/optical/lstm_model.fb
2024-08-19 18:56:04.349 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.349 26089-26216 native com.example.cameraimagetotext I I0000 00:00:1724073964.349393 26216 tflite_model_pooled_runner.cc:836] Resizing interpreter pool to 4
2024-08-19 18:56:04.349 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.349434 26207 tflite_model_pooled_runner.cc:625] Loading mlkit-google-ocr-models/gocr/layout/line_clustering_custom_ops/model.tflite
2024-08-19 18:56:04.349 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.350 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.350 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.350 26089-26207 native com.example.cameraimagetotext I I0000 00:00:1724073964.350612 26207 tflite_model_pooled_runner.cc:836] Resizing interpreter pool to 1
2024-08-19 18:56:04.358 26089-26207 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.358 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.359 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.366 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.367 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.369 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.375 26089-26216 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:04.375 26089-26216 native com.example.cameraimagetotext I I0000 00:00:1724073964.375207 26216 mobile_langid_v2.cc:58] MobileLangID V2 initialized.
2024-08-19 18:56:04.375 26089-26216 native com.example.cameraimagetotext I I0000 00:00:1724073964.375231 26216 multi_pass_line_recognition_mutator.cc:364] Finished preloading a recognizer for "Latn"
2024-08-19 18:56:04.375 26089-26206 native com.example.cameraimagetotext I I0000 00:00:1724073964.375249 26206 multi_pass_line_recognition_mutator.cc:398] Finished preloading recognizers.
2024-08-19 18:56:04.377 26089-26109 native com.example.cameraimagetotext I I0000 00:00:1724073964.377878 26109 scheduler.cc:693] ImageMetadata: 400x400
2024-08-19 18:56:06.435 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:06.440 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:06.461 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:06.465 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:06.473 26089-26089 TfLite com.example.cameraimagetotext I Usage reporting not opted in -- dropping log event 3 status code 1
2024-08-19 18:56:06.478 26089-26206 TFLite-in-PlayServices com.example.cameraimagetotext I Created interpreter.
2024-08-19 18:56:06.506 26089-26105 TransportR...EventStore com.example.cameraimagetotext D Storing event with priority=VERY_LOW, name=FIREBASE_ML_SDK for destination cct
2024-08-19 18:56:06.513 26089-26105 TransportR...oScheduler com.example.cameraimagetotext D Upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) is already scheduled. Returning...
2024-08-19 18:56:06.519 26089-26105 TransportR...EventStore com.example.cameraimagetotext D Storing event with priority=VERY_LOW, name=FIREBASE_ML_SDK for destination cct
2024-08-19 18:56:06.521 26089-26105 TransportR...oScheduler com.example.cameraimagetotext D Upload for context TransportContext(cct, VERY_LOW, MSRodHRwczovL2ZpcmViYXNlbG9nZ2luZy5nb29nbGVhcGlzLmNvbS92MGNjL2xvZy9iYXRjaD9mb3JtYXQ9anNvbl9wcm90bzNc) is already scheduled. Returning...
2024-08-19 18:56:08.044 26089-26320 ProfileInstaller com.example.cameraimagetotext D Installing profile for com.example.cameraimagetotext
2024-08-19 18:56:54.306 26089-26105 TransportR...ortBackend com.example.cameraimagetotext D Making request to: https://firebaselogging.googleapis.com/v0cc/log/batch?format=json_proto3
2024-08-19 18:56:54.382 26089-26105 TrafficStats com.example.cameraimagetotext D tagSocket(5) with statsTag=0xffffffff, statsUid=-1
2024-08-19 18:56:54.571 26089-26105 TransportR...ortBackend com.example.cameraimagetotext I Status Code: 200
2024-08-19 18:56:54.572 26089-26105 TransportR...ortBackend com.example.cameraimagetotext I Content-Type: application/json; charset=UTF-8
2024-08-19 18:56:54.572 26089-26105 TransportR...ortBackend com.example.cameraimagetotext I Content-Encoding: gzip
On a real device the error is:
2024-08-19 19:03:49.751 26578-26817 GoogleApiManager com.example.cameraimagetotext E Failed to get service from broker.
java.lang.SecurityException: Unknown calling package name 'com.google.android.gms'.
at android.os.Parcel.createExceptionOrNull(Parcel.java:3087)
at android.os.Parcel.createException(Parcel.java:3071)
at android.os.Parcel.readException(Parcel.java:3054)
at android.os.Parcel.readException(Parcel.java:2996)
at m.hv.q(:com.google.android.gms.policy_tflite_dynamite_dynamite@[email protected]:206)
at m.gi.run(:com.google.android.gms.policy_tflite_dynamite_dynamite@[email protected]:54)
at android.os.Handler.handleCallback(Handler.java:958)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:257)
at android.os.Looper.loop(Looper.java:368)
at android.os.HandlerThread.run(HandlerThread.java:67)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val appInfo = packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
appInfo.metaData.putString("com.google.mlkit.vision.DEPENDENCIES", "ocr")
enableEdgeToEdge()
setContent {
CameraImageToTextTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
Greetings(
ctx=this,
name = "Android",
modifier = Modifier.padding(innerPadding)
)
}
}
}
}
}
@Composable
fun Greetings(ctx:Context?, name: String, modifier: Modifier = Modifier) {
Text(
text = recognizeImage(ctx!!),
modifier
)
}
fun recognizeImage(ctx:Context): String
{
val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)
var result:String=""
val image: InputImage
var visionTextReturned: com.google.mlkit.vision.text.Text? = null
val file: File = File("/storage/emulated/0/Download/image.bmp")
val uri: Uri = Uri.fromFile(file)
var modified=0
try {
image = InputImage.fromFilePath (
/* context = */ ctx,
/* imageUri = */ uri
)
} catch (e: IOException) {
e.printStackTrace()
result= "Error" + e.message
return result
}
result +="before"
recognizer.process(image)
.addOnSuccessListener { visionText ->
{
println("successlistener hit ")
modified = 1
visionTextReturned = visionText
result += visionText.text + " was the result" + visionText.textBlocks.toString()
}
}
.addOnFailureListener { e ->
{
modified = 1
result+="Could not convert to text"
}
}
println("test" + modified.toString() + result + "textRet: " + (visionTextReturned?.textBlocks
?: "null"))
result += "after"
println(result)
return result
}
@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
CameraImageToTextTheme {
Greetings(name="Android", ctx=null)
}
}
Learning code to practice image to text