【发布时间】:2017-10-20 07:40:40
【问题描述】:
我正在使用 Python 3 和 OpenCV 3。我正在尝试使用 EigenFace Recognizer,它对训练和测试数据集使用相同大小的图像。我从网络摄像头读取图像并将图像大小调整为 200 x 200,但显示错误。
这是我的代码:
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
【问题讨论】:
标签: python image opencv image-processing image-resizing