title: Analize an image taken with a custom camera, with Tensorflow Lite. (Xamarin)
body: <p>It's a cross-platform project in VS 19, but for now, I'm starting with Android.</p>
  
  <p>I have found tons of repos. of apps that open the native camera software of your device and then analyze it, and throw the result. But I want to take that picture, from a custom camera.
  I found <a href="https://github.com/OsmarICancino/XamarinCameraRender" rel="nofollow noreferrer">one</a> in GitHub that could be useful as a base for it, and want to take the image taken by it and pass it through the TF lite model (locally).</p>
  
  <p>The code is pretty straight forward, this is the part were it take photo action is (Android):</p>
  
  <pre><code>       async void TakePhotoButtonTapped(object sender, EventArgs e)
      {
          camera.StopPreview();
  
          var image = textureView.Bitmap;
  
          try
          {
              var absolutePath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim).AbsolutePath;
              var folderPath = absolutePath + "/Camera";
              var filePath = System.IO.Path.Combine(folderPath, string.Format("photo_{0}.jpg", Guid.NewGuid()));
  
              var fileStream = new FileStream(filePath, FileMode.Create);
              await image.CompressAsync(Bitmap.CompressFormat.Jpeg, 50, fileStream);
              fileStream.Close();
              image.Recycle();
  
              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);
          }
          catch (Exception ex)
          {
              System.Diagnostics.Debug.WriteLine(@"               ", ex.Message);
          }
  
          camera.StartPreview();
      }
  </code></pre>
  
  <p>So, from then, it would open a new activity showing the photo that was taken and the given prediction.</p>
  
  <p>Any idea of how to fetch the image given (taken the path, as passing the bitmap I suppose would be really slow) and (most importantly) make a prediction out of it in the new activity?</p>
  
  <p>I'm basing myself with <a href="https://github.com/Veroni4ka/XamarinTensorFlowApp" rel="nofollow noreferrer">this</a> TFLite project (although, as I said, it opens the native camera) as to code the model.</p>