flutter_tflite
flutter_tflite copied to clipboard
FileNotFoundException on image saved with path_provider
Operating System: Android
Hey,
I'm trying to run the method detectObjectOnImage on a image saved using the path_provider plugin. I'm able to look at the image in the android device and load it in dart with the File() class so I know the image is there. Here is the code and the full exception:
Future<void> predictImage() async{
Directory appDocDir;
appDocDir = await getExternalStorageDirectory();
String picturePath = appDocDir.path + "/fiz_image_2020-09-29 20:49:13.319037.png";
File img = new File(picturePath);
var recognitions = await Tflite.detectObjectOnImage(
path: img.path, // required
model: "SSDMobileNet",
imageMean: 127.5,
imageStd: 127.5,
threshold: 0.4, // defaults to 0.1
numResultsPerClass: 2,// defaults to 5
asynch: true // defaults to true
);
}
Exception has occurred.
PlatformException (PlatformException(Failed to run model, /storage/emulated/0/Android/data/com.example.fiz/files/fiz_image_2020-09-29 20:49:13.319037.png: open failed: ENOENT (No such file or directory), java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.example.fiz/files/fiz_image_2020-09-29 20:49:13.319037.png: open failed: ENOENT (No such file or directory)
at libcore.io.IoBridge.open(IoBridge.java:492)
at java.io.FileInputStream.<init>(FileInputStream.java:160)
at java.io.FileInputStream.<init>(FileInputStream.java:115)
at sq.flutter.tflite.TflitePlugin.feedInputTensorImage(TflitePlugin.java:368)
at sq.flutter.tflite.TflitePlugin.detectObjectOnImage(TflitePlugin.java:565)
at sq.flutter.tflite.TflitePlugin.onMethodCall(TflitePlugin.java:120)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:692)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:335)
at android.os.Looper.loop(Looper.java:183)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
at libcore.io.Linux.open(Native Method)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7542)
at libcore.io.IoBridge.open(IoBridge.java:478)
... 15 more
))
Any ideas?
Same issue here, some suggests using rootBundle to load the image. Maybe you can get it to work?