Reputation: 119
I am using Microsoft vision api for reading the texts from image. It is working fine with my Samsung phone(OS: Android M), Lenovo K4 Note(OS: Android M).
I have one other phone of Sharp AQUOS(OS: Nougat). In this phone the text recognizing is getting failed. The vision api returns this Exception,
VisionServiceException: Error executing POST request! Received error code: 400
Anybody faced this problem? Please suggest me a solution.
My code is giving below.
Bitmap bitmap = CustomCameraStore.getInstance().getBitmap1();
ByteArrayOutputStream output = new ByteArrayOutputStream(bitmap.getByteCount());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
ByteArrayInputStream inputStream = new ByteArrayInputStream(output.toByteArray());
OCR ocr = visionClient.recognizeText(inputStream, LanguageCodes.AutoDetect, true);
String result = gsonObject.toJson(ocr);
Upvotes: 0
Views: 102
Reputation: 119
I have found the reason for my question. This exception was caused due to the large size of image that i have posting to the vision api. I reached this point by the help of this blog, the link is giving below, https://westus.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fc
I have reduced the quality variable for compressing the bitmap. Below shows the code.
Bitmap bitmap = CustomCameraStore.getInstance().getBitmap1();
ByteArrayOutputStream output = new ByteArrayOutputStream(bitmap.getByteCount());
bitmap.compress(Bitmap.CompressFormat.JPEG, 70, output);
ByteArrayInputStream inputStream = new ByteArrayInputStream(output.toByteArray());
OCR ocr = visionClient.recognizeText(inputStream, LanguageCodes.AutoDetect, true);
String result = gsonObject.toJson(ocr);
It was really sad thing that downvoted this question with out any comment.. Anyway no worries. I am putting this answer for whomever it may helpful.
Upvotes: 3