接下来该怎么办?

时间:2019-01-17 12:14:27

标签: python opencv beagleboneblack

import cv2
import numpy as np

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')

web = cv2.VideoCapture(0)

while True:

    ret, img = web.read()

    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    faces = face_cascade.detectMultiScale(gray, 1.3, 5)

    for (x, y, w, h) in faces:
        cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2)  
        roi_gray = gray[y:y+h, x:x+w] 
        roi_color = img[y:y+h, x:x+w] 

    eyes = eye_cascade.detectMultiScale(roi_gray)

     for (ex,ey,ew,eh) in eyes: 
            cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2) 

        cv2.imshow('img', img)

        k = cv2.waitKey(30) & 0xFF 
        if k == 27:


    web.release()
    cv2.destroyAllWindows()


 root@beaglebone:/var/lib/cloud9# python test5.py
  File "test5.py", line 25
    for (ex,ey,ew,eh) in eyes: 
    ^
IndentationError: unexpected indent

1 个答案:

答案 0 :(得分:0)

该行开头的空格/制表符的数量表示结构,例如哪些代码作为if语句和for循环的一部分执行。因此,您需要对代码的格式更加系统化……

专为编辑代码而设计的文本编辑器在此方面大有帮助。

另外,if k == 27:似乎是未终止的,即如果用户按下转义键,您想做什么?