简体   繁体   English

Assertion failed error in cv::CascadeClassifier::detectMultiScale in openCV

[英]Assertion failed error in cv::CascadeClassifier::detectMultiScale in openCV

I'm running on my python code using openCV我正在使用 openCV 在我的 python 代码上运行

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

face = cv2.CascadeClassifier('haarcascade_frontalface_alt.xml')

while 1:
    ret, frame = cap.read()         ##Read image frame
    frame = cv2.flip(frame, +1)     ##Mirror image frame
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    detect_face = face.detectMultiScale(gray, 1.2, 1)
    for(x, y, z, h) in detect_face:
        cv2.rectangle(frame, (x, y), (x+z, y+h), (0, 255, 0), 2)
        ROI = gray[x:x+z, y:y+h]
        length = ROI.shape[0]
        breadth = ROI.shape[1]
        Area = length * breadth
        display = 'Area = ' + str(Area)
        if Area > 0:
            cv2.putText(frame, display, (5, 50), font, 2, (255, 255, 0), 2, cv2.LINE_AA)

    for(x, y, z, h) in detect_face:
        cv2.rectangle(frame, (x, y), (x+z, y+h), (0, 255, 0), 2)
        ROI = gray[x:x+z, y:y+h]
        length = ROI.shape[0]
        breadth = ROI.shape[1]
        Area = length * breadth
        Distance = 3 * (10 ** (-9)) * (Area ** 2) - 0.001 * Area + 108.6
        display = 'Distance = ' + str(Distance)
        if Area > 0:
            cv2.putText(frame, display, (5, 50), font, 2, (255, 255, 0), 2, cv2.LINE_AA)

it prompted that它提示

penCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-71670poj\opencv\modules\objdetect\src\cascadedetect.cpp:1689: error: (-215:Assertion failed):empty() in function 'cv::CascadeClassifier::detectMultiScale' penCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-71670poj\opencv\modules\objdetect\src\cascadedetect.cpp:1689: 错误: (-215:Assertion function 'cv::CascadeClassifier::detectMultiScale' 中的 failed:empty()

I don't understand why this continuously happened.我不明白为什么这种情况不断发生。 I followed all instruction given from this site http://art-of-electronics.blogspot.com/2020/06/how-far-you-are-from-your-camera-python.html and I still could not figure it out.我按照本网站http://art-of-electronics.blogspot.com/2020/06/how-far-you-are-from-your-camera-python.html给出的所有说明进行操作,但我仍然无法理解出去。

it says that image is empty, so probably you're not correctly loading the image or importing the frame from the camera.它说图像是空的,所以你可能没有正确加载图像或从相机导入框架。

Make sure your path to the cascade file is correct.确保您的级联文件路径正确。 It fixed that for me.它为我解决了这个问题。

  • check if the spellings specified is correct检查指定的拼写是否正确

  • if the cascade is inside a folder specify that too如果级联在文件夹内也指定

  • check for typos检查拼写错误

  • check the index of the camera provided检查所提供相机的索引

hope you get it fixed regards希望你得到它固定的问候

暂无
暂无

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

相关问题 错误:OpenCV(4.5.5) 错误:(-215:Assertion failed) !empty() in function &#39;cv::CascadeClassifier::detectMultiScale&#39; - error: OpenCV(4.5.5) error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale' function 'cv::CascadeClassifier::detectMultiScale' 中的 OpenCV-Python 错误(-215:断言失败):empty() - OpenCV-Python Error (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale' 错误:(-215:断言失败)!empty() 在函数“cv::CascadeClassifier::detectMultiScale”中 - error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale' cv2.CascadeClassifier.detectMultiScale() 以 -215 失败:断言失败 - cv2.CascadeClassifier.detectMultiScale() failing with -215:Assertion failed Python opencv 错误(-215:断言失败) 0 <= scaleIdx && scaleIdx < (int)scaleData->size() in CascadeClassifier.detectMultiScale - Python opencv error (-215:Assertion failed) 0 <= scaleIdx && scaleIdx < (int)scaleData->size() in CascadeClassifier.detectMultiScale &quot;!empty() 在函数 &#39;cv::CascadeClassifier::detectMultiScale&#39;&quot; - "!empty() in function 'cv::CascadeClassifier::detectMultiScale'" 人脸检测抛出错误:函数 cv::CascadeClassifier::detectMultiScale 中的 !empty() - Face detection throws error: !empty() in function cv::CascadeClassifier::detectMultiScale 为什么在 openCV::CascadeClassifier::detectMultiScale 中出现错误? - Why do I get a error in openCV ::CascadeClassifier::detectMultiScale? OpenCV错误:cv2.matchTemplate()中的断言失败 - OpenCV Error: Assertion failed in cv2.matchTemplate() &#39;cv2.CascadeClassifier&#39; 对象没有属性 &#39;detectMultiscale&#39; - 'cv2.CascadeClassifier' object has no attribute 'detectMultiscale'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM