# API **Repository Path**: ifishes/api ## Basic Information - **Project Name**: API - **Description**: 大二上API作业笔记 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-10-24 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## API - 不同平台人脸识别(面部检测/人脸集合) 「azure、face++、BAIDU」 - 计算机视觉 - 学习心得 --- --- ### AZURE人脸识别 ``` import requests # 1、create 列表 # faceListId faceListId = "ljx_635" #设置人脸列表ID create_facelists_url = "https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}" subscription_key = "4f253843772f42e89e959977f6149561" assert subscription_key headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': subscription_key, } data = { "name": "ljx_987", "userData": "30人", "recognitionModel": "recognition_03", } r_create = requests.put(create_facelists_url.format(faceListId),headers=headers,json=data) --- r_create.content --- # 已经成功创建facelist(云端/云计算) --- #先加一张脸试试 # 2、Add face add_face_url = "https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedfaces"#学生填写 assert subscription_key headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': subscription_key, } img_url = 'http://huangjieqi.gitee.io/picture_storage/hjq.jpg'#学生填写 params_add_face={ "userData":"huangjieqi" #学生填写 } r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={"url":img_url}) --- r_add_face.status_code --- r_add_face.json()#返回persistedFaceId # {'persistedFaceId': '07c5f161-a95f-4ea2-9643-e01cd39669aa'} --- # 封装成函数方便添加图片 def AddFace(img_url=str,userData=str): add_face_url ="https://api-hjq.cognitiveservices.azure.com/face/v1.0/facelists/{}/persistedFaces" assert subscription_key headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': subscription_key, } img_url = img_url params_add_face={ "userData":userData } r_add_face = requests.post(add_face_url.format(faceListId),headers=headers,params=params_add_face,json={"url":img_url}) return r_add_face.status_code#返回出状态码 --- AddFace("http://huangjieqi.gitee.io/picture_storage/Autumnhui.jpg","丘天惠") AddFace("http://huangjieqi.gitee.io/picture_storage/L-Tony-info.jpg","林嘉茵") AddFace("http://huangjieqi.gitee.io/picture_storage/TLINGP.jpg","汤玲萍") AddFace("http://huangjieqi.gitee.io/picture_storage/WenYanZeng.jpg","曾雯燕") AddFace("http://huangjieqi.gitee.io/picture_storage/XIEIC.jpg","谢依希") AddFace("http://huangjieqi.gitee.io/picture_storage/YuecongYang.png","杨悦聪") AddFace("http://huangjieqi.gitee.io/picture_storage/Zoezhouyu.jpg","周雨") AddFace("http://huangjieqi.gitee.io/picture_storage/crayon-heimi.jpg","刘瑜鹏") AddFace("http://huangjieqi.gitee.io/picture_storage/jiayichen.jpg","陈嘉仪") AddFace("http://huangjieqi.gitee.io/picture_storage/kg2000.jpg","徐旖芊") AddFace("http://huangjieqi.gitee.io/picture_storage/liuxinrujiayou.jpg","刘心如") AddFace("http://huangjieqi.gitee.io/picture_storage/liuyu19.png","刘宇") AddFace("http://huangjieqi.gitee.io/picture_storage/ltco.jpg","李婷") AddFace("http://huangjieqi.gitee.io/picture_storage/lucaszy.jpg","黄智毅") AddFace("http://huangjieqi.gitee.io/picture_storage/pingzi0211.jpg","黄慧文") AddFace("http://huangjieqi.gitee.io/picture_storage/shmimy-cn.jpg","张铭睿") AddFace("http://huangjieqi.gitee.io/picture_storage/yichenting.jpg","陈婷") AddFace("http://huangjieqi.gitee.io/picture_storage/coco022.jpg","洪可凡") AddFace("http://huangjieqi.gitee.io/picture_storage/lujizhi.png","卢继志") AddFace("http://huangjieqi.gitee.io/picture_storage/zzlhyy.jpg","张梓乐") --- # Get facelist get_facelist_url = "https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}" #学生填写 r_get_facelist = requests.get(get_facelist_url.format(faceListId),headers=headers,params=params_add_face,json={"url":img_url})#学生填写 r_get_facelist.json() # {'persistedFaces': [{'persistedFaceId': '07c5f161-a95f-4ea2-9643-e01cd39669aa', 'userData': 'huangjieqi'}, {'persistedFaceId': 'd9ae47e8-4624-4d6f-8e1b-02b852cc5e37', 'userData': '丘天惠'}, {'persistedFaceId': '2722e234-648a-42ad-8116-c796c4a48a59', 'userData': '林嘉茵'}, {'persistedFaceId': 'bfe8c5c1-a71f-4203-a0ea-5a8faeab2d14', 'userData': '汤玲萍'}, {'persistedFaceId': 'c90535ea-791a-4253-9a7d-ff355ef2b84a', 'userData': '曾雯燕'}, {'persistedFaceId': '60f422bc-314c-47e1-bbc6-2981a1f21c87', 'userData': '谢依希'}, {'persistedFaceId': '80211287-0099-4cb6-a14b-2f45ce777a45', 'userData': '杨悦聪'}, {'persistedFaceId': '9d6ce05e-aa64-4b68-9d6b-13aa396dd141', 'userData': '周雨'}, {'persistedFaceId': '689b444e-27eb-4be4-bfb4-886a3b40b01f', 'userData': '刘瑜鹏'}, {'persistedFaceId': '44588497-8f59-407f-b7d0-e10862d58be4', 'userData': '陈嘉仪'}, {'persistedFaceId': 'fd034f7c-db25-4384-a5d5-a82ae3f18345', 'userData': '徐旖芊'}, {'persistedFaceId': '5b4c3c65-aa12-4e2e-873f-0db8e0bd1e0c', 'userData': '刘心如'}, {'persistedFaceId': '386b4131-2a3c-42b8-8b88-85dedd76fec7', 'userData': '刘宇'}, {'persistedFaceId': 'a483ebbe-3a89-4d54-b705-0e7dd58557f2', 'userData': '李婷'}, {'persistedFaceId': '0e0b50c4-015b-41ec-823d-a3c22bb8909d', 'userData': '黄智毅'}, {'persistedFaceId': 'b780d5db-eb1b-46b7-8b82-5cb64c702411', 'userData': '黄慧文'}, {'persistedFaceId': '40eaf916-c8c6-4672-a3bc-544e98914f72', 'userData': '张铭睿'}, {'persistedFaceId': 'f636f343-e378-4b1c-beba-3312542785ef', 'userData': '陈婷'}, {'persistedFaceId': 'bef8c2ae-1e13-40c1-8706-4f1a4623b00a', 'userData': '洪可凡'}, {'persistedFaceId': 'd20874a6-c4ee-406d-a1fd-dc20e4a8e39f', 'userData': '卢继志'}, {'persistedFaceId': '12398f13-7e96-4ad2-87bd-5e18f25bab4b', 'userData': '张梓乐'}], 'faceListId': 'ljx_635', 'name': 'ljx_987', 'userData': '30人'} --- faceListId = "ljx_635"#删除人脸列表 # 学生填写 --- # Detect face 删除列表内人脸id delete_face_url = "https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}"#学生填写 assert subscription_key persistedFaceId = r_add_face.json()["persistedFaceId"] # 直接取上面获得的ID{'persistedFaceId': 'f18450d3-60d2-45f3-a69e-783574dc3ce8'} headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': subscription_key, } # 注意requests请求为delete r_delete_face = requests.delete(delete_face_url.format(faceListId,persistedFaceId),headers=headers,params=params_add_face,json={"url":img_url})#学生填写 r_get_facelist.json()#学生填写 # {'persistedFaces': [{'persistedFaceId': '07c5f161-a95f-4ea2-9643-e01cd39669aa', 'userData': 'huangjieqi'}, {'persistedFaceId': 'd9ae47e8-4624-4d6f-8e1b-02b852cc5e37', 'userData': '丘天惠'}, {'persistedFaceId': '2722e234-648a-42ad-8116-c796c4a48a59', 'userData': '林嘉茵'}, {'persistedFaceId': 'bfe8c5c1-a71f-4203-a0ea-5a8faeab2d14', 'userData': '汤玲萍'}, {'persistedFaceId': 'c90535ea-791a-4253-9a7d-ff355ef2b84a', 'userData': '曾雯燕'}, {'persistedFaceId': '60f422bc-314c-47e1-bbc6-2981a1f21c87', 'userData': '谢依希'}, {'persistedFaceId': '80211287-0099-4cb6-a14b-2f45ce777a45', 'userData': '杨悦聪'}, {'persistedFaceId': '9d6ce05e-aa64-4b68-9d6b-13aa396dd141', 'userData': '周雨'}, {'persistedFaceId': '689b444e-27eb-4be4-bfb4-886a3b40b01f', 'userData': '刘瑜鹏'}, {'persistedFaceId': '44588497-8f59-407f-b7d0-e10862d58be4', 'userData': '陈嘉仪'}, {'persistedFaceId': 'fd034f7c-db25-4384-a5d5-a82ae3f18345', 'userData': '徐旖芊'}, {'persistedFaceId': '5b4c3c65-aa12-4e2e-873f-0db8e0bd1e0c', 'userData': '刘心如'}, {'persistedFaceId': '386b4131-2a3c-42b8-8b88-85dedd76fec7', 'userData': '刘宇'}, {'persistedFaceId': 'a483ebbe-3a89-4d54-b705-0e7dd58557f2', 'userData': '李婷'}, {'persistedFaceId': '0e0b50c4-015b-41ec-823d-a3c22bb8909d', 'userData': '黄智毅'}, {'persistedFaceId': 'b780d5db-eb1b-46b7-8b82-5cb64c702411', 'userData': '黄慧文'}, {'persistedFaceId': '40eaf916-c8c6-4672-a3bc-544e98914f72', 'userData': '张铭睿'}, {'persistedFaceId': 'f636f343-e378-4b1c-beba-3312542785ef', 'userData': '陈婷'}, {'persistedFaceId': 'bef8c2ae-1e13-40c1-8706-4f1a4623b00a', 'userData': '洪可凡'}, {'persistedFaceId': 'd20874a6-c4ee-406d-a1fd-dc20e4a8e39f', 'userData': '卢继志'}, {'persistedFaceId': '12398f13-7e96-4ad2-87bd-5e18f25bab4b', 'userData': '张梓乐'}], 'faceListId': 'ljx_635', 'name': 'ljx_987', 'userData': '30人'} In [36]: --- r_delete_face --- # Detect face 删除列表内人脸列表 delete_face_url = "https://face-ozl.cognitiveservices.azure.com/face/v1.0/facelists/{}"#学生填写 assert subscription_key headers = { # Request headers 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key': subscription_key, } # format内直接删除 # 注意requests请求为delete r_delete_facelist = requests.delete(delete_face_url.format(faceListId),headers=headers)#学生填写 --- r_delete_facelist --- # 3、检测人脸的id # replace with the string from your endpoint URL face_api_url = 'https://api-hjq.cognitiveservices.azure.com/face/v1.0/detect' # 请求正文 image_url = 'http://huangjieqi.gitee.io/picture_storage/hjq.jpg' headers = {'Ocp-Apim-Subscription-Key': subscription_key} # 请求参数 params = { 'returnFaceId': 'true', 'returnFaceLandmarks': 'false', # 选择model 'recognitionModel':'recognition_03',#此参数需与facelist参数一致 'detectionModel':'detection_01', # 可选参数,请仔细阅读API文档 'returnFaceAttributes': 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise', } response = requests.post(face_api_url, params=params, headers=headers, json={"url": image_url}) # json.dumps 将json--->字符串 response.json() # [{'faceId': 'fc29b492-1e72-4a2c-821c-011a96b01467', 'faceRectangle': {'top': 264, 'left': 207, 'width': 277, 'height': 277}, 'faceAttributes': {'smile': 0.0, 'headPose': {'pitch': 1.7, 'roll': -19.8, 'yaw': -13.9}, 'gender': 'male', 'age': 21.0, 'facialHair': {'moustache': 0.1, 'beard': 0.1, 'sideburns': 0.1}, 'glasses': 'NoGlasses', 'emotion': {'anger': 0.0, 'contempt': 0.002, 'disgust': 0.0, 'fear': 0.0, 'happiness': 0.0, 'neutral': 0.969, 'sadness': 0.029, 'surprise': 0.0}, 'blur': {'blurLevel': 'medium', 'value': 0.44}, 'exposure': {'exposureLevel': 'goodExposure', 'value': 0.68}, 'noise': {'noiseLevel': 'medium', 'value': 0.39}, 'makeup': {'eyeMakeup': False, 'lipMakeup': False}, 'accessories': [], 'occlusion': {'foreheadOccluded': False, 'eyeOccluded': False, 'mouthOccluded': False}, 'hair': {'bald': 0.18, 'invisible': False, 'hairColor': [{'color': 'brown', 'confidence': 0.97}, {'color': 'black', 'confidence': 0.9}, {'color': 'red', 'confidence': 0.38}, {'color': 'other', 'confidence': 0.23}, {'color': 'blond', 'confidence': 0.15}, {'color': 'gray', 'confidence': 0.09}, {'color': 'white', 'confidence': 0.0}]}}}] --- findsimilars_url = "https://api-hjq.cognitiveservices.azure.com/face/v1.0/findsimilars" # 请求正文 faceId需要先检测一张照片获取 data_findsimilars = { "faceId":"68548402-46f3-437b-9123-d51bbbe33af8",#取上方的faceID "faceListId": "zhichao01", "maxNumOfCandidatesReturned": 10, "mode": "matchFace"#matchPerson #一种为验证模式,一种为相似值模式 } r_findsimilars = requests.post(findsimilars_url,headers=headers,json=data_findsimilars) ``` --- --- ### BAIDU ``` import requests # client_id 为官网获取的API Key, client_secret 为官网获取的Secret Key host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id={}&client_secret={}' client_id = "DlnpohsOvQe6j7q2yaXi4k5n" client_secret = "wQm2WIij5jy7uAl6rxbHeScmIt8kS5ma" response = requests.get(host.format(client_id, client_secret)) if response: print(response.json()) # {'refresh_token': '25.de54e4ebd852752e0606811615114e75.315360000.1918819076.282335-22838595', 'expires_in': 2592000, 'session_key': '9mzdXUbOcgipXDz8U88KTdlM79deN/rPZKvZc7zZUNS+elFKGjBgm9G0+HGHvNwsx0Dswo9tosumAfQphK8a1DizZ2iXng==', 'access_token': '24.f2fa6a48e0a6e8b756bd662f46c89ef2.2592000.1606051076.282335-22838595', 'scope': 'public brain_all_scope vis-faceverify_faceverify_h5-face-liveness vis-faceverify_FACE_V3 vis-faceverify_idl_face_merge vis-faceverify_FACE_EFFECT wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component', 'session_secret': 'cda7d24f2b96bbca02454fd5c6cce694'} # 1.人脸检测与属性分析 request_url = "https://aip.baidubce.com/rest/2.0/face/v3/detect" params = "{\"image\":\"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1354941954,4086942311&fm=26&gp=0.jpg\",\"image_type\":\"URL\",\"face_field\":\"faceshape,facetype\"}" access_token = '24.6d684a22feb8384590448aa0f4edcb8e.2592000.1605596154.282335-22838595' # 调用鉴权接口获取的token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/json'} response = requests.post(request_url, data=params, headers=headers) response.json() # {'error_code': 0, # 'error_msg': 'SUCCESS', # 'log_id': 2599890579153, # 'timestamp': 1603459076, # 'cached': 0, # 'result': {'face_num': 1, # 'face_list': [{'face_token': 'c7029f73038bb572d1db4789088f85f5', # 'location': {'left': 73.58, 'top': 76.94, 'width': 38, 'height': 40, 'rotation': -3}, 'face_probability': 1, 'angle': {'yaw': -18.12, 'pitch': 10.44, 'roll': -4.81}, 'face_shape': {'type': 'round', 'probability': 0.45}, 'face_type': {'type': 'human', 'probability': 0.99}}]}} # 2.人脸对比 request_url = "https://aip.baidubce.com/rest/2.0/face/v3/match" params = "[{\"image\": \"https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3430692674,459091344&fm=26&gp=0.jpg\", \"image_type\": \"URL\", \"face_type\": \"CERT\", \"quality_control\": \"LOW\"}, {\"image\": \"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1603015508446&di=eee4e2c852d804bc3b80a719df3df9ef&imgtype=0&src=http%3A%2F%2Fimg2-cloud.itouchtv.cn%2Ftvtouchtv%2Fimage%2F20170914%2F1505363583630378.jpg\", \"image_type\": \"URL\", \"face_type\": \"LIVE\", \"quality_control\": \"LOW\"}]" # face_type 人脸的类型 LIVE;IDCARD;WATERMARK;CERT;INFRARED。 access_token = '24.6d684a22feb8384590448aa0f4edcb8e.2592000.1605596154.282335-22838595' # 调用鉴权接口获取的token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/json'} response = requests.post(request_url, data=params, headers=headers) response.json() # {'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 9965356579652, 'timestamp': 1603459108, 'cached': 0, 'result': {'score': 94.37832642, 'face_list': [{'face_token': '91cf0a5aa45b0371989e56760b30548c'}, {'face_token': '93d2501e1cb1685c26107d0b19cc854a'}]}} # 3.创建用户组 request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/add" params = "{\"group_id\":\"group2\"}" access_token = '24.6d684a22feb8384590448aa0f4edcb8e.2592000.1605596154.282335-22838595' # 调用鉴权接口获取的token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/json'} response = requests.post(request_url, data=params, headers=headers) response.json() # {'error_code': 223101, 'error_msg': 'group already exist', 'log_id': 9910100135201, 'timestamp': 1603459122, 'cached': 0, 'result': None} # 4.人脸注册 request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add" params = "{\"image\":\"91cf0a5aa45b0371989e56760b30548c\",\"image_type\":\"FACE_TOKEN\",\"group_id\":\"group1\",\"user_id\":\"user1\",\"user_info\":\"abc\",\"quality_control\":\"LOW\",\"liveness_control\":\"NORMAL\"}" access_token = '24.6d684a22feb8384590448aa0f4edcb8e.2592000.1605596154.282335-22838595' # 调用鉴权接口获取的token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/json'} response = requests.post(request_url, data=params, headers=headers) response.json() # {'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 1575991011017, 'timestamp': 1603459132, 'cached': 0, 'result': {'face_token': '91cf0a5aa45b0371989e56760b30548c', 'location': {'left': 186.93, 'top': 99.21, 'width': 121, 'height': 118, 'rotation': 1}}} # 5.获取用户人脸列表 request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/getlist" params = "{\"user_id\":\"user1\",\"group_id\":\"group2\"}" access_token = '24.6d684a22feb8384590448aa0f4edcb8e.2592000.1605596154.282335-22838595' # 调用鉴权接口获取的token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/json'} response = requests.post(request_url, data=params, headers=headers) response.json() # {'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 1589558935897, 'timestamp': 1603459143, 'cached': 0, 'result': {'face_list': [{'face_token': '91cf0a5aa45b0371989e56760b30548c', 'ctime': '2020-10-23 17:46:47'}]}} # 6.删除用户组 request_url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/delete" params = "{\"group_id\":\"group1\"}" access_token = '24.6d684a22feb8384590448aa0f4edcb8e.2592000.1605596154.282335-22838595' # 调用鉴权接口获取的token request_url = request_url + "?access_token=" + access_token headers = {'content-type': 'application/json'} response = requests.post(request_url, data=params, headers=headers) response.json() # {'error_code': 0, 'error_msg': 'SUCCESS', 'log_id': 525845594995, 'timestamp': 1603459154, 'cached': 0, 'result': None} ``` --- --- ### face++ ``` api_secret = '-IBzTcGyzotqF2vBQ8NdZ0aoVziYQa6E' api_key = 'AFTMRe1FWygdf3wiswKwkM-B2UVlDMTq' # 1. FaceSet Create import requests,json display_name = "网新一班人脸集合" outer_id = "00001" user_data = "52人,20男生,32女生" CreateFace_Url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/create" payload = { 'api_key': api_key, 'api_secret': api_secret, 'display_name':display_name, 'outer_id':outer_id, 'user_data':user_data } r = requests.post(CreateFace_Url, params=payload) r.json() # 运行结果 # {'faceset_token': '5f32ae674da816294a0a8f2714081121', # 'time_used': 166, # 'face_count': 0, # 'face_added': 0, # 'request_id': '1603523490,456fbd46-17a4-41ff-9286-a80081299986', # 'outer_id': '00001', # 'failure_detail': []} --- GetDetail_Url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail" payload = { 'api_key': api_key, 'api_secret': api_secret, 'outer_id':outer_id, } r = requests.post(GetDetail_Url,params=payload) r.json() # 运行结果 # {'faceset_token': '5f32ae674da816294a0a8f2714081121', # 'tags': '', # 'time_used': 84, # 'user_data': '52人,20男生,32女生', # 'display_name': '网新一班人脸集合', # 'face_tokens': [], # 'face_count': 0, # 'request_id': '1603523497,38e334fd-62e7-4c88-ad89-12caffa72d8a', # 'outer_id': '00001'} --- AddFace_url = " https://api-cn.faceplusplus.com/facepp/v3/faceset/addface" payload = { 'api_key': api_key, 'api_secret': api_secret, 'faceset_token':'37071d95016c1b2d81591a6f0c1681f2', 'face_tokens':'b0407b9e803ebd39d511cd7956fd5bf5', } r = requests.post(AddFace_url,params=payload) r.json() # 运行结果 # {'time_used': 61, # 'error_message': 'INVALID_FACESET_TOKEN', # 'request_id': '1603523499,e585884c-188b-4c36-99ef-fcf0516fe6a6'} --- RemoveFace_url = " https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface" payload = { 'api_key': api_key, 'api_secret': api_secret, 'faceset_token':'37071d95016c1b2d81591a6f0c1681f2', 'face_tokens':'b0407b9e803ebd39d511cd7956fd5bf5', } r = requests.post(RemoveFace_url,params=payload) r.json() # 运行结果 # {'time_used': 70, # 'error_message': 'INVALID_FACESET_TOKEN', # 'request_id': '1603523501,6170a338-6b06-40c1-81d7-7e0d71d92d37'} --- Update_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/update" payload = { 'api_key': api_key, 'api_secret': api_secret, 'faceset_token':'37071d95016c1b2d81591a6f0c1681f2', 'user_data':"53人,21男生,32女生", } r = requests.post(Update_url,params=payload) r.json() # 运行结果 # {'time_used': 69, # 'error_message': 'INVALID_FACESET_TOKEN', # 'request_id': '1603523530,0364956b-81a4-4f05-9b7f-d4838f2783e8'} --- liudehua01 = "https://gss0.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/7c1ed21b0ef41bd57f7f20ff57da81cb39db3d89.jpg" liudehua02 = "https://tse3-mm.cn.bing.net/th/id/OIP.Xz3HbYZeNrdUnGJ7vXNzsQHaKO?pid=Api&rs=1" wangzulan = "https://tse3-mm.cn.bing.net/th/id/OIP.ZnXeGoVYT4jQudiPOGZn3QAAAA?pid=Api&rs=1" --- Compare_url = "https://api-cn.faceplusplus.com/facepp/v3/compare" payload ={ 'api_key': api_key, 'api_secret': api_secret, 'image_url1':liudehua01, 'image_url2':wangzulan } r = requests.post(Compare_url,params=payload) r.json() # 运行结果 # {'faces1': [{'face_rectangle': {'width': 824, # 'top': 871, # 'left': 1114, # 'height': 824}, # 'face_token': '7b490ce46c0cad6bae2fe924b649d76f'}], # 'faces2': [{'face_rectangle': {'width': 86, # 'top': 91, # 'left': 65, # 'height': 86}, # 'face_token': '51c57afd776c3f50b6102d39aeded6b1'}], # 'time_used': 3744, # 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101}, # 'confidence': 26.085, # 'image_id2': 'g6kg8zfyOouG6ftP+GvEfg==', # 'image_id1': 'KIOXEC2V/MyL4zuopAcNig==', # 'request_id': '1603523985,3f8f2e25-d196-4f55-babe-4d3b570422ae'} --- Detect_url = 'https://api-cn.faceplusplus.com/facepp/v3/detect' img_url = liudehua01 payload = { "image_url":img_url, 'api_key': api_key, 'api_secret': api_secret, 'return_attributes':'gender,age,smiling,emotion', } r = requests.post(Detect_url,params=payload) r.json() # 运行结果 # {'request_id': '1603524009,a2c7b2c3-5943-49d7-b7e2-6544491ba87f', # 'time_used': 3319, # 'faces': [{'face_token': 'bfca0e148dfeb1d5eed4fd1a3d70e064', # 'face_rectangle': {'top': 871, 'left': 1114, 'width': 824, 'height': 824}, # 'attributes': {'gender': {'value': 'Male'}, # 'age': {'value': 59}, # 'smile': {'value': 99.998, 'threshold': 50.0}, # 'emotion': {'anger': 0.0, # 'disgust': 0.047, # 'fear': 0.0, # 'happiness': 99.945, # 'neutral': 0.0, # 'sadness': 0.007, # 'surprise': 0.0}}}], # 'image_id': 'KIOXEC2V/MyL4zuopAcNig==', # 'face_num': 1} --- ``` ### 学习心得 - 课上课下都不简单,可能是因为对API这个东西具体在每个地方能起到什么样的作用不够深入了解,因此没有很大的兴趣。api比网站设计什么的要枯燥的多,也很难快速的拥有一个“成品”,所以要长期坚持的学习下去是很难得。学习内容中杂糅了很多不同课程的知识,对新学的python也有很大程度的涉及,所以困难重重。虽然说和同学们一起交流作业哪里错误然后敲出代码会有很大的成就感,但时常有想放弃的想法。希望后面可以摆正自己的心态试着积极跨过这些挑战。