【问题标题】:Required argument 'rejectLevels' (pos 2) not found OpenCV Raspberry Pi找不到所需的参数“rejectLevels”(位置 2)OpenCV Raspberry Pi
【发布时间】:2015-05-03 10:05:30
【问题描述】:

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

标志 = 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)))

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

【问题讨论】:

    标签: python-2.7 opencv raspberry-pi


    【解决方案1】:

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

    【讨论】:

    • 很高兴看到它有所帮助。尝试使 minSize 值可变并忘记将它们转换为整数时,我遇到了同样令人困惑的错误消息;-)
    • 我的示例来自一个显然包含该错字的教程。
    猜你喜欢
    • 2017-05-26
    • 2019-05-10
    • 2020-08-13
    • 2019-06-20
    • 2021-04-09
    • 2018-03-10
    • 2013-12-07
    • 2019-07-10
    • 1970-01-01
    相关资源
    最近更新 更多