国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Face++ API實現(xiàn)手勢識別系統(tǒng)設(shè)計

2020-02-15 23:46:09
字體:
供稿:網(wǎng)友

        通過普通攝像頭拍攝出的照片來進(jìn)行識別是存在很大的困難的,但是有困難才能找到更好的方法去解決。在百度上大致找了一下手語識別的案例,很少。API只是看到了Face++發(fā)布的手勢識別,在我寫文章的時候又看到了百度發(fā)布的手勢識別API,之后會嘗試去進(jìn)行使用。

        這次使用的是Face++的API,F(xiàn)ace++的API是在之前發(fā)現(xiàn)的,功能上的話還是比較強(qiáng)大的,但是沒有離線版本,需要將數(shù)據(jù)進(jìn)行上傳,然后對JSON進(jìn)行解析得到結(jié)果。

這是官網(wǎng)給出的一個Demo,識別率挺不錯的,最后給出的是一個在20種手勢上的分布概率,接下來我們自己調(diào)用一下API分析自己的手勢。

1. 查看官方的API。找到Gesture API,先看一下是怎么說的。

調(diào)用參數(shù):

官方還給出了一些調(diào)用錯誤返回的參數(shù)的說明,有興趣的可以去官網(wǎng)看一下。

還給出了一個使用命令行調(diào)用API的實例:

從實例上不難看出,向 https://api-cn.faceplusplus.com/humanbodypp/beta/gesture 發(fā)送請求,默認(rèn)的參數(shù)有 api_key,api_secret,image_file。api_key和api_secret可以通過控制臺進(jìn)行生成。

接下來開始寫代碼的調(diào)用,Python版本的,其他版本的類似。

我們將API封裝成一個類 Gesture:

將其中的key和secret替換成自己的就可以使用:

'''# -*- coding:utf-8 -*-@author: TulLing'''import requests from json import JSONDecoder  gesture_englist = ['big_v','fist','double_finger_up','hand_open','heart_d','index_finger_up','ok','phonecall','palm_up','rock','thumb_down','thumb_up','victory']gesture_chinese = ["我最帥",   "拳頭,停下",   "我發(fā)誓",   "數(shù)字5",   "比心",   "數(shù)字1",   "好的呢,OK",   "打電話",   "手心向上",   "愛你,520",   "差評,不好的",   "好評,Good,很棒",   "勝利,開心"]# 將字典排序def sort_dict(adict): return sorted(adict.items(),key= lambda item:item[1]) class Gesture(object): def __init__(self): self.http_url = 'https://api-cn.faceplusplus.com/humanbodypp/beta/gesture' self.key = '*****' self.secret = '******' self.data = {"api_key":self.key,"api_secret":self.secret}   # 獲取手勢信息 def get_info(self,files): response = requests.post(self.http_url,data=self.data,files=files) req_con = response.content.decode('utf-8') req_dict = JSONDecoder().decode(req_con) #print(req_dict) if('error_message' not in req_dict.keys()) and (len(req_dict['hands'])): # 獲取  hands_dict = req_dict['hands']  #print(type(hands_dict))  # 獲取到手的矩形的字典  gesture_rectangle_dict = hands_dict[0]['hand_rectangle']  # 獲取到手勢的字典  gesture_dict = hands_dict[0]['gesture']    return gesture_dict,gesture_rectangle_dict else:  return [],[];  # 獲取到手勢文本信息 def get_text(self,index): return gesture_chinese[index]  # 獲取到手勢對應(yīng)的概率 def get_pro(self,gesture_dict,index): # print(gesture_dict) if(gesture_dict is None or gesture_dict == []):  return 0 return gesture_dict[gesture_englist[index]]  # 獲取到手勢的位置 def get_rectangle(self,gesture_rectangle_dict): if(gesture_rectangle_dict is None or gesture_rectangle_dict == []):  return (0,0,0,0) x = gesture_rectangle_dict['top'] y = gesture_rectangle_dict['left'] width = gesture_rectangle_dict['width'] height = gesture_rectangle_dict['height'] return (x,y,width,height)            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 岳普湖县| 洛宁县| 那曲县| 宝鸡市| 开鲁县| 安平县| 班玛县| 中江县| 喀什市| 秭归县| 惠安县| 遂宁市| 温州市| 丰台区| 阿拉善盟| 鄂托克前旗| 扶风县| 饶阳县| 鄂伦春自治旗| 永州市| 镇远县| 河北区| 宁强县| 云安县| 集贤县| 息烽县| 建湖县| 西安市| 新乡市| 麻阳| 神农架林区| 清原| 县级市| 洛阳市| 九寨沟县| 剑川县| 砚山县| 久治县| 长沙市| 循化| 东阳市|