必需参数'rejectLevels'(pos 2)未找到OpenCV Raspberry Pi

时间:2015-03-02 21:57:46

标签: python-2.7 opencv raspberry-pi

我有一个小脚本,我将图片从覆盆子pi上的picamera传递到OpenCV的流。一旦OpenCV有了图像,它应该使用haar级联方法寻找面部。如果我将面部检测分开,代码将运行正常,读入图像并按预期上传到远程服务器。当我进行面部检测时,我得到以下错误:

flags = cv2.cv.CV_HAAR_SCALE_IMAGE

TypeError:必需参数' rejectLevels' (位置2)未找到

这是代码:

current_time = time.time()
endtime = current_time + 30

stream  = io.BytesIO()

CAMERA_WIDTH = 640
CAMERA_HEIGHT = 480

cascPath = sys.argv[1]
faceCascade = cv2.CascadeClassifier(cascPath)

while current_time <= endtime:
    timeStamp = time.strftime('%d-%m-%Y-%H-%M-%S', time.localtime(current_time))

    with picamera.PiCamera() as cam:
        cam.rotation = 270
        cam.resolution = (CAMERA_WIDTH, CAMERA_HEIGHT)
        cam.capture(stream, format='bmp')

    data = np.fromstring(stream.getvalue(), dtype=np.uint8)
    img = cv2.imdecode(data, 1)
    stream.seek(0)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbours=5,
        minSize=(30,30),
        flags = cv2.cv.CV_HAAR_SCALE_IMAGE
    )

    print("Found {0} faces!".format(len(faces)))

我不确定错误告诉我的是什么,一些建议会很棒!

1 个答案:

答案 0 :(得分:7)

您的参数输入错误,将minNeighbours更改为minNeighbors