face++与python实现人脸识别签到(考勤)功能
作者:MudFire 时间:2021-10-18 09:06:06
项目实现利用face++开发一个课堂签到的软件,实现面向摄像头即可完成记录学号、姓名和时间的签到工作。
项目架构
项目使用场景
代码:
流程代码,主文件
#!usr/bin/
# -*- coding: utf-8 -*-
import requests
from json import JSONDecoder
import csv
import cv2
import time
import tkinter as tk
search_url = "https://api-cn.faceplusplus.com/facepp/v3/search"
getdetail_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail"
key = "***************"
secret = "*********************"
filename = time.time()
filepath = "photo/" + str(filename) + ".jpg"
cap = cv2.VideoCapture(0)
while(1):
# get a frame
ret, frame = cap.read()
# show a frame
cv2.imshow("capture", frame)
if cv2.waitKey(1) & 0xFF == ord('1'):
cv2.imwrite(filepath, frame)
break
cap.release()
cv2.destroyAllWindows()
print("waiting...")
csvfile = open('face_token.csv','r')
freader = csv.reader(csvfile)
dic = dict(freader)
csvfile.close()
faceID_dict = {v:k for k,v in dic.items()}
print("...")
data = {"api_key": key, "api_secret": secret, "outer_id":'zbpm'}
files = {"image_file": open(filepath, "rb")}
response = requests.post(search_url, data=data, files=files)
req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con)
pre_face_token = req_dict["results"][0]["face_token"]
pre_confidence = req_dict["results"][0]["confidence"]
pre_thresholds = req_dict["thresholds"]["1e-5"]
print("...")
data = {"api_key": key, "api_secret": secret,"outer_id":'zbpm'}
response = requests.post(getdetail_url, data=data)
req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con)
faces_token = req_dict["face_tokens"]
print("...")
if pre_face_token in faces_token and pre_confidence >= pre_thresholds:
labaltext = faceID_dict[pre_face_token] + "\n\n\n" +str(time.asctime(time.localtime()))
window = tk.Tk()
window.title = ('FaceID')
window.geometry = ('200x200')
var = tk.StringVar()
l = tk.Label(window,bg = 'yellow',text = labaltext,font=("黑体",20 ,"bold"),width = 30,height = 20)
l.pack()
l.config(text=labaltext+var.get())
#tk.messagebox.askokcancel('faceId', faceID_dict[pre_face_token] + "\n" +str(time.asctime(time.localtime())))
print(faceID_dict[pre_face_token])
else:
tkinter.messagebox.askokcancel('提示', '未找到')
print("未找到")
建立云脸数据集的模块:
#!usr/bin/
# -*- coding: utf-8 -*-
import requests
import time
from json import JSONDecoder
import csv
http_url ='https://api-cn.faceplusplus.com/facepp/v3/faceset/addface'
key = "z_qkMMqK1efq8ikgAPOEn89A7And-lAa"
secret = "***********************"
faceset_token = '******************************'
face_tokens_str = ''
csvfile = open('face_token.csv','r')
freader = csv.reader(csvfile)
facedata = []
i = 0
for item in freader:
i = i + 1
face_tokens_str = face_tokens_str + item[1] + ','
if i%5 == 0:
face_tokens_str = face_tokens_str[:-1]
facedata.append (face_tokens_str)
face_tokens_str = ''
face_tokens_str = face_tokens_str[:-1]
facedata.append (face_tokens_str)
csvfile.close()
for item in facedata:
print(item)
data = {"api_key":key,"api_secret":secret,"faceset_token":faceset_token,"face_tokens":item}
response = requests.post(http_url, data=data)
print(response)
print(response.text)
初始建立云联数据集的模块:
#!/usr/bin/env/ python
# _*_ coding:utf-8 _*_
import requests
from json import JSONDecoder
http_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/create"
get_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/getfacesets"
getdetails_url = "https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail"
key = "**********************"
secret = "*********************"
data = {"api_key":key,"api_secret":secret,"display_name":'SEUers',"outer_id":'zbpm'}
repn = requests.post(http_url,data = data)
print(repn)
print(repn.text)
data = {"api_key":key,"api_secret":secret}
repn = requests.post(get_url,data = data)
print(repn)
print(repn.text)
data = {"api_key":key,"api_secret":secret,"outer_id":'zbpm'}
repn = requests.post(getdetails_url,data = data)
print(repn)
print(repn.text)
生成存储facetoken:
这里从171860学号开始生成我的facetoken
#!usr/bin/
# -*- coding: utf-8 -*-
import requests
from json import JSONDecoder
import csv
id = 171860
http_url ='https://api-cn.faceplusplus.com/facepp/v3/detect'
key = "*******************"
secret = "*******************"
faceID_List = []
face_token_List = []
for i in range (0,10):
faceID = str(id + i)
file = "picture/"+ faceID + ".jpg"
data = {"api_key":key,"api_secret":secret,"return_landmark":1,}
file = {"image_file":open(file,'rb')}
response = requests.post(http_url,data = data,files = file)
req_con = response.content.decode('utf-8')
req_dict = JSONDecoder().decode(req_con)
face_token = req_dict["faces"][0]["face_token"]
faceID_List.append(faceID)
face_token_List.append(face_token)
print(faceID_List)
print(face_token_List)
csvfile = open('face_token.csv','a',newline = '')
fwriter = csv.writer(csvfile)
for i in range(len(faceID_List)):
fwriter.writerow([faceID_List[i],face_token_List[i]])
csvfile.close()
来源:https://blog.csdn.net/zhangbingxiazai/article/details/88243517
标签:face++,人脸识别,签到
0
投稿
猜你喜欢
利用python实现AR教程
2021-07-09 16:39:04
Python3 log10()函数简单用法
2021-06-27 16:47:16
Python如何通过手肘法实现k_means聚类详解
2021-03-13 16:35:34
利用python将 Matplotlib 可视化插入到 Excel表格中
2023-09-26 09:03:25
10 个Python中Pip的使用技巧分享
2023-08-02 17:52:45
SQL Server默认1433端口修改方法
2010-07-22 22:35:00
python使用socket进行简单网络连接的方法
2021-05-16 22:53:03
使用python的turtle绘画滑稽脸实例
2022-04-18 02:24:49
Python正确调用 jar 包加密得到加密值的操作方法
2021-02-26 12:12:19
配置php网页显示各种语法错误
2023-11-14 07:23:04
Django实现auth模块下的登录注册与注销功能
2022-03-06 17:49:15
vue-quill-editor插入图片路径太长问题解决方法
2024-05-29 22:46:29
python中尾递归用法实例详解
2023-10-09 06:46:15
python实现图片素描效果
2022-06-10 21:00:40
Mysql 忘记root密码和修改root密码的解决方法(小结)
2024-01-20 09:01:22
mysql与mssql的md5加密语句
2024-01-20 07:33:22
python 定时任务去检测服务器端口是否通的实例
2021-05-18 15:09:13
解决tensorflow由于未初始化变量而导致的错误问题
2023-06-05 17:44:05
网站程序员如何应对web标准
2007-05-11 16:52:00
Oracle 当前用户下所有表的记录总数
2009-07-14 21:34:00