OpenCV Error: Unknown error code -49 in Python

2024/12/9 20:50:15

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

I follow the src given in a book.

I have already installed opencv-python(3.2.0) by pip

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

from numpy import *
import cv2face_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

Kindly help me in this. Thank you.

Answer

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

https://en.xdnf.cn/q/72704.html

Related Q&A

Python Exchange ActiveSync Library

Is anyone familiar with an Exchange ActiveSync library or open source client for python? Ive done preliminary searching with little to no success. Ive seen some examples for C#, but I figured Id ask a…

Tastypie: How can I fill the resource without database?

I want to grab some information from Foursquare , add some fields and return it via django-tastypie. UPDATE:def obj_get_list(self, request=None, **kwargs):near = if near in request.GET and request.GET…

Is there a way to protect built-ins in python?

My question arises from this question, in which a user got himself confused by unknowingly rebinding the built-in global set. Is there a straightforward way to get python to warn you when you attempt t…

Generate thumbnail for arbitrary audio file

I want to represent an audio file in an image with a maximum size of 180180 pixels.I want to generate this image so that it somehow gives a representation of the audio file, think of it like SoundCloud…

Extract specific text lines?

I have a large several hudred thousand lines text file. I have to extract 30,000 specific lines that are all in the text file in random spots. This is the program I have to extract one line at a time:b…

Listing users for certain DB with PyMongo

What Im trying to acheiveIm trying to fetch users for a certain database.What I did so farI was able to find function to list the databases or create users but none for listing the users, I thought ab…

Using python selenium for Microsoft edge

I am trying to use pythons selenium for Microsoft edge but I keep getting this error:WebDriverException: Message: unknown error: cannot find Microsoft Edge binaryI downloaded the latest version of the …

get all unicode variations of a latin character

E.g., for the character "a", I want to get a string (list of chars) like "aāăą" (not sure if that example list is complete...) (basically all unicode chars with names "Latin…

How do I install Django on Ubuntu 11.10?

Im using The Definitive guide to installing Django on ubuntu and ironically need something more definitive because I cant make it work.(I have followed the steps before this on the link above) Here is …

Sympy second order ode

I have a homogeneous solution to a simple second-order ODE, which when I try to solve for initial values using Sympy, returns the same solution. It should substitute for y(0) and y(0) and yield a solut…