首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用谷歌视觉的CROP_HINTS

使用谷歌视觉的CROP_HINTS
EN

Stack Overflow用户
提问于 2017-11-28 13:28:54
回答 1查看 722关注 0票数 0

我正在使用谷歌视觉API来检测人脸和裁剪相应的图像。这是我的代码,以获得裁剪的coordinates.but,它返回我所拥有的位图图像的最大大小。

代码语言:javascript
复制
                Vision.Builder builder = new Vision.Builder(httpTransport, jsonFactory, null);
                builder.setVisionRequestInitializer(requestInitializer);

                Vision vision = builder.build();

                BatchAnnotateImagesRequest batchAnnotateImagesRequest =
                        new BatchAnnotateImagesRequest();
                batchAnnotateImagesRequest.setRequests(new ArrayList<AnnotateImageRequest>() {{
                    AnnotateImageRequest annotateImageRequest = new AnnotateImageRequest();

                    Image base64EncodedImage = new Image();
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream);
                    byte[] imageBytes = byteArrayOutputStream.toByteArray();

                    base64EncodedImage.encodeContent(imageBytes);
                    annotateImageRequest.setImage(base64EncodedImage);

                    ArrayList<Feature> features = new ArrayList<>();
                      Feature cropHints = new Feature();
                    cropHints.setType("CROP_HINTS");
                    features.add(cropHints);
                    annotateImageRequest.setFeatures(features);


                    add(annotateImageRequest);
                }});

                Vision.Images.Annotate annotateRequest =
                        vision.images().annotate(batchAnnotateImagesRequest);

                BatchAnnotateImagesResponse response = annotateRequest.execute();
Sting vertices=response.getResponses().get(0).getCropHintsAnnotation().getCropHints().get(0).getBoundingPoly().getVertices().toString())

            } 

顶点的结果

代码语言:javascript
复制
 [{}, {"x":841}, {"x":841,"y":1499}, {"y":1499}]
EN

回答 1

Stack Overflow用户

发布于 2017-11-30 16:18:44

这里您想要的是FACE_DETECTION特性,而不是CROP_HINTS。尝试在您的API请求中更改它,您将获得图像中人脸的裁剪坐标。

然后,您可能需要更改处理响应的方式,但是API请求将提供所需的解决方案。我建议您使用JSON进行这里测试,如:

代码语言:javascript
复制
{
  "requests": [
    {
      "image": {
        "source": {
          "imageUri": "<YOUR_SAMPLE_IMAGE_URL>"
        }
      },
      "features": [
        {
          "type": "FACE_DETECTION"
        }
      ]
    }
  ]
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47532783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档