错误:(-215) !empty() 函数中的 detectMultiScale [英] error: (-215) !empty() in function detectMultiScale

查看:116
本文介绍了错误:(-215) !empty() 函数中的 detectMultiScale的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 python 2.7 中学习 cv2,但是当我运行我的代码时,在它的特定部分:

I'm trying to learn cv2 in python 2.7, but when I run my code, in the specific part of it:

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


img = cv2.imread('2015-05-27-191152.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)

它返回这个:

File "face_detection.py", line 11, in <module>
    faces = face_cascade.detectMultiScale(gray, 1.3, 5)
cv2.error: /home/arthurckl/Desktop/opencv-3.0.0-rc1/modules/objdetect/src/cascadedetect.cpp:1595: error: (-215) !empty() in function detectMultiScale

我试图在这里搜索答案,但我能找到的最好的方法是我必须以错误的方式加载 face_cascade...有什么帮助吗?

I tried to search the answer here but the best i could find is that I must be loading the face_cascade the wrong way... Any help?

推荐答案

我遇到了同样的问题.

我不需要下载任何其他东西来解决这个问题.CV2 拥有我需要的一切.

I didn't need to download anything else to solve this. CV2 had everything I needed.

我没有尝试找出 .xml 文件的位置并对值进行硬编码,而是使用了 cv2 提供的属性.

Instead of trying to figure out where the .xml files are and hard coding the values, I used a property given by cv2.

来自 OP

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

成为

face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')

这篇关于错误:(-215) !empty() 函数中的 detectMultiScale的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆