我正在使用Python 3和OpenCV 3.我试图使用EigenFace识别器,它使用相同大小的图像作为训练和测试数据集。我从网络摄像头读取图像,然后将图像大小调整为200 x 200,但显示错误。Python OpenCV:无法调整图像
这是我的代码:
faceDetect=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
cam=cv2.VideoCapture(0);
rec=cv2.face.EigenFaceRecognizer_create()
#rec=cv2.face.LBPHFaceRecognizer_create()
rec.read("recognizer/EigenData.xml")
id=0
fontFace = cv2.FONT_HERSHEY_SIMPLEX
fontScale = 1
fontColor = (0, 0, 255)
while(True):
ret,img=cam.read();
resize_img = img.resize((200,200) , img)
gray=cv2.cvtColor(resize_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,255,0) , 2)
id, conf=rec.predict(gray[y:y+h, x:x+w]) #EigenFace Predict
cv2.putText(img,str(id),(x,y+h), fontFace, fontScale, fontColor,thickness=2)
cv2.imshow("Face", img);
if(cv2.waitKey(1)==ord('q')):
break;
cam.release()
cv2.destroyAllWindows()
我得到的错误是:
resize_img = img.resize((200,200) , img)
TypeError: 'tuple' object cannot be interpreted as an integer
Downvoter - 护理解释你downvote? – rayryeng
到opencv 3.0 beta的链接是不好的。我建议使用链接到opencv 3.3 docs – Miki
@Miki oops。谢谢。我会纠正的。 – rayryeng