0

im currently developing Image Classification using xamarin form, the model works well and the prediction result is good, but my problem is, it is only works in PickPhotoAsync passing to MediaFile then the MediaFile > get stream > get the byte > feed to model. i just used this for testing only

What i really need to do is to get the image from SignaturePad > get stream > get the Byte > feed to model

i got wrong prediction when i change it to signaturePad. i hope someone will help me, thank you in advance

here's my code.

   protected async void PickPhotoAsync(object sender, EventArgs e)
    {
        var file = await CrossMedia.Current.PickPhotoAsync();

        HandlePhoto(file);
    }
    private void HandlePhoto(MediaFile file)
    {
        var stream = file.GetStreamWithImageRotatedForExternalStorage();

        var memoryStream = new MemoryStream();

        stream.CopyTo(memoryStream);

        var bytes = memoryStream.ToArray();


        var len = stream.Length;
        var pos = stream.Position;
        var read = stream.CanRead;

        var lens = bytes.Length;

        List<ImageClassificationModel> classifyImage = DependencyService.Get<IClassify>().Classify(bytes); 


        var sortedList = classifyImage.OrderByDescending(x => x.Probability);

        var top = sortedList.First();//Highest Prediction Result 


        var max = sortedList.Max(x => x.Probability);

     


    }


Here is my code when i change it to SignaturePad (Source of image) which i got bad result



  private async void SaveImagePad(object sender, EventArgs e) 
    {
        Stream image = await PadView.GetImageStreamAsync(SignatureImageFormat.Png);
       //get the stream from SignaturePad

        if (image == null)
            return;

        BinaryReader br = new BinaryReader(image);
       
        Byte[] All = br.ReadBytes((int)image.Length);
        byte[] acImage = (byte[])All;

        //Convert To Byte before passing to classifier

        List<ImageClassificationModel> classifyImage = DependencyService.Get<IClassify>().Classify(acImage);
        //File.Delete(path);
        var sortedList = classifyImage.OrderByDescending(x => x.Probability);

        var top = sortedList.First();

        var max = sortedList.Max(x => x.Probability); // i got bad and random result



    }



Chi-
  • 3
  • 1
  • why are you handing the stream completely differently in your two different methods? And what does "bad result" mean specifically? What result do you expect it to return for a signature? Does it work correctly if you pass it a hardcoded sample file containing a signature? – Jason Nov 14 '22 at 12:53
  • i also used the same stream handing like from the first method before, but i got bad result (random probability result from interpreter) it seems he didnt recognize my image byte when i passed it to the classifier. out of frustration i do different stream handing like on my example above.. and my expected result, is to switch my method instead getting the image from my phone directory, the image will be produced by signature pad, just like on my first method when my interpreter recognize the byte came from the photopicker. – Chi- Nov 18 '22 at 16:27

0 Answers0