Ask Your Question

OpenCV Error: Unknown error code -49 (persistence.cpp error=

asked 2018-05-14 05:16:44 -0500

hobibey gravatar image


i tried use opencv and detect face, but this pyhton code given to this cascade error: i was downloaded cascades files from this link.

where i was wrong? thanks.

import cv2 as cv
face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml')
eye_cascade = cv.CascadeClassifier('haarcascade_eye.xml')
img = cv.imread('X.JPG')
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

OpenCV Error: Unknown error code -49 (Input file is empty) in cvOpenFileStorage, file C:\projects\opencv-python\opencv\modules\core\src\persistence.cpp, line 4484 cv2.error: C:\projects\opencv-python\opencv\modules\core\src\persistence.cpp:4484: error: (-49) Input file is empty in function cvOpenFileStorage

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:/opencv/", line 3, in <module> face_cascade = cv.CascadeClassifier('haarcascade_frontalface_default.xml') SystemError: <class 'cv2.cascadeclassifier'=""> returned a result with an error set

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2018-05-14 05:42:44 -0500

berak gravatar image

updated 2018-05-14 06:04:51 -0500

have a look at those cascade files (e.g. with a text editor). do they really contain valid xml ?

(download errors do happen, there might just be a html errormsg in there, not valid xml)

also, when using weird python ide's like pycharm, do yourself a favour, and use an absolute file path for anything, that needs to be loaded from disk.

edit flag offensive delete link more

answered 2020-04-18 00:44:21 -0500

pcvolokh gravatar image

You downloaded the html version of the xml file, not the actual raw version of the file, which is found here: []

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-05-14 05:16:44 -0500

Seen: 1,753 times

Last updated: May 14 '18