简体   繁体   English

OpenCV 4.7.0:系统错误:<class 'cv2.cascadeclassifier'> 返回带有异常集的结果</class>

[英]OpenCV 4.7.0: SystemError: <class 'cv2.CascadeClassifier'> returned a result with an exception set

This is the beginning of the code.这是代码的开头。 I am following a face recognition project tutorial using OpenCV and Python. This is meant to take a picture of a face using haar cascade face detection and then storing in a dataset file I have.我正在关注使用 OpenCV 和 Python 的面部识别项目教程。这意味着使用 haar 级联面部检测拍摄面部照片,然后存储在我拥有的数据集文件中。

import cv2
import os

cam = cv2.VideoCapture(0)
cam.set(3, 640) # set video width
cam.set(4, 480) # set video height


face_detector = cv2.CascadeClassifier('/Users/*********/workspace/Facial Recognition Project/haarcascade_frontalface_default.xml')

# For each person, enter one numeric face id
face_id = input('\n enter user id end press <return> ==>  ')

print("\n [INFO] Initializing face capture. Look the camera and wait ...")
# Initialize individual sampling face count
count = 0

while(True):

    ret, img = cam.read()
    img = cv2.flip(img, -1) # flip video image vertically
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_detector.detectMultiScale(gray, 1.3, 5)

    for (x,y,w,h) in faces:

        cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 2)     
        count += 1

        # Save the captured image into the datasets folder
        cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y+h,x:x+w])

        cv2.imshow('image', img)

    k = cv2.waitKey(100) & 0xff # Press 'ESC' for exiting video
    if k == 27:
        break
    elif count >= 30: # Take 30 face sample and stop video
         break

# Do a bit of cleanup
print("\n [INFO] Exiting Program and cleanup stuff")
cam.release()
cv2.destroyAllWindows()```

This was the error:这是错误:

cv2.error: OpenCV(4.7.0) /Users/opencv-cn/GHA-OCV-1/_work/opencv-python/opencv-python/opencv/modules/core/src/persistence.cpp:681: error: (-215:Assertion failed) buf in function 'open' cv2.error: OpenCV(4.7.0) /Users/opencv-cn/GHA-OCV-1/_work/opencv-python/opencv-python/opencv/modules/core/src/persistence.cpp:681: 错误: ( -215:断言失败) buf in function 'open'

The above exception was the direct cause of the following exception:上述异常是以下异常的直接原因:

Traceback (most recent call last): File "/Users/sashuponnaganti/workspace/Facial Recognition Project/01_face_dataset.py", line 9, in face_detector = cv2.CascadeClassifier('/Users/*********/workspace/Facial Recognition Project/haarcascade_frontalface_default.xml') SystemError: <class 'cv2.CascadeClassifier'> returned a result with an exception set回溯(最近调用最后):文件“/Users/sashuponnaganti/workspace/Facial Recognition Project/01_face_dataset.py”,第 9 行,在 face_detector = cv2.CascadeClassifier('/Users/*********/ workspace/Facial Recognition Project/haarcascade_frontalface_default.xml') SystemError: <class 'cv2.CascadeClassifier'> 返回了一个带有异常集的结果

I believe that I am using the cv2.CascadeClassifier function correctly and I know the filepath for the xml file is correct so I am confused why I am getting an error.我相信我正在正确使用 cv2.CascadeClassifier function 并且我知道 xml 文件的文件路径是正确的所以我很困惑为什么我会收到错误。

I guess you don't need to enforce cv2 to find xml at some particular path... So, try to use我想你不需要强制 cv2 在某些特定路径上找到 xml ...所以,尝试使用

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

insted.代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用cv2.CascadeClassifier解决openCV错误? - How to fix the openCV error with cv2.CascadeClassifier? Python 3.7.3 SystemError:错误返回,未设置异常 - Python 3.7.3 SystemError: error return without exception set SystemError:使用请求和调试器时,无异常设置的错误返回 - SystemError: error return without exception set, when using requests and debugger 错误:如何修复“系统错误:<built-in function imshow> 在Opencv python中返回NULL而不设置错误” - Error : How to fix "SystemError: <built-in function imshow> returned NULL without setting an error" in Opencv python 错误:(-215:Assertion failed):empty() in function 'cv::CascadeClassifier::detectMultiScale' - Error:(-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale' 使用open-cv“模块&#39;cv2&#39;没有&#39;CascadeClassifier&#39;成员”时如何修复python中的以下错误? - How to fixed the following error in python while using open-cv "Module 'cv2' has no 'CascadeClassifier' member"? 如何修复“系统错误:<built-in function 'name'> 在 Python C 扩展中返回 NULL 而不设置错误” - How to fix "SystemError: <built-in function 'name'> returned NULL without setting an error" in Python C Extension 为什么不能在OpenCV(Python)中使用`cv2.cv.BoxPoints`? - Why can't use `cv2.cv.BoxPoints` in OpenCV (Python)? 设置类变量的值,该值由类方法返回 - Set class variable value, the value returned by a class method OpenCV 4 TypeError:参数“标签”的预期 cv::UMat - OpenCV 4 TypeError: Expected cv::UMat for argument 'labels'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM