【问题标题】:"[ WARN:0 ] `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback" Error when running the code“[WARN:0] `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback” 运行代码时出错
【发布时间】:2021-05-07 05:57:23
【问题描述】:

我正在尝试运行此 OpenCV 代码以使用我的摄像机检测人脸。每当我运行我的代码时,它都会给我这个错误。我的摄像机上的灯闪烁,但随后关闭,控制台框中出现此错误以及这个 cv2.error: OpenCV(4.5.1) error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'

这是代码


# Load the cascade
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# To capture video from webcam.
cap = cv2.VideoCapture(0)
# To use a video file as input
# cap = cv2.VideoCapture('filename.mp4')

while True:
    # Read the frame
    _, img = cap.read()

    # Convert to grayscale
    #THIS IS THE ERROR AREA
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

    # Detect the faces
    faces = face_cascade.detectMultiScale(gray, 1.1, 4)

    # Draw the rectangle around each face
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)

    # Display
    cv2.imshow('img', img)

    # Stop if escape key is pressed
    k = cv2.waitKey(30) & 0xff
    if k == 27:
        break

# Release the VideoCapture object
cap.release()

【问题讨论】:

    标签: python python-3.x opencv opencv-python


    【解决方案1】:

    由于相对路径,您的脚本似乎无法正确找到 haarcascade_frontalface_default.xml 文件。尝试给出绝对路径并检查。

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 2019-05-22
      • 2020-05-17
      • 2019-10-27
      • 2018-09-17
      • 2014-04-26
      • 1970-01-01
      • 2017-11-13
      • 1970-01-01
      相关资源
      最近更新 更多