Syntax error in if and elif systems

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 syntax error. What's wrong?

    
asked by anonymous 01.04.2018 / 22:25

1 answer

2

The indentation in the code you posted is wrong because all "cv2." should be starting in the same column as the "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"
    
01.04.2018 / 22:33