0

Please Help me. I'm running a face recognition detector python program that will display the data from sqllite studio database...

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

recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read('trainer/trainer.yml')
cascadePath = "Classifiers/face.xml"
faceCascade = cv2.CascadeClassifier(cascadePath);
path = 'dataSet'

def getProfile(Id):
         conn=sqlite3.connect("facebase.db")
         cmd="SELECT * FROM people WHERE ID="+str(Id)
         cursor=conn.execute(cmd)
         profile=None
         for row in cursor:
            profile=row
         conn.close()
         return profile 


cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX #Creates a font
while True:
    ret, im =cam.read()
    gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
    faces=faceCascade.detectMultiScale(gray, 1.2,5)
    for(x,y,w,h) in faces:
        cv2.rectangle(im,(x,y),(x+w,y+h),(225,0,0),2)
        Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
        profile=getProfile(Id)
        if(profile!=None):
        #cv2.putText(im,str(profile[1]),(x,y+h+20),font, 2, 255, 3)
        cv2.putText(im, str(profile[1]), (x,y-40), font, 2, (255,255,255),3)
        #cv2.putText(im,str(profile[2]),(x,y+h+40),font, 2, 255, 3)
        cv2.putText(im, str(profile[2]), (x,y-80), font, 2, (255,255,255),3)
    else:
        Id="Unknown"
    cv2.rectangle(im, (x-22,y-90), (x+w+22, y-22), (0,255,0), -1)
    cv2.putText(im, str(Id), (x,y-40), font, 2, (255,255,255), 3)
cv2.imshow('im',im) 
if cv2.waitKey(10) & 0xFF==ord('q'):
    break
cam.release()
cv2.destroyAllWindows()

that was the program

the error was

   Traceback (most recent call last):
   File "C:\Users\Titus John\Desktop\New folder (6)\Face-Recognition-
   master\detector.py", line 38, in <module>
   cv2.putText(im, str(profile[2]), (x,y-80), font, 2, (255,255,255), 3)
   IndexError: tuple index out of range

And i'm using python 3.4 and opencv 3.4 Can anyone help me??? im new in python.

Thank you so much....

1 Answers1

0

Indexing is zero-based in Python. That means, counting starts from 0 not 1.

Try changing lines 36 and 38 to:

cv2.putText(im, str(profile[0]), (x,y-40), font, 2, (255,255,255),3)
cv2.putText(im, str(profile[1]), (x,y-80), font, 2, (255,255,255),3)
Abhishek Kumar
  • 461
  • 2
  • 11