When I only detect the face the camera zoom on the face and follows it. But when I want to detect & zoom/follow the mouth it doesn’t. It just randomly detects all type of stuff expect the mouth.
So for the mouth detection to work I need to detect the face first before I can detect the mouth succesfully.
So this works(only face):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face = face_cascade.detectMultiScale(gray, scaleFactor=SCALE_FACTOR, minNeighbors=MIN_NEIGHBORS, minSize=MINSIZE, )
boxes = np.array(face)
But this doesn’t(first face then mouth):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face = face_cascade.detectMultiScale(gray, 1.3, 15)
for (x, y, w, h) in face:
roi_gray = gray[y:y + w, x:x + w]
mouth = mouth_cascade.detectMultiScale(roi_gray, scaleFactor=SCALE_FACTOR, minNeighbors=MIN_NEIGHBORS, minSize=MINSIZE,)
boxes = np.array(mouth)
What is the problem? How do I make this work?? How will I be able to detect the mouth and zoom/follow it? Any help or tips are welcome!
Files:
Example(Instead of focusing on the face it should focus on the mouth)
berak
January 11, 2022, 12:45pm
2
for starters, there’s a simple typo:
you want
roi_gray = gray[y:y + h, x:x + w]
(wont change much, since most face cascades are trained on quadratic rects)
also, you should not use the same MINSIZE
to find eyes and faces, think of it.
in the end, the cascades approach is quite brittle, we got better tools nowadays,
e.g try the dnn based face detection here
(which also comes with builtin landmarks to detect the mouth !)
import argparse
import numpy as np
import cv2 as cv
def str2bool(v):
if v.lower() in ['on', 'yes', 'true', 'y', 't']:
return True
elif v.lower() in ['off', 'no', 'false', 'n', 'f']:
return False
else:
raise NotImplementedError
parser = argparse.ArgumentParser()
parser.add_argument('--image1', '-i1', type=str, help='Path to the input image1. Omit for detecting on default camera.')
parser.add_argument('--image2', '-i2', type=str, help='Path to the input image2. When image1 and image2 parameters given then the program try to find a face on both images and runs face recognition algorithm.')
parser.add_argument('--video', '-v', type=str, help='Path to the input video.')
parser.add_argument('--scale', '-sc', type=float, default=1.0, help='Scale factor used to resize input video frames.')
parser.add_argument('--face_detection_model', '-fd', type=str, default='face_detection_yunet_2021dec.onnx', help='Path to the face detection model. Download the model at https://github.com/opencv/opencv_zoo/tree/master/models/face_detection_yunet')
parser.add_argument('--face_recognition_model', '-fr', type=str, default='face_recognition_sface_2021dec.onnx', help='Path to the face recognition model. Download the model at https://github.com/opencv/opencv_zoo/tree/master/models/face_recognition_sface')
This file has been truncated. show original
Thank you I’ll fix the type and have a look!
berak
January 11, 2022, 1:07pm
5
dont forget, that the eyes in the images might be smaller than the minsize for the faces, and thus be rejected
Thanks! You’ve been a help