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

首頁(yè) > 編程 > Python > 正文

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

2020-01-04 14:00:55
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

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

Face++,API,手勢(shì)識(shí)別

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

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

Face++,API,手勢(shì)識(shí)別

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

Face++,API,手勢(shì)識(shí)別

Face++,API,手勢(shì)識(shí)別

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

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

Face++,API,手勢(shì)識(shí)別

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

Face++,API,手勢(shì)識(shí)別

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

我們將API封裝成一個(gè)類 Gesture:

Face++,API,手勢(shì)識(shí)別

將其中的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",   "打電話",   "手心向上",   "愛(ài)你,520",   "差評(píng),不好的",   "好評(píng),Good,很棒",   "勝利,開(kāi)心"]# 將字典排序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}   # 獲取手勢(shì)信息 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']  # 獲取到手勢(shì)的字典  gesture_dict = hands_dict[0]['gesture']    return gesture_dict,gesture_rectangle_dict else:  return [],[];  # 獲取到手勢(shì)文本信息 def get_text(self,index): return gesture_chinese[index]  # 獲取到手勢(shì)對(duì)應(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]]  # 獲取到手勢(shì)的位置 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)

封裝好了Gesture類后接下來(lái)就是調(diào)用:先將官方給出的手勢(shì)的圖片保存起來(lái),為了方便只保留單手的手勢(shì),然后生成隨機(jī)數(shù)讀取手勢(shì)圖片,我們?nèi)ツ7率謩?shì),后臺(tái)顯示是正確手勢(shì)的概率以及具體的位置,如果圖像中沒(méi)有手勢(shì)則概率為0,位置為(0,0,0,0)。

'''# -*- coding:utf-8 -*-@author: TulLing'''import syssys.path.append("../gesture/") import osimport randomimport cv2 as cvimport timeimport LearnGesture def gestureLearning(): os.system("cls") print("進(jìn)入學(xué)習(xí)手勢(shì)模式!") print("我們有13個(gè)手勢(shì),來(lái)和我學(xué)吧!(每次結(jié)束后可以選擇輸入 Q/q 退出!)") while(True): pic_num = random.randint(0,12) # 生成顯示的圖片的編號(hào)(隨機(jī)數(shù): 0 - 13) print(pic_num) pic_path = '../gesture/pic/gesture' + str(pic_num) + ".jpg" # 生成圖片路徑  pic = cv.imread(pic_path) # 加載圖片 pic = cv.resize(pic,(120,120)) cv.imshow("PIC",pic) # 顯示要學(xué)習(xí)的手勢(shì)  print("即將打開(kāi)攝像頭,你有5秒種的時(shí)間準(zhǔn)備手勢(shì),5秒種保持手勢(shì)!") write_path = "../gesture/pic/test.jpg" cap = cv.VideoCapture(1) while(True):  _,frame = cap.read()  cv.imshow("Frame",frame)  key = cv.waitKey(10)  if(key == ord('Q') or key == ord('q')):  cv.imwrite(write_path,frame)  cv.waitKey(200)  cap.release()  cv.destroyAllWindows()  break   # 此處應(yīng)該有手勢(shì)識(shí)別 files = {"image_file":open(write_path,'rb')} gesture = LearnGesture.Gesture()  # 獲取到手勢(shì)文本 ge_text = gesture.get_text(pic_num) # 獲取手勢(shì)信息 gesture_dict,gesture_rectangle_dict = gesture.get_info(files) # 獲取手勢(shì)的概率 ge_pro = gesture.get_pro(gesture_dict,pic_num) # 獲取到手勢(shì)的坐標(biāo) ge_rect = gesture.get_rectangle(gesture_rectangle_dict) print("您學(xué)習(xí)的手勢(shì)是:",ge_text) print("相似度達(dá)到:",ge_pro) print("具體位置:",ge_rect)   # print("一輪學(xué)習(xí)結(jié)束,是否繼續(xù)學(xué)習(xí)?(Y/N)") # 退出程序,回到主菜單或者繼續(xù) commend = input("一輪學(xué)習(xí)結(jié)束,是否繼續(xù)學(xué)習(xí)?(Y/N):") print(commend)  if( commend == 'N' or commend == "n"):  breakgestureLearning()

Face++,API,手勢(shì)識(shí)別

圖片保存的路徑:./pic/

運(yùn)行結(jié)果:

Face++,API,手勢(shì)識(shí)別

顯示的隨機(jī)手勢(shì)

Face++,API,手勢(shì)識(shí)別

模仿的手勢(shì)(打個(gè)碼,主要看手)

點(diǎn)擊Q后:

Face++,API,手勢(shì)識(shí)別

手勢(shì)做的有點(diǎn)不標(biāo)準(zhǔn),但是沒(méi)關(guān)系,系統(tǒng)可以運(yùn)行。

調(diào)用Face++API的文章到此結(jié)束。代碼打包后會(huì)上傳。之后會(huì)修改鏈接地址。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持VEVB武林網(wǎng)。


注:相關(guān)教程知識(shí)閱讀請(qǐng)移步到python教程頻道。
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乌审旗| 扬中市| 辉县市| 陆川县| 长岭县| 莲花县| 盘锦市| 仪征市| 云南省| 姜堰市| 乳山市| 台湾省| 綦江县| 卢龙县| 阿拉善左旗| 孟州市| 阜城县| 新安县| 邹城市| 神木县| 商南县| 临沭县| 额敏县| 泉州市| 澜沧| 年辖:市辖区| 襄汾县| 三台县| 志丹县| 周口市| 安康市| 阳高县| 沙坪坝区| 尉犁县| 兰西县| 集安市| 原平市| 巴青县| 九台市| 鲜城| 林州市|