Ask Your Question
0

i am unable to solve this plz help as soon as possible the cascade and the code is in the same file but i still get this error

asked 2019-01-06 10:26:00 -0500

updated 2019-02-12 12:34:23 -0500

LBerger gravatar image

hi everyone i am getting the same error what ever i do i even tried using the normal method(entering only the name) but still didnt work plz help as soon as possible, sorry for not arranged an an neat manner because i am using it first time and i dont know to use it properly

Traceback (most recent call last): File "/home/programmer/Desktop/project/face recg.py", line 11, in <module> faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5) cv2.error: OpenCV(3.4.5) /io/opencv/modules/objdetect/src/cascadedetect.cpp:1698: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

my code is given below for face recognizer

import numpy as np
import cv2

face_cascade = cv2.CascadeClassifier('/home/programmer/Desktop/project/cascades/data/cascades/data/haarcascade_fontalface_alt2.xml')

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
    for(x, y, w, h) in faces:
        print(x,y,w,h)
    cv2.imshow('frame',frame)
    if cv2.waitKey(20) & 0xFF == ord('q'):
        break
cap.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2019-01-06 10:38:28 -0500

LBerger gravatar image

updated 2019-01-06 10:46:57 -0500

try this :

face_cascade = cv2.CascadeClassifier('/home/programmer/Desktop/project/cascades/data/cascades/data/haarcascade_fontalface_alt2.xml')
if face_cascade.empty() :
        print("Le fichier ne peut etre lu. Verifier le chemin du fichier")
        print("File cannot be read. Check file path")
        print("Datei kann nicht gelesen werden. Dateipfad überprüfen")
        print("ບໍ່ສາມາດອ່ານໄຟລ໌ໄດ້. ກວດເບິ່ງເສັ້ນທາງໄຟລ໌")
        print("Dosja nuk mund të lexohet. Kontrollo rrugën e skedarit")
        print("Il file non può essere letto. Controlla il percorso del file")
        print("ファイルを読み込めません。 ファイルパスを確認する")
        print("文件无法读取。 检查文件路径")
        print("No se puede leer el archivo. Verifique la ruta del archivo")
        return
edit flag offensive delete link more

Comments

You have duplicated path? /cascades/data/cascades/data/ It could be like this /cascades/data/haarcascade_fontalface_alt2.xml. Even, if you not sure, why not put haarcascade_fontalface_alt2.xml in your currently folder and see what happen.

supra56 gravatar imagesupra56 ( 2019-01-07 08:03:58 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-06 10:11:06 -0500

Seen: 97 times

Last updated: Jan 06