我用python和opencv构建人脸识别代码。这条线给出了错误;当我更换;用>或者它工作的任何其他运算符但是变得未知它显示这样的错误.... NameError:名称'lt'未定义。
这是我在detector.py中的完整代码
import cv2
import numpy as np
faceDetect= cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam = cv2.VideoCapture(0);
rec= cv2.face.LBPHFaceRecognizer_create()
rec.read("recognizer\\trainingData.yml")
id=0
fontFace = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
fontColor = (255, 255, 255)
#font = cv2.InitFont(cv2.CV_FONT_HERSHEY_SIMPLEX, 1, 1, 0, 1, 1)
while True:
ret, img =cam.read()
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces=faceDetect.detectMultiScale(gray, 1.3,5)
for(x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),2)
#print(rec.predict(gray[y:y+h,x:x+w]))
id, conf = rec.predict(gray[y:y+h,x:x+w])
if(conf< >= 50):
if(id==1):
id="Osama"
elif(id==2):
id="Psycho"
else:
id = conf
cv2.putText(img,str(id), (x,y+h), fontFace, fontScale, fontColor)
cv2.imshow('Face',img)
if cv2.waitKey(1) ==ord('q'):
break
cam.release()
cv2.destroyAllWindows()
答案 0 :(得分:2)