1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Amazon Rekognition でオブジェクトとシーンの検出をしてみる

Posted at

ローカルPC内の画像を対象にした実装とS3に入っている画像を対象にした実装

#!/usr/bin/env python                                                                                                                                                                                                                                                           
#-*- coding: utf-8 -*-                                                                                                                                                                                                                                                          

from boto3 import client

def local_image_rekognition():
    """ ローカルPC内のファイルを指定する場合                                                                                                                                                                                                                                    
    """
    fd = open("[ファイル名]", "rb")

    rekognition = client("rekognition", region_name='us-west-2')

    response = rekognition.detect_labels(
        Image={
            'Bytes': fd.read()
        },
        MaxLabels=128
    )

    print(response)


def s3_image_rekognition():
    """ S3内のファイルを指定する場合                                                                                                                                                                                                                                            
    """
    rekognition = client("rekognition", region_name='us-west-2')

    response = rekognition.detect_labels(
        Image={
            'S3Object': {
                'Bucket': '[バケット名]',
                'Name': '[ファイル名]',
            }
        },
        MaxLabels=128
    )

    print(response)


def main():
    """                                                                                                                                                                                                                                                                         
    """
    s3_image_rekognition()


if __name__ == "__main__":
    """                                                                                                                                                                                                                                                                         
    """
    main()
1
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?