Suraj
Suraj

Reputation: 2477

Unable to detect faces of cartoon images

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 !

Upvotes: 3

Views: 1734

Answers (3)

Suraj
Suraj

Reputation: 2477

So as cartoon images are very different to that of humans, we need to train a model from scratch for them separately. I implemented a YOLO model, and trained it, and the results were really good !

labelImg can be used to prepare the dataset.

I referred this blog : Darknet YOLO using OpenCV to create my own YOLO detector in which the github repository Darknet YOLO is cloned and modified.

EDIT : My project on github

Upvotes: 2

Leonard
Leonard

Reputation: 43

Actually I agree with all above comments. There is no ready sollution for catroon objects and I've tried a lot of models and nothing works (ORB, Haar Cascade, SuperPixel and etc.) and no AutoML solution (from Google or Amazon) also does not work. There is only one way to do the face recognition in cartoons objects. This solution is firstly to make your own labeled data set of images and then try to train some models to detect objects. So I've chosen this way, and results are great, 91% accuracy.

Upvotes: 1

terminatorash2199
terminatorash2199

Reputation: 305

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

Upvotes: 4

Related Questions