Reputation: 465
cv2.putText(img,str(id),(x,y+h),font,255); TypeError: an integer is required (got type tuple) using python 3.7
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
font= cv2.FONT_HERSHEY_COMPLEX_SMALL,5,1,0,4
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)
id,conf=rec.predict(gray[y:y+h,x:x+w])
if(id==1):
id="x"
cv2.putText(img,str(id),(x,y+h),font,255);
cv2.imshow("Face",img);
if(cv2.waitKey(1)==ord('q')):
break;
cam.release()
cv2.destroy.AllWindows()
Upvotes: 0
Views: 279
Reputation: 8287
The error shows the line where it's coming from
cv2.putText(img,str(id),(x,y+h),font,255)
The fourth parameter is expected to be a font object, but you've initialised it to a tuple here:
font= cv2.FONT_HERSHEY_COMPLEX_SMALL,5,1,0,4
I believe font should be only
font = cv2.FONT_HERSHEY_COMPLEX_SMALL
Look at the docs here.
Btw, you don't need semicolons in python.
Upvotes: 1