usersblock / Facial-Attribute-Classification-by-ML-Algorithms

Other
1 stars 2 forks source link

Haar Cascade code no detecting some images #33

Open jvivar2383 opened 2 years ago

jvivar2383 commented 2 years ago

I'm using this code to detect the faces in an image and get the rectangle points: f_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_default.xml')#cv2.data.haarcascades +

e_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')

rectangles = [] masked = [] phonyimg =[] i = 0 for image in images:

gray = cv2.cvtColor(frame, cv.COLOR_BGR2GRAY)

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#gray = cv2.equalizeHist(gray)

faces = face_cascade.detectMultiScale(gray)

faces = f_cascade.detectMultiScale(gray, minNeighbors = 1, minSize =[9,9]) #, 1.3, 5, scalefactor=#1.2
if type(faces)!= tuple:
    i+=1
    testImg = image
    param = faces[0]
    print(param)
    testImg[0:param[0]] = 0
    testImg[param[2]:200] = 0
    testImg[:, 0:param[1]]  = 0
    testImg[:, param[3]:200] = 0
    masked.append(testImg)
    break
else:
    phonyimg.append(image)

However, some of the faces in the images are not detected. I tried modifying the parameters like minNeighbors etc. Any ideas? This is what the image looks like after the mask:

Screen Shot 2022-05-13 at 10 27 50 PM

?

yxiang001 commented 2 years ago

I have similar issue before. try to work it later when I get a chance