4.6.201909271045 • Published 5 years ago

@dfeidao/fd-an000001 v4.6.201909271045

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

百度智能云-人脸对比

Installation

yarn add --dev @dfeidao/fd-an000001

参数

参数描述
app_id从百度智能云申请的AppID
api_key从百度智能云获取的ApiKey
secret_key从百度智能云获取的Secret Key
images图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式

返回值

名称说明
error_code等于0时,标示比对成功
error_msg比对结果
log_id请求唯一标识码,随机数
score比对得分,推荐80分作为阈值,80分以上可以判断为同一人,此分值对应万分之一误识率

Example

  1. 客户端通过调用 import img2base64 from '@dfeidao/atom-web/file/img2base64'; 原子操作,把base64格式的图片传到服务端
  2. 服务端调用 @dfeidao/fd-an000001 人脸对比原子操作进行比对
  3. 需要注意的是 app_id, api_key, secret_key 不要出现在客户端,仅限在服务端出现
import an001 from '@dfeidao/fd-an000001';

export default async function atom(message: Message, action_id: string, session_id: string, headers: IncomingHttpHeaders): Promise<IWebResult> {
	try {
		const img1 = message.img1;
		const img2 = message.img2;

		const images = [{
			image: img1,
			image_type: 'BASE64'
		}, {
			image: img2,
			image_type: 'BASE64'
		}];
		const res = await an001('app_id', 'api_key', 'secret_key', images);

	} catch (error) {
		// 获取到具体的错误信息
		console.log(error);
	}
}