这应该算是自己写出来的第一个写出来的一个小小小的程序。也算是机器学习上的一个开头把,甚至可以算是自己程序员道路的开头,小小纪念一下。
当然其中参考了其他大佬写的代码。不过自己也搞懂了。争取以后自己可以成为这样的大佬吧。哈哈
import base64
import cv2
cap=cv2.VideoCapture(0)
while(1):
ret,frame=cap.read()
cv2.imshow(“capture”,frame)
if cv2.waitKey(1)& 0xFF == ord (‘q’) :
cv2.imwrite(“你自己的文件名”,frame)
break
cap.release()
cv2.destroyAllWindows()
from aip import AipFace
#百度云上获取的账号,可百度搜索百度人工智能
APP_ID=“14751721”
API_KEY=“G2h8NbO94OPhyq267cWy1jrG”
SECRET_KEY=“z2Xp2L1zDXGEB3SGubdOdFzpRBhPifWX”
client = AipFace(APP_ID, API_KEY, SECRET_KEY)
filepath=“同上的文件名”
#将图片文件转化为base64格式
with open(filepath,“rb”) as f:
base64_data = base64.b64encode(f.read())
image = str(base64_data, ‘utf-8’)
imageType = “BASE64”
options = {}
options[“face_field”] = “age,beauty”
options[“max_face_num”] = 1
options[“face_type”] = “LIVE”
result = client.detect(image, imageType,options);
print(result)