Ask Your Question
0

Input file is invalid

asked 2020-10-27 06:32:22 -0600

flaviu2 gravatar image

updated 2020-10-27 06:33:17 -0600

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 ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-10-27 07:22:24 -0600

berak gravatar image

updated 2020-10-27 07:24:54 -0600

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

here's the correct link

edit flag offensive delete link more

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 ( 2020-10-27 11:16:09 -0600 )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 ( 2020-10-27 11:36:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-10-27 06:32:22 -0600

Seen: 6,117 times

Last updated: Oct 27 '20