I'm using Jim Bennett's "OnDeviceImageClassification" plugin, to try to classify an image taken by a Camera Custom Renderer I did. The problem is, that when it gets to classifying the image taken from the stream:var tags = await CrossImageClassifier.Current.ClassifyImage(fileStream);
, It crashes.
Visual Studio 19, throws "Failed to classify image - check the inner exception for more details"
Here's the complete error:
Xam.Plugins.OnDeviceCustomVision.ImageClassifierException Mensaje = Failed to classify image - check the inner exception for more details Origen = mscorlib Seguimiento de la pila: at Xam.Plugins.OnDeviceCustomVision.ImageClassifierImplementation.ClassifyImage (System.IO.Stream imageStream) [0x00184] in <377ca536dcf942e7853c2239a662e7b2>:0 at CustomRenderer.Droid.CameraPageRenderer.TakePhotoButtonTapped (System.Object sender, System.EventArgs e) [0x001cf] in C:\tensorflow1\CC + IA\XamarinCameraRender-master\CustomRenderer\CustomRenderer.Android\CameraPageRenderer.cs:263 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at Android.App.SyncContext+<>c__DisplayClass2_0.b__0 () [0x00000] in <55654ebe9f2a48e6bade2862bb243f94>:0 at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in <55654ebe9f2a48e6bade2862bb243f94>:0 at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <55654ebe9f2a48e6bade2862bb243f94>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.1(intptr,intptr)
This is the complete method where the image is created, streamed and classified:
async void TakePhotoButtonTapped(object sender, EventArgs e)
{
camera.StopPreview();
var context = this.Context;
var image = textureView.Bitmap;
try
{
var absolutePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;
var folderPath = absolutePath;
filePath = System.IO.Path.Combine(folderPath, string.Format("photo_{0}.jpg", Guid.NewGuid()));
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(@" ", ex.Message);
}
var fileStream = new FileStream(filePath, FileMode.Create);
await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 25, fileStream);
var intent = new Android.Content.Intent(Android.Content.Intent.ActionMediaScannerScanFile);
var file = new Java.IO.File(filePath);
var uri = Android.Net.Uri.FromFile(file);
intent.SetData(uri);
MainActivity.Instance.SendBroadcast(intent);
var tags = await CrossImageClassifier.Current.ClassifyImage(fileStream);
var result = tags.OrderByDescending(t => t.Probability).First().Tag;
resultText.Text = result;
This is the output log:
06-26 19:04:45.641 D/skia (24234): --- Failed to create image decoder with message 'unimplemented' 06-26 19:04:45.671 D/DRM/DcfDecoder(24234): decodeDrmImageIfNeeded with stream 06-26 19:04:45.672 D/DRM/DcfDecoder(24234): decodeDrmImageIfNeeded: [0][0][0][0][0] 06-26 19:04:45.672 D/DRM/DcfDecoder(24234): decodeDrmImageIfNeeded: headerSize = 0 06-26 19:04:45.673 D/DRM/DcfDecoder(24234): isDrmFile: version is not dcf version 1, no oma drm file Xam.Plugins.OnDeviceCustomVision.ImageClassifierException: 'Failed to classify image - check the inner exception for more details'