国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術(shù)文章
文章詳情頁

python調(diào)用百度API實現(xiàn)人臉識別

瀏覽:47日期:2022-07-05 10:53:46

1、代碼

from aip import AipFaceimport cv2import timeimport base64from PIL import Imagefrom io import BytesIOimport pyttsx3# ''' 你的 APPID AK SK '''APP_ID = ’1965####’API_KEY = ’YXL65ekIloykyjrT4kzc####’SECRET_KEY = ’lFiapBoZ5eBwOFyxMbiwQDmClg1u####’client = AipFace(APP_ID, API_KEY, SECRET_KEY)# def frame2base64(frame):# img = Image.fromarray(frame) #將每一幀轉(zhuǎn)為Image# output_buffer = BytesIO() #創(chuàng)建一個BytesIO# img.save(output_buffer, format=’JPEG’) #寫入output_buffer# byte_data = output_buffer.getvalue() #在內(nèi)存中讀取# image = base64.b64encode(byte_data) #轉(zhuǎn)為BASE64# return image #轉(zhuǎn)碼成功 返回base64編碼def generate(): camera = cv2.VideoCapture(0) engine = pyttsx3.init() try: while True: engine = pyttsx3.init() ret, img = camera.read() cv2.imwrite('E://Ana/face.png',img) cv2.imshow('調(diào)用攝像頭', img) imageType = 'BASE64' groupIdList = '1,2,3,4' ''' 如果有可選參數(shù) ''' options = {} options['max_face_num'] = 4 options['match_threshold'] = 70 options['quality_control'] = 'NORMAL' options['liveness_control'] = 'NONE' # options['user_id'] = '233451' options['max_user_num'] = 4# ''' 帶參數(shù)調(diào)用人臉搜索 ''' with open('E://Ana/face.png', ’rb’) as fp:imageB = base64.b64encode(fp.read()) image = str(imageB, ’utf-8’) ''' 調(diào)用人臉搜索 ''' result = client.search(image, imageType, groupIdList, options) engine.runAndWait() print(2) if result:if not result[’result’]: continuename = result[’result’][’user_list’][0][’user_id’]#獲取名字score = result[’result’][’user_list’][0][’score’]#獲取相似度if name == ’cgh_1’: if score>80: print(score) print(name) engine.say('華來了')elif name == ’yjc_1’: if score > 80: print(score) print(name) engine.say('楊來了')elif name == ’cjy_1’: if score > 80: print(score) print(name) engine.say('言來了')elif name == ’hjy_1’: if score > 80: print(score) print(name) engine.say('怡來了')else: print('匹配失敗') else:continue except Exception as e: print(e) finally: # 釋放資源 engine.runAndWait() camera.release() cv2.destroyAllWindows() generate()

2、實現(xiàn)步驟

2.1、獲取百度ID和key

在百度API中可以申請到免費的API賬號,每天有免費的幾千次人臉識別,下圖為我申請的API賬號,然后在人臉庫中創(chuàng)建需要識別的人臉就行了

python調(diào)用百度API實現(xiàn)人臉識別

python調(diào)用百度API實現(xiàn)人臉識別

2.2、創(chuàng)建客戶端

APP_ID = ’1965####’API_KEY = ’YXL65ekIloykyjrT4kzc####’SECRET_KEY = ’lFiapBoZ5eBwOFyxMbiwQDmClg1u####’client = AipFace(APP_ID, API_KEY, SECRET_KEY)

2.3、實現(xiàn)人臉識別

主要內(nèi)容就是參數(shù)需要自己修改,然后獲取視頻圖像,然后通過對比看一下,對比出來的名字,然后再看一下分數(shù)即可,我在里面加了一個電腦播報的,所以只要識別出來,電腦就會播報,延遲不超過以秒。

到此這篇關(guān)于python調(diào)用百度API實現(xiàn)人臉識別的文章就介紹到這了,更多相關(guān)python 人臉識別內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標簽: 百度 Python
相關(guān)文章:
主站蜘蛛池模板: 和硕县| 大新县| 安新县| 渝北区| 孙吴县| 洛浦县| 安溪县| 卓资县| 阳西县| 同德县| 格尔木市| 洛扎县| 塔城市| 从化市| 江山市| 石棉县| 永泰县| 石泉县| 涟水县| 林周县| 灵宝市| 重庆市| 安国市| 永嘉县| 乌审旗| 仁布县| 浦县| 泰州市| 凤城市| 岳池县| 界首市| 屯留县| 株洲市| 淮安市| 西乌珠穆沁旗| 东辽县| 缙云县| 济南市| 梓潼县| 凤凰县| 韶关市|