名人识别

本页介绍如何使用 Vision API 识别图片中的名人。

借助 Vision API,您可以检测图片中的人脸。在识别人脸时,Vision API 可以根据 Google 整理的名人索引图库进行人脸比对。

Vision API 可以识别成千上万的名人,且只能用于专业拍摄的媒体内容(其中一些常见的名人会出现在图片中)。

如果找到匹配项,Vision API 将提供相应名人的知识图谱机器 ID (MID)、姓名和指示人脸在图片中出现位置的边界框。

申请 API 访问权限

此功能仅供媒体和娱乐公司或获得批准的合作伙伴用于专业制作的媒体内容。如需申请 API 访问权限,请提交此表单,在其中提供有关您的公司和用例的信息。

对本地图片申请名人识别

您可以使用 Vision API 对本地图片文件执行特征检测。

对于 REST 请求,请将图片文件的内容作为 base64 编码的字符串在请求正文中发送。

对于 gcloud 和客户端库请求,请在请求中指定本地图片的路径。

如需发送名人识别请求,您首先需要为您的项目获取对该功能的访问权限,然后使用现有人脸检测功能(FACE_DETECTION 枚举)。 如果检测到名人,则结果中会包含名人信息。

REST

在使用任何请求数据之前,请先进行以下替换:

  • BASE64_ENCODED_IMAGE:二进制图片数据的 base64 表示(ASCII 字符串)。此字符串应类似于以下字符串:
    • /9j/4QAYRXhpZgAA...9tAVx/zDQDlGxn//2Q==
    如需了解详情,请参阅 base64 编码主题。
  • PROJECT_ID:您的 Google Cloud 项目 ID。

HTTP 方法和网址:

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
            }
          ]
        }
      ]
    }
  ]
}

对远程图片申请名人识别

您可以使用 Vision API 对位于 Cloud Storage 或网络中的远程图片文件执行特征检测。如需发送远程文件请求,请在请求正文中指定文件的网址或 Cloud Storage URI。

如需发送名人识别请求,您首先需要为您的项目获取对该功能的访问权限,然后使用现有人脸检测功能(FACE_DETECTION 枚举)。 如果检测到名人,则结果中会包含名人信息。

REST

在使用任何请求数据之前,请先进行以下替换:

  • CLOUD_STORAGE_IMAGE_URI:Cloud Storage 存储桶中有效图片文件的路径。您必须至少拥有该文件的读取权限。 示例:
    • gs://my-cloud-bucket/img/celebrity_image.jpg
  • PROJECT_ID:您的 Google Cloud 项目 ID。

HTTP 方法和网址:

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 或 Video Intelligence API 的此项功能中,请填写并提交此表单

举报滥用行为

如果您怀疑 Vision API 名人识别功能被滥用,请通过此表单告知我们。