OpenCV错误:Python中未知错误代码-49 [英] OpenCV Error: Unknown error code -49 in Python

查看:507
本文介绍了OpenCV错误:Python中未知错误代码-49的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cv2在python-3.6中学习人脸检测.

I am trying to learn face detection in python-3.6 using cv2.

我遵循书中给出的src.

I follow the src given in a book.

我已经通过 pip

.xml和.jpg文件都与python代码位于同一路径.

.xml and .jpg files are all in the same path with python code.

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)

我遇到一个无法在任何地方找到的错误.

I am getting an error to which I am not able to find anywhere.

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

请帮助我.谢谢.

推荐答案

在这个琐碎的小问题上,我花了很多时间.真正的问题是Open CV仅适用于Haarcascade XML文件,该文件可在Opencv.org网站上获得,而不能从github

I have spent lot of manhours on this small trivial issue. The real issue is that Open CV will work only with the Haarcascade XML files, which are available on the Opencv.org website and not from the github

这篇关于OpenCV错误:Python中未知错误代码-49的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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