欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 九九热在线免费观看 | 好爽好大www视频在线播放 | 久久精品一区二区免费播放 | 激情综合欧美 | 亚洲午夜无码毛片AV久久 | 人人草视频在线 | 成人亚洲视频 | 成人国产精品一区 | 国产免费av大片 | 在线观看毛片视频 | 欧美日韩中文字幕一区二区高清 | 青青草91| 九九热国产在线 | 亚洲精品亚洲人成人网 | 一区在线播放 | 欧美一区二区三区gg高清影视 | 我和我的祖国电影在线观看免费版高清 | 日本高清在线精品一区二区三区 | 亚洲国产综合人成综合网站00 | 久久视频精品53在线观看 | 鲁一鲁综合 | 亚洲天堂网站 | 激情深爱 | 欧美一级网站 | 亚洲一区在线观看视频 | 一本到在线观看视频不卡 | 欧美色xx| 国产精品va一区二区三区 | 三级毛片免费 | 亚洲国产高清高潮精品美女 | 拍真实国产伦偷精品 | 久久女人被添全过程A片 | 96久久久久久| 色综合视频 | 免费在线成人 | 九九这里只有精品视频 | 先锋影音资源网站 | 亚洲精品视频免费观看 | 激情91| 91久久老司机福利精品网 | 91精品观看 |