一次将重复的数据写入excel文件?

时间:2018-12-15 22:11:48

标签: python excel opencv face-recognition

我正在尝试在Windows Pycharm中编写“基于面部识别的考勤系统”的代码。 我想做的是“当识别器识别出用户时,它只会将用户数据和识别日期记录到yoklamaexcel中一次”

我无法解决此问题,请帮助我。这是我的识别器并保存部件代码

import cv2,os
import numpy as np
from PIL import Image
import pickle
import sqlite3
from openpyxl import *
import datetime


recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('trainer.yml')
cascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
yoklamaexcel = load_workbook(filename="yoklama.xlsx")
path = 'veriseti'
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_COMPLEX
conn=sqlite3.connect("yetki.db")
cursor = conn.cursor()
while True:
    ret, im =cam.read()
    gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
    faces=faceCascade.detectMultiScale(gray, scaleFactor=1.2,minNeighbors=5, minSize=(100, 100), flags=cv2.CASCADE_SCALE_IMAGE)
    for(x,y,w,h) in faces:
      nbr_predicted, conf = recognizer.predict(gray[y:y+h,x:x+w])
      cv2.rectangle(im,(x-50,y-50),(x+w+50,y+h+50),(225,0,0),2)
      cursor.execute("SELECT * FROM personel WHERE id=?",(nbr_predicted,))
      data=cursor.fetchall()
      cv2.putText(im,str(data[0])+"--"+str(conf),(100,70),font,0.5(255,255,255),2,cv2.LINE_AA)
      cv2.imshow('im',im)
      cv2.waitKey(10)

0 个答案:

没有答案