5

I am trying to use the Azure Face API on android. I am capturing an image from the device camera and then converting it to an InputStream to be sent to the detect method. I keep getting the error "com.microsoft.projectoxford.face.rest.ClientException: Image size is too small"

I checked the documentation and the image size is 1.4Mb which is within the 1Kb-4Mb range. I don't understand why it isn't working.

Bitmap bitmap = cameraKitImage.getBitmap();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, bos);
bitmapdata = bos.toByteArray();

new FaceTask().execute(new ByteArrayInputStream(bitmapdata));

Face[] faces = faceServiceClient.detect(inputStreams[0], true, false, null);
Amit Maraj
  • 241
  • 3
  • 8
  • This seems to match other coding examples I've seen. Have you verified you are getting valid image data from cameraKitImage? Does it still fail if you use CompressFormat.JPEG? – Pedro Mar 20 '18 at 18:00
  • 2
    Yes, I tried using the JPEG format. I even tried scaling the image to increase the size. Yes I converted the image to an actual image file and opened and it's correct. – Amit Maraj Mar 20 '18 at 19:01
  • Kudos for saving to a file and checking the image! I don't know the API, just thinking aloud, but what is `inputStreams[0]` referring to? If it's an array of `ByteArrayInputStream`s, and the first/only element is meant to be filled in by the `FaceTask().execute(...)` is it a timing problem? (the naming of various bits suggests the `.execute()` might happen in the background. – TripeHound Apr 13 '18 at 11:54
  • inputStreams[0] is an instance of ByteArrayInputStream. Yes this task is performed in the background using AsyncTask. I used the detect method before in another app and never had this problem. How would I solve a timing problem because I'm not sure if it is. – Amit Maraj Apr 14 '18 at 19:28
  • Still no answer to this question? Have anyone found a solution? – Thecave3 Sep 03 '19 at 15:17

1 Answers1

0

Somehow your file is being compressed more than 1Kb or if it is small in actual size already. Try to save it somewhere in the drawable or assets folder and open it in the input stream.

Danish Ahmed
  • 490
  • 5
  • 6