GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-sdk/python-sdk/call.py at master · Shenxudong/python-sdk Expand file tree/ Copy pathcall.pyMore file actions 96 lines (76 loc) · 3.32 KB / Copy pathcall.pyFile metadata and controls96 lines (76 loc) · 3.32 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 #-*- coding: utf-8 -*- # 您需要先注册一个App,并将得到的API key和API secret写在这里。 # You need to register your App first, and enter you API key/secret. API_KEY = "<YOUR_API_KEY>" API_SECRET = "<YOUR_API_SECRETַ>" # 网络图片的URL地址,调用demo前请填上内容 # The url of network picture, please fill in the contents before calling demo face_one = 'http://bj-mc-prod-asset.oss-cn-beijing.aliyuncs.com/mc-official/images/face/demo-pic11.jpg' # 本地图片的地址,调用demo前请填上内容 # Local picture location, please fill in the contents before calling demo face_two = './demo.jpeg' # 本地图片的地址,调用demo前请填上内容 # Local picture location, please fill in the contents before calling demo face_search = './demo.jpeg' #国际版的服务器地址 #the server of international version api_server_international = 'https://api-us.faceplusplus.com/facepp/v3/' # Import system libraries and define helper functions # 导入系统库并定义辅助函数 from pprint import pformat def print_result(hit, result): def encode(obj): if type(obj) is unicode: return obj.encode('utf-8') if type(obj) is dict: return {encode(v): encode(k) for (v, k) in obj.iteritems()} if type(obj) is list: return [encode(i) for i in obj] return obj print hit result = encode(result) print '\n'.join(" " + i for i in pformat(result, width=75).split('\n')) # First import the API class from the SDK # 首先,导入SDK中的API类 from facepp import API, File #创建一个API对象,如果你是国际版用户,代码为:api = API(API_KEY, API_SECRET, srv=api_server_international) #Create a API object, if you are an international user,code: api = API(API_KEY, API_SECRET, srv=api_server_international) api = API(API_KEY, API_SECRET) # 创建一个Faceset用来存储FaceToken # create a Faceset to save FaceToken ret = api.faceset.create(outer_id='test') print_result("faceset create", ret) # 对图片进行检测 # detect image Face = {} res = api.detect(image_url=face_one) print_result("person_one", res) Face['person_one'] = res["faces"][0]["face_token"] res = api.detect(image_file=File(face_two)) print_result("person_two", res) Face['person_two'] = res["faces"][0]["face_token"] # 将得到的FaceToken存进Faceset里面 # save FaceToken in Faceset api.faceset.addface(outer_id='test', face_tokens=Face.itervalues()) # 对待比对的图片进行检测,再搜索相似脸 # detect image and search same face ret = api.detect(image_file=File(face_search)) print_result("detect", ret) search_result = api.search(face_token=ret["faces"][0]["face_token"], outer_id='test') # 输出结果 # print result print_result('search', search_result) print '=' * 60 for k, v in Face.iteritems(): if v == search_result['results'][0]['face_token']: print 'The person with highest confidence:', k break # 删除无用的人脸库 # delect faceset because it is no longer needed api.faceset.delete(outer_id='test', check_empty=0) # 恭喜!您已经完成了本教程,可以继续阅读我们的API文档并利用Face++ API开始写您自 # 己的App了! # 旅途愉快 :) # Congratulations! You have finished this tutorial, and you can continue # reading our API document and start writing your own App using Face++ API! # Enjoy :) |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |