欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

python 使用百度API實現人臉對比識別

系統 1838 0
  • 要求

    1.安裝百度python API
    2.到百度智能云創建應用
    3.調用API,代碼

1.安裝百度python API

使用pip安裝
pip3 install baidu-api

2.到 百度智能云創建應用

-如下圖
python 使用百度API實現人臉對比識別_第1張圖片
創建應用得到
APP_ID
API_KEY
SECRET_KEY
python 使用百度API實現人臉對比識別_第2張圖片

3.調用API,代碼

            
              from aip import AipFace
import base64
import urllib
import cv2
""" 你的 APPID AK SK """
APP_ID = '你的 APP_ID   '
API_KEY = '你的 API_KEY'
SECRET_KEY = '你的SECRET_KEY '
client = AipFace(APP_ID, API_KEY, SECRET_KEY)

def fileopen(filepath): #打開圖片
    with open(filepath, 'rb') as f:
        data = base64.b64encode(f.read())
    image = str(data,'utf-8')
    return image

def CatchUsbVideo(window_name,camera_idx):
    cv2.namedWindow(window_name)
    #視頻來源,可以來自一段已存好的視頻,也可以直接來自USB攝像頭
    cap = cv2.VideoCapture(camera_idx)
    #識別出人臉后要畫的邊框的顏色,RGB格式
    color = (0, 255, 0)
    while cap.isOpened():
        ok, frame = cap.read() #讀取一幀數據
        if not ok:            
            break
        c = cv2.waitKey(10)#按q退出
        cv2.imshow(window_name, frame)
        if c == ord('p'):
            cv2.imwrite('p1.jpg',frame)#保存圖片
            print('圖片保存成功')
            break
        if c == ord('o'):
            cv2.imwrite('p2.jpg',frame)#保存圖片
            break
        if c  == ord('q'):
            break        
    #釋放攝像頭并銷毀所有窗口
    cap.release()
    cv2.destroyAllWindows()  
    
def face_detect(filepath1,filepath2):  #人臉對比
    image1 = fileopen(filepath1)
    image2 = fileopen(filepath2)
    result = client.match([
    {
        'image': image1,
        'image_type': 'BASE64',
    },
    {
        'image': image2,
        'image_type': 'BASE64',
    }])
    print(result)              #打印出所有的信息
    
def face_add(filepath,groupid,userid):  #人臉庫增加 地址 組 用戶
    image = fileopen(filepath)
    imageType="BASE64"
    result=client.addUser(image,imageType,groupid,userid)
    if result['error_code']==0:
        print("增加人臉成功")
    else:
        print("增加人臉失敗")
        
def face_search(filepath,groupIdList):  #人臉庫搜索  222207 groupIdList="你的用戶組名稱"
    image = fileopen(filepath)
    imageType="BASE64"
    result=client.search(image,imageType,groupIdList)
    print(result)            #打印出所有信息

if __name__ == '__main__':
    #face_comper()
    #face_detect('p1.jpg','p2.jpg')
    #face_add('p1.jpg','test','one')
    #face_search('p2.jpg','test')
    CatchUsbVideo('window_name',0)
 

            
          

我是使用opencv打開攝像頭來拍取照片并上傳的
注意要上傳的圖片格式要經過 base64編碼并str強制類型轉換才能使用,因為可能base64編碼+,-,=這些符號還是ascll碼,不然可能會報錯,代碼如下

            
              def fileopen(filepath): #打開圖片
    with open(filepath, 'rb') as f:
        data = base64.b64encode(f.read())
    image = str(data,'utf-8')
    return image

            
          

這里是一些子函數

            
              def test1():
    with open("./p1.jpg", 'rb') as f:
        data = base64.b64encode(f.read())
    #image = "取決于image_type參數,傳入BASE64字符串或URL字符串或FACE_TOKEN字符串"
    #image = urllib.parse.urlencode(data)
    image = str(data,'utf-8')
    imageType = "BASE64"

    """ 調用人臉檢測 """
    result = client.detect(image, imageType);
    print(result)
    
def face_detect(filepath1,filepath2):  #人臉對比
    image1 = fileopen(filepath1)
    image2 = fileopen(filepath2)
    result = client.match([
    {
        'image': image1,
        'image_type': 'BASE64',
    },
    {
        'image': image2,
        'image_type': 'BASE64',
    }])
    print(result)              #打印出所有的信息
    
def face_add(filepath,groupid,userid):  #人臉庫增加 地址 組 用戶
    image = fileopen(filepath)
    imageType="BASE64"
    result=client.addUser(image,imageType,groupid,userid)
    if result['error_code']==0:
        print("增加人臉成功")
    else:
        print("增加人臉失敗")
        
def face_search(filepath,groupIdList):  #人臉庫搜索  groupIdList="你的用戶組名稱"
    image = fileopen(filepath)
    imageType="BASE64"
    data=client.search(image,imageType,groupIdList)
    result = data.get('result')
    print(result)            #打印出所有信息
    if result == None:
        return None
    else:#分數大于70
        if result['user_list'][0]['score'] >70 :
            print(result['user_list'][0]['user_id'])
            return result['user_list'][0]['user_id']
        else :
            return None

            
          

更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久久久久国产精品视频 | 刑事侦缉档案1 | 一级片观看 | 成人免费精品 | 日韩欧美中文字幕视频 | 色蜜桃网 | 亚洲国产精品网站 | 成人亚洲一区 | 精品一区二区三区三区 | 日韩精品一区二区三区视频播放 | 亚洲精品二三区 | 极品狂兵电视剧免费观看 | 一级黄色片毛片 | 狠狠久 | 99爱在线精品视频免费观看9 | 欧美日韩一区二区在线 | 黄色电影在线免费观看 | 亚洲精品视频免费看 | 成人久久一区 | 国产精品视频第一区二区三区 | wwwav在线| 久久亚洲精品中文字幕二区 | 国产二区在线播放 | 久久国产精品一区 | 极品尤物一区二区三区 | 天天干天天干天天干天天干天天干 | 日韩精品免费视频 | 国产精品亚洲成在人线 | 色网站免费视频 | 亚洲高清成人欧美动作片 | 女同久久另类99精品国产 | 99在线精品视频在线观看 | 色婷婷综合在线 | 色噜噜亚洲男人的天堂 | 亚洲午夜精品视频 | 91精品国产91久久久 | 久久人精品 | 日本高清在线中文字幕网 | 青娱在线 | 精品欧美一区二区精品久久久 | 久草在线免费福利视频 |