- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将使用 Google Cloud Vision API。
在教程中,它说我需要将图像发送到他们的 Google Cloud Storage,然后通过使用该链接我需要向 API 发出请求。所以该方案如下所示:
手机照片(本地存储)--download--> GC Storage --get link--> 使用此链接发送请求到 GC Vision API --get JSON--> 使用 JSON
所以问题是。我为什么需要将图像存储在云端?只为了一个链接?我可以在不使用 GC 存储的情况下将图像直接发送到 Vision API 吗?所以方案:
手机照片(本地存储)--下载-->到 GC Vision API --获取 JSON--> 使用 JSON
最佳答案
是的,您可以直接将图像发送到视觉 API,如下所示:
package code.logicbeat.vision.controller;
import java.util.Collections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.google.cloud.vision.v1.AnnotateImageRequest;
import com.google.cloud.vision.v1.AnnotateImageResponse;
import com.google.cloud.vision.v1.BatchAnnotateImagesResponse;
import com.google.cloud.vision.v1.EntityAnnotation;
import com.google.cloud.vision.v1.Feature;
import com.google.cloud.vision.v1.Image;
import com.google.cloud.vision.v1.ImageAnnotatorClient;
import com.google.protobuf.ByteString;
@RestController
public class VisionController {
@Autowired
private ImageAnnotatorClient imageAnnotatorClient;
@PostMapping("/vision")
public String uploadImage(@RequestParam("file") MultipartFile file) throws Exception {
byte[] imageBytes = StreamUtils.copyToByteArray(file.getInputStream());
Image image = Image.newBuilder().setContent(ByteString.copyFrom(imageBytes)).build();
// Sets the type of request to label detection, to detect broad sets of
// categories in an image.
Feature feature = Feature.newBuilder().setType(Feature.Type.LABEL_DETECTION).build();
AnnotateImageRequest request = AnnotateImageRequest.newBuilder().setImage(image).addFeatures(feature).build();
BatchAnnotateImagesResponse responses = this.imageAnnotatorClient
.batchAnnotateImages(Collections.singletonList(request));
StringBuilder responseBuilder = new StringBuilder("<table border=\"1\">");
responseBuilder.append("<tr><th>description</th><th>score</th></tr>");
// We're only expecting one response.
if (responses.getResponsesCount() == 1) {
AnnotateImageResponse response = responses.getResponses(0);
if (response.hasError()) {
System.out.println(response.getError());
throw new Exception(response.getError().getMessage());
}
for (EntityAnnotation annotation : response.getLabelAnnotationsList()) {
responseBuilder.append("<tr><td>").append(annotation.getDescription()).append("</td><td>")
.append(annotation.getScore()).append("</td></tr>");
}
}
responseBuilder.append("</table>");
return responseBuilder.toString();
}
}
请检查我的存储库示例的链接以供引用: https://github.com/logicbeat/googlevisionapidemo
关于java - 如何将图像发送到 GCP Vision API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46966332/
我正在从 spring boot maven 项目调用 google vision OCR api 以从图像中提取文本。 public class TestGoogleVision { Buffere
是否可以使用 Google Vision API 读取姓名、地址、出生日期等身份证信息?在文档中,我找到了一些东西,但我不知道如何使用它。 https://developers.google.com/
请看两个测试结果。 有两种语言,但 Cloud vision api 总是以一种语言返回结果。 我们能否告诉图像中需要哪种语言,以便引擎可以尝试识别所有字符,即使它们是不同的语言? 1. 原图有3个汉
如何调用 Vision API 并在图像上应用多个功能。 我想在图像上同时应用标签检测和地标检测 最佳答案 您可以如下定义您的请求,以在每个图像中包含多个功能请求 "requests":[
我正在探索 Cloud Vision API 的功能,我想知道是否有任何方法可以检测标签检测下对象的尺寸。例如,如果您在街上拍摄汽车的照片,则 Cloud Vision API 将返回汽车的尺寸(长度
首先,请原谅我的英语不好。我在里面工作。 我正在从事计算机视觉应用方面的工作。我正在使用网络摄像头。主循环是这样的: while true get frame process
我正在尝试训练一个模型来识别图像中的某些标签。我尝试使用 1 小时免费版本,一小时后培训结束。结果并不像我想要的那么准确,所以我冒险选择了没有定义训练模型的具体时间限制的选项。 此时,它显示“训练视觉
我试图识别的最简单的例子: 我用 DOCUMENT_TEXT_DETECTION ,但在答案中我得到了象形文字。 如果我使用 Eng在 ImageContext addAllLanguageHints
我将其交叉发布到 Cloud Vision 的谷歌组... 并添加了一些额外的发现。 以下是我认为相关的所有细节: 使用 VB.NET 2010 使用服务帐号认证 仅限于 .NET 4.0 使用这些
我正在尝试使用 Google Vision API。我正在关注 getting started guide : 我已启用 Cloud Vision API 我已启用计费 我已经设置了 API key
我对使用Microsoft的认知服务还很陌生。我想知道MS Computer Vision API和MS Custom Vision API有什么区别? 最佳答案 它们都处理图像上的计算机视觉,但是希
知道如何将规范化顶点转换为顶点吗?归一化顶点给出了图像上的相对位置,而顶点根据图像的比例返回坐标。我有一组标准化顶点,我想将其转换为常规顶点。 https://cloud.google.com/vis
我正在使用 google cloud vision api 来分析图片。是否有 labelAnnotations 方法的所有可能响应的列表? 最佳答案 API reference Vision API
Google Cloud Vision API(测试版)的第 1 版允许通过 TEXT_DETECTION 请求进行光学字符识别。虽然识别质量很好,但返回的字符没有任何原始布局的暗示。因此,结构化文本
假设我有图像并且我想用西类牙语为它们生成标签 - Google Cloud Vision API 是否允许选择以哪种语言返回标签? 最佳答案 标签检测 Google Cloud Vision API
我使用 import torchvision 时遇到的错误这是: 错误信息 "*Traceback (most recent call last): File "/Users/gokulsrin/
我正在为 Google Cloud Vision API 使用 Python 客户端,与文档中的代码基本相同 http://google-cloud-python.readthedocs.io/en/
我正在查看 Google AutoML Vision API 和 Google Vision API。我知道,如果您使用 Google AutoML Vision API,那么它就是一个自定义模型,因
我正在查看 Google AutoML Vision API 和 Google Vision API。我知道,如果您使用 Google AutoML Vision API,那么它就是一个自定义模型,因
由于火线相机由于带宽限制而变得过时,相机制造商似乎正在转向 USB 3.0 或千兆以太网接口(interface)。两者都有许多制造商都遵守的标准 USB3 Vision 和 GigE Vision。
我是一名优秀的程序员,十分优秀!