获取else语句右括号的无效语法错误,是由于缩进错误还是编码错误,我该如何解决。
font= cv2.FONT_HERSHEY_COMPLEX_SMALL
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(conf<50):
user=getUser(id)
if(user!=None):
cv2.putText(img,str(user[1]),(x,y+h),font,2,(0,255,0),2)
else:
cv2.putText(img,"Unknown"),(x,y+h),font,2,(0,255,0),2)#<-get invalid syntax for close bracket
cv2.imshow("Face",img);
if(cv2.waitKey(1)==ord('q')):
break;
cam.release()
cv2.destroy.AllWindows()
答案 0 :(得分:3)
您有一个额外的支架,请删除该额外的支架。
cv2.putText(img,"Unknown",(x,y+h),font,2,(0,255,0),2)