【发布时间】: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