我似乎无法在任何地方找到解决方案,我有一个运行面部识别脚本的脚本,但由于某种原因它告诉我这个确切的错误:
文件“box.py”,第98行,中 label,confidence = model.predict(crop)
TypeError:'int'对象不可迭代
我的代码对问题非常重要:
import cv2
#Creates model to be the facerecognizer
model = cv2.face.createEigenFaceRecognizer()
#Defines the model as a training image taken previously
model.load(config.TRAINING_FILE)
#Initializes the camera as camera
camera = config.get_camera()
#Takes a picture using the camera
image = camera.read()
#Converts to grayscale
image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
#Results if it found a face
result = face.detect_single(image)
#Tells you to keep taking a picture until you have a face recognized
if result is None:
print 'Could not see face! Retake picture!'
continue
#gets dimensions of the face
x,y,w,h = result
#resizes the face
crop = face.resize(face.crop(image, x, y, w, h))
#Tests face against the previously taken model
label, confidence = model.predict(crop) **<--- This is where the error is**
#Im not 100% as to what this does, I got this part on the internet
result = cv2.face.MinDistancePredictCollector()
model.predict(crop)
label = result.getLabel()
confidence = result.getDist()
这基本上就是它(Theres显然在内部和之间设置了更多的代码,但它不重要或与问题相关,至少我不认为,我使用Python 2.7与opencv 3.1.0在raspbian raspberry pi 3如果你需要那些信息
答案 0 :(得分:1)
你得到的错误告诉你model.predict(crop)
只返回一件事,你告诉Python期望它返回两件事。
但是,除非你省略了一些重要的东西,否则你会在下一个代码块中覆盖变量label
和confidence
,所以你可以表面上只删除那行代码。
如果无法删除该行,请通过将其中一个变量设置为零来进行修补:label, confidence = model.predict(crop), 0