I am using Google Cloud Vision API for OCR purpose. I am able to connect to the API and getting JSON result back as expected. What baffles me is that while the https://cloud.google.com/vision/ url correctly detects the text in the image, the API call often returns inaccurate text data for the same image. Pl. let me know what could be the case. Sample code is attached.
String url = "https://vision.googleapis.com/v1/images:annotate?key=mykey";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
BufferedImage img = ImageIO.read(new File("F://image.jpg"));
ByteArrayOutputStream baos=new ByteArrayOutputStream();
String fileext = "jpg";
ImageIO.write(img, fileext, baos );
baos.flush();
byte[] imageInByte=baos.toByteArray();
baos.close();
String imgstr = java.util.Base64.getEncoder().encodeToString(imageInByte);
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");