Ask Your Question
0

Input file is invalid

asked Oct 27 '0

flaviu2 gravatar image

updated Oct 27 '0

I am a newbie in Python. I have a OpenCV related issue. I have this simple code:

import sys
from matplotlib import pyplot
import cv2

im = cv2.imread("E:\\Face.jpg")

def plot_img(img):
    rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    pyplot.imshow(rgb)

if im.any():
    plot_img(im)

if im.any():
    classifier = cv2.CascadeClassifier()
    classifier.load("E:\\haarcascade_eye.xml")
    classifier.detectMultiScale(im)

but on line classifier.load("E:\haarcascade_eye.xml") I got the following error:

Exception has occurred: error
OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-d54til6p\opencv\modules\core\src\persistence.cpp:717: error: (-49:Unknown error code -49) Input file is invalid in function 'cv::FileStorage::Impl::open'
  File "D:\Tempx\PythonApplication1\PythonApplication1.py", line 18, in <module>
    classifier.load("E:\\haarcascade_eye.xml")

I have downloaded haarcascade_eye.xmlfrom here: https://github.com/opencv/opencv/tree...

What could be the problem ?

Preview: (hide)

1 answer

Sort by » oldest newest most voted
1

answered Oct 27 '0

berak gravatar image

updated Oct 27 '0

try to open it with a text editor, it might be corrupted, maybe you got some html from github

here's the correct link

Preview: (hide)

Comments

Thank you a lot, that was the problem. I wonder from where can I take the right xml files because I took the wrong xml from the official OpenCV repository.

flaviu2 gravatar imageflaviu2 (Oct 27 '0)edit

if you click any of the xml files in a webbrowser, use the raw button on that page

if you use curl or wget, replace blob with raw in the url

berak gravatar imageberak (Oct 27 '0)edit

Question Tools

1 follower

Stats

Asked: Oct 27 '0

Seen: 6,361 times

Last updated: Oct 27 '20