LoginSignup
2
1

More than 5 years have passed since last update.

AWSの画像認識API Rekognitionをちょっと試してみた(awsコマンドとPython版)

Last updated at Posted at 2018-09-23

awsのS3はこんなかんじです。
Screen Shot 2018-09-23 at 16.45.12.png

では画像認識してみよう。

準備

・awsコマンドが打てるようにaws-shellをインストール
・python上でaws接続できるようにboto3をインストール

pip install aws-shell
pip install boto3

実行

awsコマンドの場合

aws rekognition detect-labels --image '{"S3Object":{"Bucket":"hogeeeeee","Name":"2018-08-29 19.46.23.jpg"}}'

python実行の場合

import boto3

rekognition = boto3.client("rekognition", "us-east-1")
bucket = "hogeeeeee"
key = "2018-08-29 19.46.23.jpg"

response = rekognition.detect_labels(
        Image={
            "S3Object": {
                "Bucket": bucket,
                "Name": key,
            }
        }
    )

print(response)

以上。どっちもやってることは一緒。

出力結果

{
    "Labels": [
        {
            "Name": "Bbq",
            "Confidence": 98.98237609863281
        },
        {
            "Name": "Food",
            "Confidence": 98.98237609863281
        },
        {
            "Name": "Brick",
            "Confidence": 65.28954315185547
        },
        {
            "Name": "Lighting",
            "Confidence": 53.96083068847656
        }
    ]
}

出力結果からなんの画像かわかる?



正解はこちら。
2018-08-29 19.46.23.jpg

厚切り牛タンであることは検知できなかった。

飯テロでした。

2
1
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
2
1