[enter image description here][1]I have been trying to consume azure cognitive 'face detect' service. While passing the image as a url I am able to get a positive response from service, but when passing after converting the image in bytes the service does throw error: { "code": "InvalidImageSize", "message": "Image size is too small." } I did made sure (in debug mode) byte size after conversion was 1194Kb, which is well under limit (1Kb to 6Mb). Though I am not sure what I am doing wrong :|
I did tried converting image to bytes in multiple ways but all went in vain.
My ultimate aim is: instead of reading image from local, I need to accept a base64 representation of image and call this face detect service.
Any help would be much appreciated, thank you.
String photo = "C:\\dev\\check.jpeg";
try {
byte[] readAllBytes = Files.readAllBytes(Paths.get(photo));
ByteArrayEntity reqEntity = new ByteArrayEntity(readAllBytes, ContentType.APPLICATION_OCTET_STREAM);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.set("Ocp-Apim-Subscription-Key", "xxxxxxxxxxxx");
Map<String, String> params = new HashMap<>();
params.put("returnFaceId", "true");
params.put("recognitionModel", "recognition_02");
params.put("detectionModel", "detection_02");
ResponseEntity<List<DetectFaceRes>> exchange = restTemplateFaceApiService.exchange(getUri(DETECT_FACE.getMapping()), HttpMethod.POST, new HttpEntity<>(reqEntity, headers), new ParameterizedTypeReference<List<DetectFaceRes>>(){}, params);
if(responseHasTargetFace(exchange)) {
return exchange.getBody();
}
log.error("some error");
throw someExpception()
}
Error:
{
"code": "InvalidImageSize",
"message": "Image size is too small."
}
[1]: https://i.stack.imgur.com/JJH8U.jpg