I am trying to implement a simple face detection of cartoons code using opencv and python. Though the code I have used works for faces of humans I am not able to detect cartoon faces using this. Is there any way I can make it detect cartoon faces too.
import cv2
import matplotlib.pyplot as plt
imagePath = 'frame179.jpg'
cascPath = '/Users/tonystark/opencv/data/haarcascades/haarcascade_frontalface_default.xml'
faceCascade = cv2.CascadeClassifier(cascPath)
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=40,
minSize=(24, 24),
flags=cv2.CASCADE_SCALE_IMAGE
)
The images are human for which I am able to get the location of the face, whereas for cartoon, I am not able to get the location of faces.
Thanks a lot in advance !
Haar cascades are used to detect only one particular thing and in your case, it has been trained to detect only human faces. You will have to create another haar cascade to detect cartoon faces.
You can refer to this video for creating one -https://www.youtube.com/watch?v=jG3bu0tjFbk