• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java VisionRequestInitializer类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中com.google.api.services.vision.v1.VisionRequestInitializer的典型用法代码示例。如果您正苦于以下问题:Java VisionRequestInitializer类的具体用法?Java VisionRequestInitializer怎么用?Java VisionRequestInitializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

VisionRequestInitializer类属于com.google.api.services.vision.v1包,在下文中一共展示了VisionRequestInitializer类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: annotateImage

点赞 2

import com.google.api.services.vision.v1.VisionRequestInitializer; //导入依赖的package包/类
/**
 * Construct an annotated image request for the provided image to be executed
 * using the provided API interface.
 *
 * @param imageBytes image bytes in JPEG format.
 * @return collection of annotation descriptions and scores.
 */
public static Map<String, Float> annotateImage(byte[] imageBytes) throws IOException {
    // Construct the Vision API instance
    HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();
    JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
    VisionRequestInitializer initializer = new VisionRequestInitializer(CLOUD_VISION_API_KEY);
    Vision vision = new Vision.Builder(httpTransport, jsonFactory, null)
            .setVisionRequestInitializer(initializer)
            .build();

    // Create the image request
    AnnotateImageRequest imageRequest = new AnnotateImageRequest();
    Image img = new Image();
    img.encodeContent(imageBytes);
    imageRequest.setImage(img);

    // Add the features we want
    Feature labelDetection = new Feature();
    labelDetection.setType(LABEL_DETECTION);
    labelDetection.setMaxResults(MAX_LABEL_RESULTS);
    imageRequest.setFeatures(Collections.singletonList(labelDetection));

    // Batch and execute the request
    BatchAnnotateImagesRequest requestBatch = new BatchAnnotateImagesRequest();
    requestBatch.setRequests(Collections.singletonList(imageRequest));
    BatchAnnotateImagesResponse response = vision.images()
            .annotate(requestBatch)
            // Due to a bug: requests to Vision API containing large images fail when GZipped.
            .setDisableGZipContent(true)
            .execute();

    return convertResponseToMap(response);
}
 

开发者ID:androidthings,
项目名称:doorbell,
代码行数:40,
代码来源:CloudVisionUtils.java

示例2: authToGoogleCloudVision

点赞 2

import com.google.api.services.vision.v1.VisionRequestInitializer; //导入依赖的package包/类
private Vision authToGoogleCloudVision(String API_KEY) {
    HttpTransport httpTransport = new NetHttpTransport();
    JsonFactory jsonFactory = GsonFactory.getDefaultInstance();

    Vision.Builder builder = new Vision.Builder(httpTransport, jsonFactory, null);
    builder.setVisionRequestInitializer(new
            VisionRequestInitializer(API_KEY));
    return builder.build();
}
 

开发者ID:gaborvecsei,
项目名称:OCR-libraries,
代码行数:10,
代码来源:GoogleDetection.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)