how do I save variable values in a mysql database

0

I'm trying to create a facial recognition system using Opencv to record user access to the school lab but the problem is that I'm not able to save the access time information for each user and neither the image of it at the time that he entered. I'm using this code

import MySQLdb
import cv2
from datetime import datetime
import numpy as np

classificador = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
reconhecedor = cv2.face.LBPHFaceRecognizer_create()
reconhecedor.read("classificadorLBPH.yml")
largura, altura = 220, 220
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
camera = cv2.VideoCapture(0)
banco_de_dados = MySQLdb.connect(user='root', host='127.0.0.1', 
database='acesso_usuarios')
cursor = banco_de_dados.cursor()
hora = datetime.now()
while (True):
    conectado, imagem = camera.read()
    imagemCinza = cv2.cvtColor(imagem, cv2.COLOR_BGR2GRAY)
    facesDetectadas = classificador.detectMultiScale(imagemCinza,
                                                 scaleFactor=1.5,
                                                 minSize=(150, 150))


    for (x, y, l, a) in facesDetectadas:
        imagemFace = cv2.resize(imagemCinza[y:y + a, x:x + l], (largura, altura))
        id, confianca = reconhecedor.predict(imagemFace)
        regiao = imagem[y:y + a, x:x + l]
        cv2.putText(imagem,
                str(hora.day) + '/' + str(hora.month) + '/' + str(hora.year) + '-' + str(hora.hour) + ':' + str(
                    hora.minute) + ':' + str(hora.second), (0, 20), font, 1.5, (0, 255, 0))

        if np.average(imagemCinza) > 110:

            chegada = str(hora.hour) + '-' + str(hora.minute) +'-'+ str(hora.second) +' '+ str(hora.day) +'/'+ str(hora.month) +'/'+ str(hora.year)
            nome = ''
            if id == -1:
                nome = 'desconhecido'
            elif id == 1:
                nome = 'William'
            elif id == 2:
                nome = 'Isaac'
            elif id == 3:
                nome = 'ivamberg'
            elif id == 4:
                nome = 'afonso'

            cursor.execute('SELECT * FROM acesso_usuarios.'+nome)
            arg = 'INSERT INTO' +nome+ '(hora_chegada) VALUES %s'
            val = chegada
            cursor.execute(arg, val)
            if np.average(imagemCinza) < 110 or (id != 1):
                hora_de_saida = datetime.now()

                saida = str(hora_de_saida.hour) + str(hora_de_saida.minute) + str(hora_de_saida.second) + str(
            hora_de_saida.day) + str(hora_de_saida.month) + str(hora_de_saida.year)
                arg = 'INSERT INTO' +nome+ '(hora_saida) VALUES %s'
                val = saida
                cursor.execute(arg, val)

            cv2.putText(imagem, nome, (x, y + (a + 30)), font, 2, (0, 0, 255)) 
            cv2.putText(imagem, str(confianca), (x, y + (a + 50)), font, 1, (0, 0, 255))  

        cv2.imshow("Face", imagem)
        if cv2.waitKey(1) == ord('q'):
            break

camera.release()
cv2.destroyAllWindows()

But whenever I run from this error

  

Traceback (most recent call last):     File "C: \ Users \ Gear \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ MySQLdb \ cursors.py", line 238, in execute       query = query% args   TypeError: not all arguments converted during string formatting   During handling of the above exception, another exception occurred:   Traceback (most recent call last):     File "C: \ Users \ Gear \ AppData \ Local \ Programs \ Python \ Python37-32 \ test.py", line 49, in       cursor.execute (arg, val)     File "C: \ Users \ Gear \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ MySQLdb \ cursors.py", line 240, in execute       self.errorhandler (self, ProgrammingError, str (m))     File "C: \ Users \ Gear \ AppData \ Local \ Programs \ Python \ Python37-32 \ lib \ site-packages \ MySQLdb \ connections.py", line 52, in defaulterrorhandler       raise errorclass (errorvalue)   _mysql_exceptions.ProgrammingError: not all arguments converted during string formatting

    
asked by anonymous 26.07.2018 / 14:01

0 answers