【问题标题】:google cloud vision api OCR bounding boxgoogle cloud vision api OCR 边界框
【发布时间】:2023-03-02 23:31:01
【问题描述】:

我使用了谷歌云视觉 api。

我只想识别图像的某些部分

通过坐标输入进行ocr分析.. (如果我在图像中找到坐标)

不在 google 示例中。

有可能吗?

【问题讨论】:

    标签: java coordinates ocr vertices vision-api


    【解决方案1】:

    是的,有可能,这里我留下一部分代码,你可以试试, 主要是找到您尝试使用的字段的顶点“x”和“y”。

    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("<---------------->"); }
                         */
    
                    }
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-25
      • 2016-07-24
      • 2020-10-22
      • 2019-06-07
      相关资源
      最近更新 更多