最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時(shí)間:2020年11月17日 09:30:11   作者:難賦深情  
這篇文章主要介紹了python調(diào)用百度API實(shí)現(xiàn)人臉識(shí)別,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

1、代碼

from aip import AipFace
import cv2
import time
import base64
from PIL import Image
from io import BytesIO
import 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)建一個(gè)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)用人臉?biāo)阉?"""
      with open("E://Ana/face.png", 'rb') as fp:
        imageB = base64.b64encode(fp.read())
      image = str(imageB, 'utf-8')
      """ 調(diào)用人臉?biāo)阉?"""
      result = client.search(image, imageType, groupIdList, options)
      engine.runAndWait()
      print(2)
      if result:
        if not result['result']:
          continue
        name = 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("華來(lái)了")
        elif name == 'yjc_1':
          if score > 80:
            print(score)
            print(name)
            engine.say("楊來(lái)了")
        elif name == 'cjy_1':
          if score > 80:
            print(score)
            print(name)
            engine.say("言來(lái)了")
        elif name == 'hjy_1':
          if score > 80:
            print(score)
            print(name)
            engine.say("怡來(lái)了")
        else:
          print("匹配失敗")
      else:
        continue
  except Exception as e:
    print(e)
  finally:
    # 釋放資源
    engine.runAndWait()
    camera.release()
    cv2.destroyAllWindows()
 
generate()

2、實(shí)現(xiàn)步驟

2.1、獲取百度ID和key

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

在這里插入圖片描述

在這里插入圖片描述

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

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

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

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

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

相關(guān)文章

最新評(píng)論

子长县| 韶山市| 皮山县| 康定县| 巩留县| 古丈县| 巴楚县| 巴中市| 筠连县| 新丰县| 长汀县| 积石山| 宝坻区| 呼图壁县| 晋江市| 文水县| 巍山| 河东区| 英德市| 安化县| 揭东县| 易门县| 廊坊市| 湖口县| 阿瓦提县| 比如县| 河东区| 德安县| 陆丰市| 洱源县| 襄城县| 孟州市| 东方市| 蒲江县| 贵定县| 巴塘县| 公安县| 光泽县| 榆树市| 额敏县| 湟中县|