Python_sdk 优图人脸识别sdk 项目简介
Python_sdk是一款用于腾讯优图人脸识别服务的sdk文件,优图人脸识别(Face Recognition), 是由腾讯优图团队研发的,基于人的脸部特征信息进行身份识别的一种生物识别技术。它提供了"人脸检测与分析"、"人脸比对"、"人脸验证"、"人脸识别"等一整套技术方案。Python sdk for 腾讯云智能优图服务 & 腾讯优图开放平台安装依赖性- Requests,获取更新版本 http://docs.python-requests.org/en/latest/构建工程1. 下载sdk到您的目录${python_sdk} git clone https://github.com/TencentYouTu/python_sdk.git2. 在您需要使用sdk的文件中import TencentYoutuyun包名词AppId 平台添加应用后分配的AppIdSecretId 平台添加应用后分配的SecretIdSecretKey 平台添加应用后分配的SecretKey签名 接口鉴权凭证,由AppId、SecretId、SecretKey等生成,详见http://open.youtu.qq.com/welcome/authentication使用示例# -*- coding: utf-8 -*-
import time
import TencentYoutuyun
appid = 'xxx'
secret_id = 'xxxxxxx'
secret_key = 'xxxxxxxx'
userid= 'xxx'
#end_point = TencentYoutuyun.conf.API_TENCENTYUN_END_POINT // 腾讯云
end_point = TencentYoutuyun.conf.API_YOUTU_END_POINT // 优图开放平台
youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point)
ret = youtu.FaceCompare('you_path_one.jpg','you_path_two.jpg')
print retSDK内部错误码说明IMAGE_FILE_NOT_EXISTS -1 //文件不存在
IMAGE_NETWORK_ERROR -2 //网络错误
IMAGE_PARAMS_ERROR -3 //图片参数错误
PERSON_ID_EMPTY -4 //参数person_id 为空
GROUP_ID_EMPTY -5 //参数group_id 为空
GROUP_IDS_EMPTY -6 //参数group_ids 为空
IMAGES_EMPTY -7 //参数images 集合为空
FACE_IDS_EMPTY -8 //参数face_ids 集合为空
FACE_ID_EMPTY -9 //参数face_id为空
LIST_TYPE_INVALID -10 //不是list类型
IMAGE_PATH_EMPTY -11 //传入的image_path为空初始化示例<span style="font-family: 微软雅黑,Microsoft YaHei;">youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">ytopen_sdk::AppSign</span><span style="font-family: 微软雅黑,Microsoft YaHei;">appid</span> 业务中的应用标识AppId<span style="font-family: 微软雅黑,Microsoft YaHei;">secret_id</span> 秘钥SecretId<span style="font-family: 微软雅黑,Microsoft YaHei;">secret_key</span> 秘钥SecretKey<span style="font-family: 微软雅黑,Microsoft YaHei;">userid</span> 用户id<span style="font-family: 微软雅黑,Microsoft YaHei;">end_point</span> 服务后台路径,默认是优图开放平台,支持腾讯云接口说明接口调用统一返回值说明返回值<span style="font-family: 微软雅黑,Microsoft YaHei;">Json</span>格式的返回结果,具体字段参考API文档人脸检测接口<span style="font-family: 微软雅黑,Microsoft YaHei;">DetectFace(self, image_path, mode = 0, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待检测的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">mode</span> 是否大脸模式,默认非大脸模式<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url人脸配准接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceShape(self, image_path, mode = 0, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待检测的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">mode</span> 是否大脸模式,默认非大脸模式<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image是图片还是url, 0代表图片,1代表url人脸比对接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceCompare(self, image_pathA, image_pathB, data_type = 0):</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_pathA</span> 待比对的A图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">image_pathB</span> 待比对的B图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_pathA, image_pathB是图片还是url, 0代表图片,1代表url人脸验证接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceVerify(self, person_id, image_path, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待验证的个体id<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待验证的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url人脸识别接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceIdentify(self, group_id, image_path, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">group_id</span> 识别的组id<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待识别的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url新建个体接口<span style="font-family: 微软雅黑,Microsoft YaHei;">NewPerson(self, person_id, image_path, group_ids, person_name= '', tag='', data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 新建的个体id,用户指定,需要保证app_id下的唯一性<span style="font-family: 微软雅黑,Microsoft YaHei;">person_name</span> 个体对应的姓名<span style="font-family: 微软雅黑,Microsoft YaHei;">group_ids</span> 数组类型,用户指定(组默认创建)的个体存放的组id,可以指定多个组id<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 包含个体人脸的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">tag</span> 备注信息,用户自解释字段<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url删除个体接口<span style="font-family: 微软雅黑,Microsoft YaHei;">DelPerson(self, person_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待删除的个体id增加人脸接口<span style="font-family: 微软雅黑,Microsoft YaHei;">AddFace(self, person_id, images, tag='', data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 新增人脸的个体身份id<span style="font-family: 微软雅黑,Microsoft YaHei;">images</span> 数组类型,待增加的包含人脸的图片路径,可加入多张(包体大小<2m)<span style="font-family: 微软雅黑,Microsoft YaHei;">tag</span> 人脸备注信息,用户自解释字段<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示images是图片还是url, 0代表图片,1代表url删除人脸接口<span style="font-family: 微软雅黑,Microsoft YaHei;">DelFace(self, person_id, face_ids)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待删除人脸的个体身份id<span style="font-family: 微软雅黑,Microsoft YaHei;">face_ids</span> 数组类型,待删除的人脸id获取信息接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetInfo(self, person_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待查询的个体身份id设置信息接口<span style="font-family: 微软雅黑,Microsoft YaHei;">SetInfo(self, person_id, person_name='', tag='')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待设置的个体身份id<span style="font-family: 微软雅黑,Microsoft YaHei;">person_name</span> 新设置的个体名字,为空无效<span style="font-family: 微软雅黑,Microsoft YaHei;">tag</span> 新设置的人脸备注信息,为空无效获取组列表接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetGroupIds(self)</span>参数无获取个体列表接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetPersonIds(self, group_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">group_id</span> 待查询的组id获取人脸列表接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetFaceIds(self, person_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待查询的个体id获取人脸信息接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetFaceInfo(self, face_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">face_id</span> 待查询的人脸id模糊验证<span style="font-family: 微软雅黑,Microsoft YaHei;">fuzzydetect(self, image_path, data_type = 0, seq = '')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 标识图片信息<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url美食检测<span style="font-family: 微软雅黑,Microsoft YaHei;">fooddetect(self, image_path, data_type = 0, seq = '')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 标识图片信息<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url图片分类<span style="font-family: 微软雅黑,Microsoft YaHei;">imagetag(self, image_path, data_type = 0, seq = '')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 标识图片信息<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url
import time
import TencentYoutuyun
appid = 'xxx'
secret_id = 'xxxxxxx'
secret_key = 'xxxxxxxx'
userid= 'xxx'
#end_point = TencentYoutuyun.conf.API_TENCENTYUN_END_POINT // 腾讯云
end_point = TencentYoutuyun.conf.API_YOUTU_END_POINT // 优图开放平台
youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point)
ret = youtu.FaceCompare('you_path_one.jpg','you_path_two.jpg')
print retSDK内部错误码说明IMAGE_FILE_NOT_EXISTS -1 //文件不存在
IMAGE_NETWORK_ERROR -2 //网络错误
IMAGE_PARAMS_ERROR -3 //图片参数错误
PERSON_ID_EMPTY -4 //参数person_id 为空
GROUP_ID_EMPTY -5 //参数group_id 为空
GROUP_IDS_EMPTY -6 //参数group_ids 为空
IMAGES_EMPTY -7 //参数images 集合为空
FACE_IDS_EMPTY -8 //参数face_ids 集合为空
FACE_ID_EMPTY -9 //参数face_id为空
LIST_TYPE_INVALID -10 //不是list类型
IMAGE_PATH_EMPTY -11 //传入的image_path为空初始化示例<span style="font-family: 微软雅黑,Microsoft YaHei;">youtu = TencentYoutuyun.YouTu(appid, secret_id, secret_key, userid, end_point)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">ytopen_sdk::AppSign</span><span style="font-family: 微软雅黑,Microsoft YaHei;">appid</span> 业务中的应用标识AppId<span style="font-family: 微软雅黑,Microsoft YaHei;">secret_id</span> 秘钥SecretId<span style="font-family: 微软雅黑,Microsoft YaHei;">secret_key</span> 秘钥SecretKey<span style="font-family: 微软雅黑,Microsoft YaHei;">userid</span> 用户id<span style="font-family: 微软雅黑,Microsoft YaHei;">end_point</span> 服务后台路径,默认是优图开放平台,支持腾讯云接口说明接口调用统一返回值说明返回值<span style="font-family: 微软雅黑,Microsoft YaHei;">Json</span>格式的返回结果,具体字段参考API文档人脸检测接口<span style="font-family: 微软雅黑,Microsoft YaHei;">DetectFace(self, image_path, mode = 0, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待检测的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">mode</span> 是否大脸模式,默认非大脸模式<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url人脸配准接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceShape(self, image_path, mode = 0, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待检测的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">mode</span> 是否大脸模式,默认非大脸模式<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image是图片还是url, 0代表图片,1代表url人脸比对接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceCompare(self, image_pathA, image_pathB, data_type = 0):</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_pathA</span> 待比对的A图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">image_pathB</span> 待比对的B图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_pathA, image_pathB是图片还是url, 0代表图片,1代表url人脸验证接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceVerify(self, person_id, image_path, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待验证的个体id<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待验证的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url人脸识别接口<span style="font-family: 微软雅黑,Microsoft YaHei;">FaceIdentify(self, group_id, image_path, data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">group_id</span> 识别的组id<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 待识别的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url新建个体接口<span style="font-family: 微软雅黑,Microsoft YaHei;">NewPerson(self, person_id, image_path, group_ids, person_name= '', tag='', data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 新建的个体id,用户指定,需要保证app_id下的唯一性<span style="font-family: 微软雅黑,Microsoft YaHei;">person_name</span> 个体对应的姓名<span style="font-family: 微软雅黑,Microsoft YaHei;">group_ids</span> 数组类型,用户指定(组默认创建)的个体存放的组id,可以指定多个组id<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 包含个体人脸的图片路径<span style="font-family: 微软雅黑,Microsoft YaHei;">tag</span> 备注信息,用户自解释字段<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url删除个体接口<span style="font-family: 微软雅黑,Microsoft YaHei;">DelPerson(self, person_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待删除的个体id增加人脸接口<span style="font-family: 微软雅黑,Microsoft YaHei;">AddFace(self, person_id, images, tag='', data_type = 0)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 新增人脸的个体身份id<span style="font-family: 微软雅黑,Microsoft YaHei;">images</span> 数组类型,待增加的包含人脸的图片路径,可加入多张(包体大小<2m)<span style="font-family: 微软雅黑,Microsoft YaHei;">tag</span> 人脸备注信息,用户自解释字段<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示images是图片还是url, 0代表图片,1代表url删除人脸接口<span style="font-family: 微软雅黑,Microsoft YaHei;">DelFace(self, person_id, face_ids)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待删除人脸的个体身份id<span style="font-family: 微软雅黑,Microsoft YaHei;">face_ids</span> 数组类型,待删除的人脸id获取信息接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetInfo(self, person_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待查询的个体身份id设置信息接口<span style="font-family: 微软雅黑,Microsoft YaHei;">SetInfo(self, person_id, person_name='', tag='')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待设置的个体身份id<span style="font-family: 微软雅黑,Microsoft YaHei;">person_name</span> 新设置的个体名字,为空无效<span style="font-family: 微软雅黑,Microsoft YaHei;">tag</span> 新设置的人脸备注信息,为空无效获取组列表接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetGroupIds(self)</span>参数无获取个体列表接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetPersonIds(self, group_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">group_id</span> 待查询的组id获取人脸列表接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetFaceIds(self, person_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">person_id</span> 待查询的个体id获取人脸信息接口<span style="font-family: 微软雅黑,Microsoft YaHei;">GetFaceInfo(self, face_id)</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">face_id</span> 待查询的人脸id模糊验证<span style="font-family: 微软雅黑,Microsoft YaHei;">fuzzydetect(self, image_path, data_type = 0, seq = '')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 标识图片信息<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url美食检测<span style="font-family: 微软雅黑,Microsoft YaHei;">fooddetect(self, image_path, data_type = 0, seq = '')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 标识图片信息<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url图片分类<span style="font-family: 微软雅黑,Microsoft YaHei;">imagetag(self, image_path, data_type = 0, seq = '')</span>参数<span style="font-family: 微软雅黑,Microsoft YaHei;">image_path</span> 标识图片信息<span style="font-family: 微软雅黑,Microsoft YaHei;">data_type</span> 用于表示image_path是图片还是url, 0代表图片,1代表url