[英]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.