gpt4 book ai didi

python - 人脸识别opencv有类型元组错误

转载 作者:行者123 更新时间:2023-12-02 17:31:13 25 4
gpt4 key购买 nike

cv2.putText(img,str(id),(x,y + h),font,255);
TypeError:使用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()

最佳答案

错误显示该行来自何处

cv2.putText(img,str(id),(x,y+h),font,255)

第四个参数应该是字体对象,但是您已经在此处将其初始化为元组:
font= cv2.FONT_HERSHEY_COMPLEX_SMALL,5,1,0,4

我相信字体应该只是
font = cv2.FONT_HERSHEY_COMPLEX_SMALL

查看docs here

顺便说一句,您在python中不需要分号。

关于python - 人脸识别opencv有类型元组错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55511896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com