日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

人脸识别代码_Python人脸识别源代码可自动识别出年龄、性别等

發(fā)布時(shí)間:2024/9/30 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 人脸识别代码_Python人脸识别源代码可自动识别出年龄、性别等 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

利用百度AI進(jìn)行人臉識(shí)別,可自動(dòng)識(shí)別出年齡、性別等信息,準(zhǔn)確率非常高。

運(yùn)行程序前請(qǐng)安裝需要的模塊。

import base64from aip import AipFaceimport cv2# 配置百度aip參數(shù)APP_ID = '19484855'API_KEY = 'V2mDOleCsk3yEE6P5MgVwSjI'SECRET_KEY = 'RbRMAuPmz8QpDweikrbpfGQjXUm7HiCD'a_face = AipFace(APP_ID, API_KEY, SECRET_KEY)image_type = 'BASE64'options = {'face_field': 'age,gender,beauty', "max_face_num": 10}max_face_num = 10def get_file_content(file_path): """獲取文件內(nèi)容""" with open(file_path, 'rb') as fr: content = base64.b64encode(fr.read()) return content.decode('utf8')def face_score(file_path): """臉部識(shí)別分?jǐn)?shù)""" result = a_face.detect(get_file_content(file_path), image_type, options) return result# 圖片地址,圖片與程序同一目錄下file_path = "timg.jpg"result = face_score(file_path)# #從文件讀取圖像并轉(zhuǎn)為灰度圖像img = cv2.imread(file_path)# 圖片放文字# 設(shè)置文件的位置、字體、顏色等參數(shù)font = cv2.FONT_HERSHEY_DUPLEX# font = ImageFont.truetype("simhei.ttf", 20, encoding="utf-8")color = (0, 0, 255)for item in result['result']['face_list']: x = int(item['location']['left']) y = int(item['location']['top']) w = item['location']['width'] h = item['location']['height'] age = item['age'] beauty = item['beauty'] gender = item['gender']['type'] cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 3) cv2.putText(img, 'age:%s' % age, (x, y + h + 10), font, 1, color, 1) cv2.putText(img, 'beauty:%s' % beauty, (x, y + h + 30), font, 1, color, 1) cv2.putText(img, 'gender:%s' % gender, (x, y + h + 50), font, 1, color, 1)cv2.imshow('Image', img)# 按任意鍵退出key = cv2.waitKey()if key == 27: # 銷毀所有窗口 cv2.destroyAllWindows()

總結(jié)

以上是生活随笔為你收集整理的人脸识别代码_Python人脸识别源代码可自动识别出年龄、性别等的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。