我正在玩openCV,我得到了一个错误说(-215:Assert失败)!函数'cv::CascadeClassifier::detectMultiScale'中的empty()。我不知道为什么。
代码:
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
#face classifier
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
#eye classifier
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')
nose_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_mcs_nose.xml')
while True:
ret, frame = cap.read()
#detect face
#convert image to grey
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#use grey image in face classifier
faces = face_cascade.detectMultiScale(gray, 1.3, 10)
#defining faces for the classifier
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 5)
#find eyes on face
roi_gray = gray[y:y+w, x:x+w]
roi_color = frame[y:y+h, x:x+w]
#detect eyes with eye classifier
eyes = eye_cascade.detectMultiScale(roi_gray, 1.3, 10)
for (ex, ey, ew, eh) in eyes:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 5)
nose = nose_cascade.detectMultiScale(roi_gray, 1.3, 10)
for (ex, ey, ew, eh) in nose:
cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 0, 255), 5)
cv2.imshow('frame', frame)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
字符串
我已经检查了代码的拼写错误和语法,但它仍然没有工作
2条答案
按热度按时间isr3a4wc1#
我让你的代码与眼睛和脸一起工作,但我没有鼻子xml来修复鼻子,所以下面是我能为你修复的所有内容:
字符串
ql3eal8s2#
这个有滑块,所以你可以调整结果
字符串