このページでは、Vision API を使用して画像内の有名人を認識する方法について説明します。
Vision API を使用すると、画像に含まれている顔を検出できます。顔を認識すると、Vision API はその顔の画像と Google が照合した有名人のインデックス付きギャラリーを比較します。
Vision API は数千人の有名人を認識できますが、これは専門家が制作したメディア コンテンツの中から有名人を識別することを目的としています。
一致する人物が見つかると、Vision API は、有名人の Knowledge Graph Machine ID(MID)、名前、画像内での顔の位置を示す境界ボックスを返します。
API アクセスのリクエスト
この機能は、専門家が制作したメディア コンテンツを扱うメディア・エンターテイメント企業やその認定パートナーにご利用いただくように意図されています。API アクセスをリクエストするには、このフォームに御社の情報とこの機能の用途を記入して送信してください。
Celebrity Recognition にローカル画像の認識をリクエストする
Vision API を使用して、ローカル画像ファイルに特徴検出を実行できます。
REST リクエストの場合は、リクエストの本文で画像ファイルのコンテンツを base64 エンコード文字列として送信します。
gcloud
とクライアント ライブラリ リクエストの場合は、リクエストにローカル イメージへのパスを指定します。
Celebrity Recognition にリクエストを送信するには、プロジェクトで機能に対するアクセス権を取得してから、既存の顔検出機能(FACE_DETECTION
enum)を使用します。有名人が検出されると、結果に有名人の情報が含まれます。
リクエストのデータを使用する前に、次のように置き換えます。
- BASE64_ENCODED_IMAGE: バイナリ画像データの base64 表現(ASCII 文字列)。これは次のような文字列になります。
/9j/4QAYRXhpZgAA...9tAVx/zDQDlGxn//2Q==
- PROJECT_ID: Google Cloud プロジェクト ID。
HTTP メソッドと URL:
POST https://vision.googleapis.com/v1p4beta1/images:annotate
リクエストの本文(JSON):
{ "requests": [ { "image": { "content": "BASE64_ENCODED_IMAGE " }, "features": [ { "type": "FACE_DETECTION" } ], "imageContext": { "faceRecognitionParams": { "celebritySet": ["builtin/default"] } } } ] }
リクエストを送信するには、次のいずれかのオプションを選択します。
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_ID " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1p4beta1/images:annotate"
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_ID " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1p4beta1/images:annotate" | Select-Object -Expand Content
次のような JSON レスポンスが返されます。
レスポンス
{ "responses": [ { "faceAnnotations": [ { "boundingPoly": { "vertices": [ { "x": 203 }, { "x": 570 }, { "x": 570, "y": 368 }, { "x": 203, "y": 368 } ] }, "fdBoundingPoly": { "vertices": [ { "x": 254, "y": 48 }, { "x": 524, "y": 48 }, { "x": 524, "y": 318 }, { "x": 254, "y": 318 } ] }, "landmarks": [ { "type": "LEFT_EYE", "position": { "x": 328.92297, "y": 135.14728, "z": -0.00084506406 } }, { "type": "RIGHT_EYE", "position": { "x": 440.65927, "y": 131.96986, "z": -0.18113805 } }, { "type": "LEFT_OF_LEFT_EYEBROW", "position": { "x": 290.14877, "y": 114.45657, "z": 11.400304 } }, { "type": "RIGHT_OF_LEFT_EYEBROW", "position": { "x": 357.85278, "y": 109.40719, "z": -21.749352 } }, { "type": "LEFT_OF_RIGHT_EYEBROW", "position": { "x": 411.14322, "y": 108.33092, "z": -21.866737 } }, { "type": "RIGHT_OF_RIGHT_EYEBROW", "position": { "x": 480.46622, "y": 110.60321, "z": 11.405331 } }, { "type": "MIDPOINT_BETWEEN_EYES", "position": { "x": 384.6528, "y": 129.57939, "z": -23.62145 } }, { "type": "NOSE_TIP", "position": { "x": 383.5203, "y": 196.91586, "z": -55.91733 } }, { "type": "UPPER_LIP", "position": { "x": 387.36368, "y": 236.28792, "z": -29.9772 } }, { "type": "LOWER_LIP", "position": { "x": 385.20834, "y": 277.3345, "z": -21.621998 } }, { "type": "MOUTH_LEFT", "position": { "x": 341.77988, "y": 248.98514, "z": 0.5651365 } }, { "type": "MOUTH_RIGHT", "position": { "x": 439.91428, "y": 244.32759, "z": 2.6951885 } }, { "type": "MOUTH_CENTER", "position": { "x": 385.44574, "y": 254.93304, "z": -21.696716 } }, { "type": "NOSE_BOTTOM_RIGHT", "position": { "x": 415.55923, "y": 201.68005, "z": -13.386427 } }, { "type": "NOSE_BOTTOM_LEFT", "position": { "x": 354.17462, "y": 205.03098, "z": -12.758772 } }, { "type": "NOSE_BOTTOM_CENTER", "position": { "x": 385.9818, "y": 213.22089, "z": -30.45643 } }, { "type": "LEFT_EYE_TOP_BOUNDARY", "position": { "x": 329.98587, "y": 128.55806, "z": -7.625594 } }, { "type": "LEFT_EYE_RIGHT_CORNER", "position": { "x": 350.25543, "y": 136.96538, "z": 0.3162137 } }, { "type": "LEFT_EYE_BOTTOM_BOUNDARY", "position": { "x": 327.47772, "y": 142.9333, "z": -1.0234838 } }, { "type": "LEFT_EYE_LEFT_CORNER", "position": { "x": 307.4751, "y": 137.34349, "z": 10.214714 } }, { "type": "LEFT_EYE_PUPIL", "position": { "x": 328.45987, "y": 136.19621, "z": -3.1551569 } }, { "type": "RIGHT_EYE_TOP_BOUNDARY", "position": { "x": 440.0691, "y": 126.8801, "z": -7.779711 } }, { "type": "RIGHT_EYE_RIGHT_CORNER", "position": { "x": 464.28534, "y": 135.34042, "z": 10.301969 } }, { "type": "RIGHT_EYE_BOTTOM_BOUNDARY", "position": { "x": 441.76584, "y": 140.32564, "z": -1.2271972 } }, { "type": "RIGHT_EYE_LEFT_CORNER", "position": { "x": 422.21207, "y": 135.32939, "z": 0.33341154 } }, { "type": "RIGHT_EYE_PUPIL", "position": { "x": 441.37714, "y": 134.46259, "z": -3.4412556 } }, { "type": "LEFT_EYEBROW_UPPER_MIDPOINT", "position": { "x": 324.93048, "y": 96.94437, "z": -13.394134 } }, { "type": "RIGHT_EYEBROW_UPPER_MIDPOINT", "position": { "x": 444.3336, "y": 95.093765, "z": -13.487409 } }, { "type": "LEFT_EAR_TRAGION", "position": { "x": 261.2239, "y": 191.10706, "z": 136.27896 } }, { "type": "RIGHT_EAR_TRAGION", "position": { "x": 513.192, "y": 187.88185, "z": 136.99525 } }, { "type": "FOREHEAD_GLABELLA", "position": { "x": 384.6936, "y": 107.73683, "z": -26.120888 } }, { "type": "CHIN_GNATHION", "position": { "x": 388.01538, "y": 322.47537, "z": -6.83534 } }, { "type": "CHIN_LEFT_GONION", "position": { "x": 274.37195, "y": 261.15628, "z": 91.56324 } }, { "type": "CHIN_RIGHT_GONION", "position": { "x": 500.2335, "y": 257.99966, "z": 91.12145 } } ], "rollAngle": -0.8706148, "panAngle": -0.0915068, "tiltAngle": 0.05244069, "detectionConfidence": 0.99914575, "landmarkingConfidence": 0.7713903, "joyLikelihood": "VERY_LIKELY", "sorrowLikelihood": "VERY_UNLIKELY", "angerLikelihood": "VERY_UNLIKELY", "surpriseLikelihood": "VERY_UNLIKELY", "underExposedLikelihood": "VERY_UNLIKELY", "blurredLikelihood": "VERY_UNLIKELY", "headwearLikelihood": "VERY_UNLIKELY", "recognitionResult": [ { "celebrity": { "name": "builtin/celebrity-mid ", "displayName": "celebrity-name " }, "confidence": 0.82625544 } ] } ] } ] }
Celebrity Recognition にリモート画像の認識をリクエストする
Vision API を使用すると、Cloud Storage またはウェブ上にあるリモート画像ファイルに特徴検出を実行できます。リモート ファイル リクエストを送信するには、リクエストの本文でファイルのウェブ URL または Cloud Storage URI を指定します。
Celebrity Recognition にリクエストを送信するには、プロジェクトで機能に対するアクセス権を取得してから、既存の顔検出機能(FACE_DETECTION
enum)を使用します。有名人が検出されると、結果に有名人の情報が含まれます。
リクエストのデータを使用する前に、次のように置き換えます。
- CLOUD_STORAGE_IMAGE_URI: Cloud Storage バケット内の有効な画像ファイルへのパス。少なくとも、ファイルに対する読み取り権限が必要です。例:
gs://my-cloud-bucket/img/celebrity_image.jpg
- PROJECT_ID: Google Cloud プロジェクト ID。
HTTP メソッドと URL:
POST https://vision.googleapis.com/v1p4beta1/images:annotate
リクエストの本文(JSON):
{ "requests": [ { "image": { "source": { "imageUri": "CLOUD_STORAGE_FILE_URI " } }, "features": [ { "type": "FACE_DETECTION" } ], "imageContext": { "faceRecognitionParams": { "celebritySet": ["builtin/default"] } } } ] }
リクエストを送信するには、次のいずれかのオプションを選択します。
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project:PROJECT_ID " \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://vision.googleapis.com/v1p4beta1/images:annotate"
リクエスト本文を request.json
という名前のファイルに保存して、次のコマンドを実行します。
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "PROJECT_ID " }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1p4beta1/images:annotate" | Select-Object -Expand Content
次のような JSON レスポンスが返されます。
レスポンス
{ "responses": [ { "faceAnnotations": [ { "boundingPoly": { "vertices": [ { "x": 203 }, { "x": 570 }, { "x": 570, "y": 368 }, { "x": 203, "y": 368 } ] }, "fdBoundingPoly": { "vertices": [ { "x": 254, "y": 48 }, { "x": 524, "y": 48 }, { "x": 524, "y": 318 }, { "x": 254, "y": 318 } ] }, "landmarks": [ { "type": "LEFT_EYE", "position": { "x": 328.92297, "y": 135.14728, "z": -0.00084506406 } }, { "type": "RIGHT_EYE", "position": { "x": 440.65927, "y": 131.96986, "z": -0.18113805 } }, { "type": "LEFT_OF_LEFT_EYEBROW", "position": { "x": 290.14877, "y": 114.45657, "z": 11.400304 } }, { "type": "RIGHT_OF_LEFT_EYEBROW", "position": { "x": 357.85278, "y": 109.40719, "z": -21.749352 } }, { "type": "LEFT_OF_RIGHT_EYEBROW", "position": { "x": 411.14322, "y": 108.33092, "z": -21.866737 } }, { "type": "RIGHT_OF_RIGHT_EYEBROW", "position": { "x": 480.46622, "y": 110.60321, "z": 11.405331 } }, { "type": "MIDPOINT_BETWEEN_EYES", "position": { "x": 384.6528, "y": 129.57939, "z": -23.62145 } }, { "type": "NOSE_TIP", "position": { "x": 383.5203, "y": 196.91586, "z": -55.91733 } }, { "type": "UPPER_LIP", "position": { "x": 387.36368, "y": 236.28792, "z": -29.9772 } }, { "type": "LOWER_LIP", "position": { "x": 385.20834, "y": 277.3345, "z": -21.621998 } }, { "type": "MOUTH_LEFT", "position": { "x": 341.77988, "y": 248.98514, "z": 0.5651365 } }, { "type": "MOUTH_RIGHT", "position": { "x": 439.91428, "y": 244.32759, "z": 2.6951885 } }, { "type": "MOUTH_CENTER", "position": { "x": 385.44574, "y": 254.93304, "z": -21.696716 } }, { "type": "NOSE_BOTTOM_RIGHT", "position": { "x": 415.55923, "y": 201.68005, "z": -13.386427 } }, { "type": "NOSE_BOTTOM_LEFT", "position": { "x": 354.17462, "y": 205.03098, "z": -12.758772 } }, { "type": "NOSE_BOTTOM_CENTER", "position": { "x": 385.9818, "y": 213.22089, "z": -30.45643 } }, { "type": "LEFT_EYE_TOP_BOUNDARY", "position": { "x": 329.98587, "y": 128.55806, "z": -7.625594 } }, { "type": "LEFT_EYE_RIGHT_CORNER", "position": { "x": 350.25543, "y": 136.96538, "z": 0.3162137 } }, { "type": "LEFT_EYE_BOTTOM_BOUNDARY", "position": { "x": 327.47772, "y": 142.9333, "z": -1.0234838 } }, { "type": "LEFT_EYE_LEFT_CORNER", "position": { "x": 307.4751, "y": 137.34349, "z": 10.214714 } }, { "type": "LEFT_EYE_PUPIL", "position": { "x": 328.45987, "y": 136.19621, "z": -3.1551569 } }, { "type": "RIGHT_EYE_TOP_BOUNDARY", "position": { "x": 440.0691, "y": 126.8801, "z": -7.779711 } }, { "type": "RIGHT_EYE_RIGHT_CORNER", "position": { "x": 464.28534, "y": 135.34042, "z": 10.301969 } }, { "type": "RIGHT_EYE_BOTTOM_BOUNDARY", "position": { "x": 441.76584, "y": 140.32564, "z": -1.2271972 } }, { "type": "RIGHT_EYE_LEFT_CORNER", "position": { "x": 422.21207, "y": 135.32939, "z": 0.33341154 } }, { "type": "RIGHT_EYE_PUPIL", "position": { "x": 441.37714, "y": 134.46259, "z": -3.4412556 } }, { "type": "LEFT_EYEBROW_UPPER_MIDPOINT", "position": { "x": 324.93048, "y": 96.94437, "z": -13.394134 } }, { "type": "RIGHT_EYEBROW_UPPER_MIDPOINT", "position": { "x": 444.3336, "y": 95.093765, "z": -13.487409 } }, { "type": "LEFT_EAR_TRAGION", "position": { "x": 261.2239, "y": 191.10706, "z": 136.27896 } }, { "type": "RIGHT_EAR_TRAGION", "position": { "x": 513.192, "y": 187.88185, "z": 136.99525 } }, { "type": "FOREHEAD_GLABELLA", "position": { "x": 384.6936, "y": 107.73683, "z": -26.120888 } }, { "type": "CHIN_GNATHION", "position": { "x": 388.01538, "y": 322.47537, "z": -6.83534 } }, { "type": "CHIN_LEFT_GONION", "position": { "x": 274.37195, "y": 261.15628, "z": 91.56324 } }, { "type": "CHIN_RIGHT_GONION", "position": { "x": 500.2335, "y": 257.99966, "z": 91.12145 } } ], "rollAngle": -0.8706148, "panAngle": -0.0915068, "tiltAngle": 0.05244069, "detectionConfidence": 0.99914575, "landmarkingConfidence": 0.7713903, "joyLikelihood": "VERY_LIKELY", "sorrowLikelihood": "VERY_UNLIKELY", "angerLikelihood": "VERY_UNLIKELY", "surpriseLikelihood": "VERY_UNLIKELY", "underExposedLikelihood": "VERY_UNLIKELY", "blurredLikelihood": "VERY_UNLIKELY", "headwearLikelihood": "VERY_UNLIKELY", "recognitionResult": [ { "celebrity": { "name": "builtin/celebrity-mid ", "displayName": "celebrity-name " }, "confidence": 0.82625544 } ] } ] } ] }
オプトアウトのリクエスト
有名人としての自分の画像が Cloud Vision API または Video Intelligence API で識別されないようにするには、このフォームに必要事項を記入してお送りください。
不正行為の報告
Vision API の Celebrity Recognition 機能が悪用されている可能性がある場合は、このフォームを使用してお知らせください。