1
votes

i used google cloud vision api.

i want recognize only certain parts of the image

and ocr analysis through coordinate input.. (if I found the coordinates in the image)

not in the google example.

is it possible?

1

1 Answers

0
votes

Yes it can be possible, here i leave a part of code that you can try, The main thing is to find the vertex "x" and "y" of the fields you are trying to work with.

try (ImageAnnotatorClient client = ImageAnnotatorClient.create()) {
        BatchAnnotateImagesResponse response = client.batchAnnotateImages(requests);
        List<AnnotateImageResponse> responses = response.getResponsesList();

        for (AnnotateImageResponse res : responses) {
            if (res.hasError()) {
                System.out.format("Error: %s%n", res.getError().getMessage());
                return;
            }

            for (int i = 0; i < res.getTextAnnotationsCount(); i++) {
                EntityAnnotation annotation = res.getTextAnnotations(i);
                if (i > 0) {
                    descriptionText = annotation.getDescription().replaceAll("\\s+", "").trim();
                    System.out.println("Text--> " + descriptionText);

                    for (int x = 0; x < annotation.getBoundingPoly().getVerticesCount(); x++) {
                        xvertice = annotation.getBoundingPoly().getVertices(x).getX();
                        yvertice = annotation.getBoundingPoly().getVertices(x).getY();

                        System.out.println("X--> " + xvertice);
                        System.out.println("Y--> " + yvertice);
                        System.out.println("<---------------->");
                    }

                    /*
                     * for (int xx = 0; xx <
                     * annotation.getBoundingPoly().getNormalizedVerticesCount(); xx++) { xp =
                     * annotation.getBoundingPoly().getNormalizedVertices(xx).getX(); yy =
                     * annotation.getBoundingPoly().getNormalizedVertices(xx).getY();
                     * 
                     * System.out.println("X--> " + xp); System.out.println("Y--> " + yy);
                     * System.out.println("<---------------->"); }
                     */

                }
            }
        }