【发布时间】:2023-03-02 23:31:01
【问题描述】:
我使用了谷歌云视觉 api。
我只想识别图像的某些部分
通过坐标输入进行ocr分析.. (如果我在图像中找到坐标)
不在 google 示例中。
有可能吗?
【问题讨论】:
标签: java coordinates ocr vertices vision-api
我使用了谷歌云视觉 api。
我只想识别图像的某些部分
通过坐标输入进行ocr分析.. (如果我在图像中找到坐标)
不在 google 示例中。
有可能吗?
【问题讨论】:
标签: java coordinates ocr vertices vision-api
是的,有可能,这里我留下一部分代码,你可以试试, 主要是找到您尝试使用的字段的顶点“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("<---------------->"); }
*/
}
}
}
【讨论】: