Syntax error in if and Elif systems

Asked

Viewed 137 times

0

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 = "Tiago"
    cv2.cv.PutText(cv2.cv.fromarray(img),str(id), (x,y+h+30),font, 255)
    cv2.cv.PutText(cv2.cv.fromarray(img),str(genderTiago), (x,y+h+60),font, 255)
    cv2.cv.PutText(cv2.cv.fromarray(img),str(occupationTiago),(x,y+h+90),font,255)
    cv2.imshow("Face",img)
    elif(id ==2):
        id = "Obama"
if (cv2.waitKey(1) == ord('q')):
    break;

I’m doing a face recognition program and I’m having a problem with the last Elif. Python says it’s a syntax error. What’s wrong?

1 answer

2


The indentation in the code you posted is wrong because all "cv2." should be starting in the same column as "id".

if (id == 1):
    id = "Tiago"
    cv2.cv.PutText(cv2.cv.fromarray(img),str(id), (x,y+h+30),font, 255)
    # ...
elif (id == 2):
    id = "Obama"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.