Python 错误:(-49:未知错误代码-49)haarcascade

Python 错误:(-49:未知错误代码-49)haarcascade,python,Python,我的代码: import cv2 img_path = 'Bruce Lee.jpg' img = cv2.imread(img_path) detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') boxes = detector.detectMultiScale(img) for box in boxes: x1,y1,width,height=box x2,y

我的代码:

import cv2

img_path = 'Bruce Lee.jpg'

img = cv2.imread(img_path)

detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

boxes = detector.detectMultiScale(img)

for box in boxes:
    
    x1,y1,width,height=box
    
    x2,y2=x1+width,y1+height

    cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imshow('Pic',img)

cv2.waitKey(0)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\opencv\modules\core\src\persistence.cpp:717: error: (-49:Unknown error code -49) Input file is invalid in function 'cv::FileStorage::Impl::open'


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

Traceback (most recent call last):
  File "E:\HOC TAP\Phyton\PYTHON\Lesson 10 CUSTOM HAARCASCADE - Data Collection And Training Process Made Easy\pythonProject\CUSTOM HAARCASCADE\Draft.py", line 5, in <module>
    detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
结果是:

import cv2

img_path = 'Bruce Lee.jpg'

img = cv2.imread(img_path)

detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

boxes = detector.detectMultiScale(img)

for box in boxes:
    
    x1,y1,width,height=box
    
    x2,y2=x1+width,y1+height

    cv2.rectangle(img,(x1,y1),(x2,y2),(0,255,0),2)
cv2.imshow('Pic',img)

cv2.waitKey(0)
cv2.error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\opencv\modules\core\src\persistence.cpp:717: error: (-49:Unknown error code -49) Input file is invalid in function 'cv::FileStorage::Impl::open'


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

Traceback (most recent call last):
  File "E:\HOC TAP\Phyton\PYTHON\Lesson 10 CUSTOM HAARCASCADE - Data Collection And Training Process Made Easy\pythonProject\CUSTOM HAARCASCADE\Draft.py", line 5, in <module>
    detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
SystemError: <class 'cv2.CascadeClassifier'> returned a result with an error set
cv2.error:OpenCV(4.5.1)C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-wvn_it83\OpenCV\modules\core\src\persistence.cpp:717:error:(-49:未知错误代码-49)输入文件在函数“cv::FileStorage::Impl::open”中无效
上述异常是以下异常的直接原因:
回溯(最近一次呼叫最后一次):
文件“E:\HOC TAP\Phyton\PYTHON\Lesson 10 CUSTOM HAARCASCADE-数据收集和培训过程变得简单\PYTHON项目\CUSTOM HAARCASCADE\Draft.py”,第5行,在
detector=cv2.CascadeClassifier('haarcascade\u frontalface\u default.xml'))
SystemError:返回了一个带有错误集的结果