face++与python实现人脸识别签到(考勤)功能


Posted in Python onAugust 28, 2019

项目实现利用face++开发一个课堂签到的软件,实现面向摄像头即可完成记录学号、姓名和时间的签到工作。

项目架构

face++与python实现人脸识别签到(考勤)功能

项目使用场景

face++与python实现人脸识别签到(考勤)功能

代码:

流程代码,主文件

#!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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
下载糗事百科的内容_python版
Dec 07 Python
python对html代码进行escape编码的方法
May 04 Python
python+tkinter编写电脑桌面放大镜程序实例代码
Jan 16 Python
深入理解Python爬虫代理池服务
Feb 28 Python
遗传算法python版
Mar 19 Python
python3 enum模块的应用实例详解
Aug 12 Python
Python OrderedDict的使用案例解析
Oct 25 Python
Python高级特性之闭包与装饰器实例详解
Nov 19 Python
python自动提取文本中的时间(包含中文日期)
Aug 31 Python
基于python实现图片转字符画代码实例
Sep 04 Python
使用python爬取抖音app视频的实例代码
Dec 01 Python
Python Pycharm虚拟下百度飞浆PaddleX安装报错问题及处理方法(亲测100%有效)
May 24 Python
OpenCV+face++实现实时人脸识别解锁功能
Aug 28 #Python
Python的垃圾回收机制详解
Aug 28 #Python
Python通过cv2读取多个USB摄像头
Aug 28 #Python
python3.5 cv2 获取视频特定帧生成jpg图片
Aug 28 #Python
Django--权限Permissions的例子
Aug 28 #Python
Python中函数的返回值示例浅析
Aug 28 #Python
django认证系统实现自定义权限管理的方法
Aug 28 #Python
You might like
提取HTML标签
2006/10/09 PHP
PHP简单读取PDF页数的实现方法
2016/07/21 PHP
实例讲解php实现多线程
2019/01/27 PHP
PHP PDOStatement::closeCursor讲解
2019/01/30 PHP
jquery.alert 弹出式复选框实现代码
2009/06/15 Javascript
将字符串转换成gb2312或者utf-8编码的参数(js版)
2013/04/10 Javascript
JavaScript设置IFrame高度自适应(兼容各主流浏览器)
2013/06/05 Javascript
jQuery中after的两种用法实例
2013/07/03 Javascript
鼠标选择动态改变网页背景颜色的JS代码
2013/12/10 Javascript
从QQ网站中提取的纯JS省市区三级联动菜单
2013/12/25 Javascript
JavaScript将数据转换成整数的方法
2014/01/04 Javascript
适用于javascript开发者的Processing.js入门教程
2016/02/24 Javascript
js实现文字截断功能
2016/09/14 Javascript
jQuery实现遍历复选框的方法示例
2017/03/06 Javascript
使用node.js搭建服务器
2017/05/20 Javascript
Node.js使用Express.Router的方法
2017/11/14 Javascript
Vuex提升学习篇
2018/01/11 Javascript
关于express与koa的使用对比详解
2018/01/25 Javascript
JavaScript字符和ASCII实现互相转换
2020/06/03 Javascript
Javascript var变量删除原理及实现
2020/08/26 Javascript
js实现弹窗猜数字游戏
2020/11/26 Javascript
Python 保存矩阵为Excel的实现方法
2019/01/28 Python
python虚拟环境的安装和配置(virtualenv,virtualenvwrapper)
2019/08/09 Python
HTML5的结构和语义(3):语义性的块级元素
2008/10/17 HTML / CSS
HTML5表单验证特性(知识点小结)
2020/03/10 HTML / CSS
女士鞋子、包包和服装在线,第一款10美元:ShoeDazzle
2019/07/26 全球购物
国际政治个人自荐信范文
2013/11/26 职场文书
公交公司毕业生求职信
2014/02/15 职场文书
《雾凇》教学反思
2014/02/17 职场文书
党支部创先争优活动总结
2014/08/28 职场文书
社区灵活就业证明
2014/11/03 职场文书
生日祝酒词大全
2015/08/10 职场文书
党风廉政教育心得体会2016
2016/01/22 职场文书
vue首次渲染全过程
2021/04/21 Vue.js
Python爬虫基础讲解之请求
2021/05/13 Python
Java tomcat手动配置servlet详解
2021/11/27 Java/Android