【问题标题】:AWS Rekognition - create image from detect-faces bounding boxAWS Rekognition - 从检测人脸边界框创建图像
【发布时间】:2019-04-17 04:15:13
【问题描述】:

目前正试图弄清楚如何从边界框(从检测人脸响应)制作人脸裁剪,并使用这些裁剪通过 SearchFacesByImage API 搜索现有集合

这在 SearchFacesByImage 文档中有所提及。

您也可以调用 DetectFaces 操作并使用响应中的边界框进行人脸裁剪,然后您可以将其传递给 SearchFacesByImage 操作

我正在尝试在 Python 或 Node.js 中的 Lambda 函数中执行此操作。输入图像是一个 s3 对象。

非常感谢所有帮助。

【问题讨论】:

  • 我正在尝试在 java 中执行此操作,但由于将 AWS Image 转换为 java Image 时出现问题,目前无法完成。我在这个问题中有一些代码stackoverflow.com/questions/49801592/…

标签: aws-lambda face-detection amazon-rekognition


【解决方案1】:

我也遇到过同样的问题。请参阅 AWS 文档中的 this link。在这里,您将找到适用于 python 或 java 的示例代码。它将返回边界框的 Top、Lfet、Width 和 Height。请记住,左上角将被视为 (0,0)。

然后如果你使用python,你可以用cv2或PIL裁剪图像。

这是一个 PIL 的例子:

from PIL import Image

img = Image.open( 'my_image.png' )
cropped = img.crop( ( Left, Top, Left + Width, Top + Height ) ) 
cropped.show()

在此代码中,Top、Lfet、Width 和 Height 是对链接中给出的代码的响应。

【讨论】:

    【解决方案2】:

    我在java中做了这个脚本,也许它的帮助

            java.awt.image.BufferedImage image = ...
        com.amazonaws.services.rekognition.model.BoundingBox target ...
    
    
        int x = (int) Math.abs((image.getWidth() * target.getLeft()));
        int y = (int) Math.abs((image.getHeight() *target.getTop()));;
        int w = (int) Math.abs((image.getWidth() * target.getWidth()));
        int h = (int) Math.abs((image.getHeight() * target.getHeight()));
    
        int finalX = x + w;
        int finalH = y + h;
    
        if (finalX > image.getWidth())
            w = image.getWidth()-x;
    
        if (finalH > image.getHeight())
            h = image.getHeight()-y;
    
    
        System.out.println(finalX);
        System.out.println(finalH);
    
        //
        //
        BufferedImage subImage = image.getSubimage(
                x, 
                y, 
                w,
                h);
    
        //
        //
        String base64 = ImageUtils.imgToBase64String(subImage, "jpg");
    

    【讨论】:

      猜你喜欢
      • 2020-09-20
      • 2011-06-25
      • 1970-01-01
      • 2012-04-17
      • 2016-02-25
      • 2019-06-18
      • 2020-12-26
      • 1970-01-01
      • 2017-06-09
      相关资源
      最近更新 更多