我正在尝试使用 cv2 在 python-3.6 中学习人脸检测。
我按照书上给出的src进行操作。
我已经安装了opencv-python(3.2.0) by pip
.xml 和 .jpg 文件都与 python 代码位于同一路径中。
from numpy import *
import cv2
face_cascade = cv2.CascadeClassifier("D:\\Python\\FaceDetec\\lbpcascade_frontalface.xml")
img = cv2.imread("z1.jpg")
gary = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.2, 3)
for(x, y, w, h) in faces:
img2 = cv2.rectangle(img, (x, y), (x+w, y+h), (255, 255, 255), 2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
cv2.imshow("img", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.imwrite("z1.head.jpg", img)
我收到一个我无法在任何地方找到的错误。
OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file D:\Build\OpenCV\opencv-3.2.0\modules\core\src\persistence.cpp, l
ine 4422
Traceback (most recent call last):
File "d:\Python\FaceDetec\Harr_cascade.py", line 6, in <module>
face_cascade = cv2.CascadeClassifier("D:\\Python\\FaceDetec\\lbpcascade_frontalface.xml")
cv2.error: D:\Build\OpenCV\opencv-3.2.0\modules\core\src\persistence.cpp:4422: error: (-49) Input file is empty in function cvOpenFileStorage
请在这方面帮助我。谢谢。