人脸识别服务 FRS-Python SDK:SDK代码解析
时间:2024-10-17 17:48:14
SDK代码解析
- 人脸检测
# detect face by base64 def detectFaceByBase64(): try: request = DetectFaceByBase64Request() request.body = FaceDetectBase64Req( image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD...", attributes="2,4" ) response = client.detect_face_by_base64(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # detect face by file def detectFaceByFile(): try: request = DetectFaceByFileRequest() with open("/root/picture.jpg", "rb") as f: request.body = DetectFaceByFileRequestBody(image_file=FormFile(f)) response = client.detect_face_by_file(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 人脸比对
# compare face by base64 def compareFaceByBase64(): try: request = CompareFaceByBase64Request() request.body = FaceCompareBase64Req( image1_base64="/9j/4AAQSkZJRgABAQAAAQABAAD...", image2_base64="/9j/4AAQSkZJRgABAQAAAQABAAD..." ) response = client.compare_face_by_base64(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # compare face by file def compareFaceByFile(): try: request = CompareFaceByFileRequest() with open("/root/picture1.jpg", "rb") as f1: with open("/root/picture2.jpg", "rb") as f2: request.body = CompareFaceByFileRequestBody(image1_file=FormFile(f1), image2_file=FormFile(f2)) response = client.compare_face_by_file(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 人脸搜索
# search face by base64 def searchFaceByBase64(): try: request = SearchFaceByBase64Request() request.face_set_name = "face_set_name" listFaceSearchBase64ReqReturnFieldsbody = [ "timestamp" ] request.body = FaceSearchBase64Req( return_fields=listFaceSearchBase64ReqReturnFieldsbody, image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD..." ) response = client.search_face_by_base64(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # search face by file def searchFaceByFile(): try: request = SearchFaceByFileRequest() request.face_set_name = "face_set_name" with open("/root/picture.jpg", "rb") as f: request.body = SearchFaceByFileRequestBody( return_fields="[\"timestamp\"]", filter="timestamp:10", top_n=10, image_file=FormFile(f) ) response = client.search_face_by_file(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 创建人脸库
def createFaceSet(): try: request = CreateFaceSetRequest() request.body = CreateFaceSetReq( face_set_name="face_set_name", external_fields={"timestamp": {"type": "long"}} ) response = client.create_face_set(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 查询人脸库
def showFaceSet(): try: request = ShowFaceSetRequest() request.face_set_name = "face_set_name" response = client.show_face_set(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 查询所有人脸库
def showAllFaceSet(): try: request = ShowAllFaceSetsRequest() response = client.show_all_face_sets(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 删除人脸库
def deleteFaceSet(): try: request = DeleteFaceSetRequest() request.face_set_name = "face_set_name" response = client.delete_face_set(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 添加人脸
# add face by base64 def addFacesByBase64(): try: request = AddFacesByBase64Request() request.face_set_name = "face_set_name" request.body = AddFacesBase64Req( external_fields="{\"timestamp\":12}", image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD..." ) response = client.add_faces_by_base64(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # add face by file def addFacesByFile(): try: request = AddFacesByFileRequest() request.face_set_name = "face_set_name" with open("/root/picture.jpg", "rb") as f: request.body = AddFacesByFileRequestBody( external_fields="{\"timestamp\":12}", image_file=FormFile(f) ) response = client.add_faces_by_file(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 删除人脸
def deleteFace(): # Delete Face By FaceId try: request = DeleteFaceByFaceIdRequest() request.face_set_name = "face_set_name" request.face_id = "LkPJblq6" response = client.delete_face_by_face_id(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # Delete Face By ExternalImageId try: request = DeleteFaceByExternalImageIdRequest() request.face_set_name = "face_set_name" request.external_image_id = "external_image_id" response = client.delete_face_by_external_image_id(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 批量删除人脸
def batchDeleteFaces(): try: request = BatchDeleteFacesRequest() request.face_set_name = "face_set_name" request.body = DeleteFacesBatchReq( filter="age:[20 TO 30]" ) response = client.batch_delete_faces(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 更新人脸
def updateFace(): try: request = UpdateFaceRequest() request.face_set_name = "face_set_name" request.body = UpdateFaceReq(face_id="LkPJblq6") response = client.update_face(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 查询人脸
def showFaces(): # Show Faces By FaceId try: request = ShowFacesByFaceIdRequest() request.face_set_name = "face_set_name" request.face_id = "LkPJblq6" response = client.show_faces_by_face_id(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # Show Faces By Limit try: request = ShowFacesByLimitRequest() request.face_set_name = "face_set_name" request.offset = 0 request.limit = 10 response = client.show_faces_by_limit(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 动作活体检测
# detect live by base64 def detectLiveByBase64(): try: request = DetectLiveByBase64Request() request.body = LiveDetectBase64Req( actions="1,2,3,4", video_base64="/9j/4AAQSkZJRgABAQAAAQABAAD..." ) response = client.detect_live_by_base64(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # detect live by file def detectLiveByFile(): try: request = DetectLiveByFileRequest() with open("/root/video.mp4", "rb") as f: request.body = DetectLiveByFileRequestBody( video_file=FormFile(f), actions="1,2,3,4" ) response = client.detect_live_by_file(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
- 静默活体检测
# detect live face by base64 def detectLiveFaceByBase64(): try: request = DetectLiveFaceByBase64Request() request.body = LiveDetectFaceBase64Req( image_base64="/9j/4AAQSkZJRgABAQAAAQABAAD..." ) response = client.detect_live_face_by_base64(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) # detect live face by file def detectLiveFaceByFile(): try: request = DetectLiveFaceByFileRequest() with open("/root/picture.jpg", "rb") as f: request.body = DetectLiveFaceByFileRequestBody( image_file=FormFile(f) ) response = client.detect_live_face_by_file(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg)
support.huaweicloud.com/sdkreference-face/face_04_0021.html
看了此文的人还看了
CDN加速
GaussDB
文字转换成语音
免费的服务器
如何创建网站
域名网站购买
私有云桌面
云主机哪个好
域名怎么备案
手机云电脑
SSL证书申请
云点播服务器
免费OCR是什么
电脑云桌面
域名备案怎么弄
语音转文字
文字图片识别
云桌面是什么
网址安全检测
网站建设搭建
国外CDN加速
SSL免费证书申请
短信批量发送
图片OCR识别
云数据库MySQL
个人域名购买
录音转文字
扫描图片识别文字
OCR图片识别
行驶证识别
虚拟电话号码
电话呼叫中心软件
怎么制作一个网站
Email注册网站
华为VNC
图像文字识别
企业网站制作
个人网站搭建
华为云计算
免费租用云托管
云桌面云服务器
ocr文字识别免费版
HTTPS证书申请
图片文字识别转换
国外域名注册商
使用免费虚拟主机
云电脑主机多少钱
鲲鹏云手机
短信验证码平台
OCR图片文字识别
SSL证书是什么
申请企业邮箱步骤
免费的企业用邮箱
云免流搭建教程
域名价格
推荐文章