# @azure/cognitiveservices-face 中文文档

规范地址：https://npmcn.com/package/%40azure/cognitiveservices-face/

版本：5\.0\.0
npm 元数据更新时间：2026-04-03T21:02:52.466Z
中文译文更新时间：2026-11-07T15:52:39.833Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40azure/cognitiveservices-face
原文对照：https://npmcn.com/package/%40azure/cognitiveservices-face/?lang=original
项目主页：https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/cognitiveservices/cognitiveservices-face
源码仓库：https://github.com/Azure/azure-sdk-for-js

弃用说明：This package has been deprecated\. For more information, please see: https://learn\.microsoft\.com/azure/ai-services/face/overview-identity

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：1.5 MB，119 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：2 个
- 首次发布：2018-11-14T17:59:52.876Z
- 最新版本发布：2021-11-30T16:54:08.684Z
- 近 30 天下载量：6097（2026-10-08 至 2026-11-06，npm 官方下载统计）
- 已发布版本数：9（近 12 个月 0 个）

## 中文简介

FaceClient 库中含有节点.js和浏览器的打字符类型定义.

## 安装

```sh
npm install @azure/cognitiveservices-face
```

也可以使用：`pnpm add @azure/cognitiveservices-face`、`yarn add @azure/cognitiveservices-face`、`bun add @azure/cognitiveservices-face`

## README

## 用于 - FaceClient 的同位素 Javascript sdk

这个包包含了FaceClient的同位素 SDK.

### 目前得到支持的环境

-   [节点.js的LTS版本](https://nodejs.org/about/releases/)
-   Safari,Chrome,Edge,和Firefox的最新版本.

### 如何安装

```bash
npm install @azure/cognitiveservices-face
```

### 如何使用

#### nodejs - 认证,客户端创建和将个人GroupPerson列为TypeScript所写的示例.

##### 安装@azure/ ms-rest-azure-js

```bash
npm install @azure/ms-rest-azure-js
```

##### 样本代码

以下样本检测出给定图像上的面部特征. 要了解更多的情况,请参考 [面相 API 上的 Azure 文档](https://docs.microsoft.com/azure/cognitive-services/face/overview)

```javascript
const { FaceClient, FaceModels } = require("@azure/cognitiveservices-face");
const { CognitiveServicesCredentials } = require("@azure/ms-rest-azure-js");

async function main() {
  const faceKey = process.env["faceKey"] || "<faceKey>";
  const faceEndPoint = process.env["faceEndPoint"] || "<faceEndPoint>";
  const cognitiveServiceCredentials = new CognitiveServicesCredentials(faceKey);
  const client = new FaceClient(cognitiveServiceCredentials, faceEndPoint);
  const url =
    "https://pbs.twimg.com/profile_images/3354326900/3a5168f2b45c07d0965098be1a4e3007.jpeg";
  const options = {
    returnFaceLandmarks: true
  };
  client.face
    .detectWithUrl(url, options)
    .then(result => {
      console.log("The result is: ");
      console.log(result);
    })
    .catch(err => {
      console.log("An error occurred:");
      console.error(err);
    });
}

main();
```

#### 浏览器 - 认证,客户端创建并列出个人GroupPerson作为JavaScript所写的示例.

##### 样本代码

-   索引.html

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>@azure/cognitiveservices-face sample</title>
    <script src="node_modules/@azure/ms-rest-js/dist/msRest.browser.js"></script>
    <script src="node_modules/@azure/cognitiveservices-face/dist/cognitiveservices-face.js"></script>
    <script type="text/javascript">
      const faceKey = "<YOUR_FACE_KEY>";
      const faceEndPoint = "<YOUR_FACE_ENDPOINT>";
      const cognitiveServiceCredentials = new msRest.ApiKeyCredentials({
        inHeader: {
          "Ocp-Apim-Subscription-Key": faceKey
        }
      });
      const client = new Azure.CognitiveservicesFace.FaceClient(
        cognitiveServiceCredentials,
        faceEndPoint
      );

      const url =
        "https://pbs.twimg.com/profile_images/3354326900/3a5168f2b45c07d0965098be1a4e3007.jpeg";
      const options = {
        returnFaceLandmarks: true
      };
      client.face
        .detectWithUrl(url, options)
        .then(result => {
          console.log("The result is: ");
          console.log(result);
        })
        .catch(err => {
          console.log("An error occurred:");
          console.error(err);
        });
    </script>
  </head>
  <body></body>
</html>
```

## 相关项目

-   [Microsoft Azure SDK 用于 Javascript](https://github.com/Azure/azure-sdk-for-js)

![Impressions](https://azure-sdk-impressions.azurewebsites.net/api/impressions/azure-sdk-for-js%2Fsdk%2Fcognitiveservices%2Fcognitiveservices-face%2FREADME.png)

## 常见问题

### @azure/cognitiveservices-face 是什么？

FaceClient 库中含有节点\.js和浏览器的打字符类型定义\.注意：该包已被作者标记为弃用——This package has been deprecated\. For more information, please see: https://learn\.microsoft\.com/azure/ai-services/face/overview-identity

### 如何安装 @azure/cognitiveservices-face？

在项目目录运行 npm install @azure/cognitiveservices-face，或使用 pnpm add / yarn add / bun add。

### @azure/cognitiveservices-face 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @azure/cognitiveservices-face 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @azure/cognitiveservices-face 可以商用吗？

@azure/cognitiveservices-face 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @azure/cognitiveservices-face 的下载量有多少？

根据 npm 官方下载统计，@azure/cognitiveservices-face 在 2026/10/08 – 2026/11/06 这 30 天内被下载 6,097 次，日均约 203 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @azure/cognitiveservices-face 还在维护吗？

最新版本 5\.0\.0 发布于 2021/12/01（4 年前）；至今共发布 9 个版本，其中过去 12 个月发布了 0 个；首次发布于 2018/11/15。作者已将其标记为弃用，新项目建议寻找替代方案。

