请帮帮我。我正在运行一个人脸识别探测器python程序,它将显示来自sqllite studio数据库的数据...
zoom
这是程序
错误是
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()
我正在使用python 3.4和opencv 3.4 谁能帮我???我是python的新手。
非常感谢....
答案 0 :(得分:0)
Python中的索引从零开始。这意味着,从0
而不是1
开始计算。
尝试将第36和38行更改为:
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)