O código esta assim
captura_video = cv2.VideoCapture(0)
classificador_face = cv2.CascadeClassifier('classificadores/haarcascade_frontalface_default.xml')
contador = 0
try:
while(True):
captura_ok, frame = captura_video.read()
if captura_ok:
frame = padronizar_imagem(frame)
frame_gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
faces = classificador_face.detectMultiScale(frame_gray, 1.3, 5)
if len(faces) > 0:
contador += 1
if contador <= 100:
for (x,y,w,h) in faces:
roi = frame_gray[y:y+h, x:x+w]
cv2.resize(roi, (200, 200), interpolation=cv2.INTER_LANCZOS4)
cv2.imwrite("imagens/anne/" + str(contador) + ".png", roi)
cv2.putText(frame, "Coletado " + str(contador) + " faces", (20,20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,0), 2)
else:
cv2.putText(frame, "ConcluIdo", (20,20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,0), 2)
exibir_video(frame)
except KeyboardInterrupt:
captura_video.release()
print("Interrompido")
porém aparece esse erro aqui
error Traceback (most recent call last) in 13 frame_gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY) 14 ---> 15 faces = classificador_face.detectMultiScale(frame_gray, 1.3, 5) 16 17 if len(faces) > 0:
error: OpenCV(4.0.1) C:\ci\opencv-suite_1573470242804\work\modules\objdetect\src\cascadedetect.cpp:1658: error: (-215:Assertion failed) !empty() in function 'cv::CascadeClassifier::detectMultiScale'