项目实现利用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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
2024年11月16日
2024年11月16日
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览
- 三国志8重制版哪个武将好 三国志8重制版武将排行一览
- 三国志8重制版武将图像怎么保存 三国志8重制版武将图像设置方法
- 何方.1990-我不是那种人【林杰唱片】【WAV+CUE】
- 张惠妹.1999-妹力新世纪2CD【丰华】【WAV+CUE】
- 邓丽欣.2006-FANTASY【金牌大风】【WAV+CUE】
- 饭制《黑神话》蜘蛛四妹手办
- 《燕云十六声》回应跑路:年内公测版本完成95%
- 网友发现国内版《双城之战》第二季有删减:亲亲环节没了!
- 邓丽君2024-《漫步人生路》头版限量编号MQA-UHQCD[WAV+CUE]
- SergeProkofievplaysProkofiev[Dutton][FLAC+CUE]
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]