欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 高清一区二区在线观看 | 毛片免费在线观看 | 久久久久亚洲精品中文字幕 | 欧美日本国产 | 天天摸日日操 | 亚洲伦理一区 | 色偷偷噜噜噜亚洲男人 | 一区二区三区精品视频 | 九色网址 | 狠狠操网站 | 日韩精品 电影一区 亚洲 | 杀破狼在线观看 | 日韩欧美在线中文字幕 | 91精品国产91久久久久久最新 | 一区二区三区视频免费 | 欧美极品在线观看 | 欧美精品 在线观看 | 国产免费av大片 | 特黄做愛又硬又大A片视频 小视频在线看 | 亚洲综合色丁香婷婷六月图片 | 日韩成人在线电影 | 日本一区免费在线观看 | 极品xxxx欧美一区二区 | 欧美在线观看视频 | 欧美日韩国产精品自在自线 | 久久精品免费视频观看 | 一级黄色毛片a | 国产久| 站长推荐国产午夜免费视频 | 成人国产一区二区三区 | 国产高清在线精品免费 | 午夜小视频免费 | 亚洲一区久欠无码A片 | 怦然心动50免费完整版 | 91久久国产精品 | 污污的网站免费在线观看 | 亚洲欧美自拍另类图片色 | 欧美成人午夜免费完成 | 九九久久久| 欧美人在线 | 午夜久久久久久久久久一区二区 |