# 人脸识别

参数说明,腾讯ai仅支持base64编码后的图片,并且最大为1m,但是当前package提供了三种调用方式

所有支持image参数的接口 均可以用此方式来传递image参数

```
// base64 code调用
$code = 'image base64 code';
$ai->face()->base64($code)->detect();

// 图片url
$url = 'http://domain.com/some.jpg';
$ai->face()->url($url)->detect();

// 本地文件路径
$path = 'path/to/some.jpg';
$ai->face()->path($path )->detect();
```

| 名称      | 路由          | 参数                          |
| ------- | ----------- | --------------------------- |
| 人脸检测与分析 | detect      | image,mode                  |
| 多人脸检测   | multiDetect | image                       |
| 跨年龄人脸识别 | crosssAge   | source\_image,target\_image |
| 五官定位    | shape       | image                       |
| 人脸对比    | compare     | source\_image,target\_image |
| 人脸验证    | verify      | image,person\_id            |

## 人脸检测与分析

```
$code = 'image base64 code';
$res = $ai->face()->base64($base64Code)->detect(['mode' => 0]);
if($res-success()){
    var_dump($res->toArray());
}
```

## 多人脸检测

```
$url = 'http://domain.com/some.jpg';
$res = $ai->face()->url($url)->multiDetect();
if($res-success()){
    var_dump($res->toArray());
}
```

## 跨年龄人脸识别

```
$sourceImgCode = 'source base64 code';
$destImgCode = 'dest base64 code';
$res = $ai->face()->crosssAge([
    'source_image' => $sourceImgCode,
    'target_image' => $destImgCode
]);
if($res-success()){
    var_dump($res->toArray());
}
```

## 五官定位

```
$path = 'path/to/some.jpg';
$res = $ai->face()->path($path)->shape();
if($res-success()){
    var_dump($res->toArray());
}
```

## 人脸对比

```
$sourceImgCode = 'source base64 code';
$destImgCode = 'dest base64 code';
$res = $ai->face()->compare([
    'source_image' => $sourceImgCode,
    'target_image' => $destImgCode
]);
if($res-success()){
    var_dump($res->toArray());
}
```

## 人脸验证

```
$path = 'path/to/some.jpg';
$res = $ai->face()->path($path)->verify([
    'person_id' => 'person0'
]);
if($res-success()){
    var_dump($res->toArray());
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doc.crisen.org/ai/tencent/face.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
