所需参数 'rejectLevels'(位置 2)未找到 OpenCV Raspberry Pi

Required argument 'rejectLevels' (pos 2) not found OpenCV Raspberry Pi

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

标志 = cv2.cv.CV_HAAR_SCALE_IMAGE

TypeError: 必需参数 'rejectLevels' (pos 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)))

我不确定错误到底告诉我什么,一些建议会很好!

您的参数有错别字,请将 minNeighbours 更改为 minNeighbors