Giter Site home page Giter Site logo

lbpcascade_animeface's Introduction

lbpcascade_animeface

The face detector for anime/manga using OpenCV.

Original release since 2011 at OpenCVによるアニメ顔検出ならlbpcascade_animeface.xml (in Japanese)

Usage

Download and place the cascade file into your project directory.

wget https://raw.githubusercontent.com/nagadomi/lbpcascade_animeface/master/lbpcascade_animeface.xml

Python Example

import cv2
import sys
import os.path

def detect(filename, cascade_file = "../lbpcascade_animeface.xml"):
    if not os.path.isfile(cascade_file):
        raise RuntimeError("%s: not found" % cascade_file)

    cascade = cv2.CascadeClassifier(cascade_file)
    image = cv2.imread(filename, cv2.IMREAD_COLOR)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)
    
    faces = cascade.detectMultiScale(gray,
                                     # detector options
                                     scaleFactor = 1.1,
                                     minNeighbors = 5,
                                     minSize = (24, 24))
    for (x, y, w, h) in faces:
        cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)

    cv2.imshow("AnimeFaceDetect", image)
    cv2.waitKey(0)
    cv2.imwrite("out.png", image)

if len(sys.argv) != 2:
    sys.stderr.write("usage: detect.py <filename>\n")
    sys.exit(-1)
    
detect(sys.argv[1])

Run

python detect.py imas.jpg

result

Note

I am providing similar project at https://github.com/nagadomi/animeface-2009. animeface-2009 is my original work that was made before libcascade_animeface. The detection accuracy is higher than this project. However, installation of that is a bit complicated. Also I am providing a face cropping script using animeface-2009.

lbpcascade_animeface's People

Contributors

nagadomi avatar youkaichao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lbpcascade_animeface's Issues

Re-thinking anime(animation/manga/game/draw) character face detection task

hello nagadomi, one of pioneer of related research
and researchers that studies on this field

I have some thinking about this detection task

Detection

in reality research on detection has been extended to, target detection, face recognition, OCR and other detection tasks, here I'm not going to expand detail or reference some example(maybe later will add)

There are also many related animation tasks that make use of this tool
For example, character recognition systems, as well as generation tasks, character design tools, character animation, etc.

from 2016 to 2021

But they result not so good , especially the generation based
the research is almost stagnant, and there is not much research on it, these result can't be commercial

that is because definition of detection (anime face) is no longer suitable for these tasks
in reality research tasks also have no counterpart in anime
and it is not possible to clean, split and extract useful data to make a dataset with detection and classification tools

Downstream tasks

I believe that there is now a need to redefine and design different datasets for the following tasks

  • Tool cleaning to facilitate the creation of semantic, annotated datasets
  • (face, full body) character design (diversity [data], quality, creative [decoupling])
  • Anime character recognition systems(include famous, not very popular, unpopular and manga, original)
  • Automatic animation, AI warp, motion -> talkinghead
  • anime stylization on real faces
  • (this*doesnotexist, large-scale generative pre-train) anime on generative model

As far as I know, every detector is now working for one purpose only, to detect anime faces
The definition is very vague, and the

there are various types sources (animation/manga/game/draw)
anime is mainly express on characters, those media type also has varies Form of expression

As a data processing tool

The value of the detector in the anime deeplearning very high, not just for detect faces, but as a data processing tool, and I think the detector needs multiple requirements

  • wild hard collect (in-game CG and more)
  • positive and negative samples to provide
  • angle of view, deformation, degree of perspective
  • what components and what proportion of them and how it composition
  • the degree of degradation of the image (colour, shape, light and shadow)
  • provide some attributes for downstream (for the generation task or recognition system etc.)

appendix - What is Anime

I studied anime data for a long time (Data mining) but now I found it was easy to define

anime-look(based creation ecology) character with multi-media (animaiton, manga, game, draw, novel)

so .. many vtubers also are anime

character works , derivative work , fanmade/fanart(mostly is draw ,meme etc.) , these are peripheral anime ecology
and can expression on real world,eg : cosplay , doujinshi circle , sale goods , event etc..

and those type of character with multi-media define can generalized to Fictional characters based entertainment

Thank for you reading

Provide demonstration script for producing images cropped to the face

I experimented with using facedetect's cropping script on anime images to try to crop faces into separate files (the goal here being to experiment with modeling faces using WGAN to see if it improves on IllustrationGAN), but it didn't work at all. I tried using this, and it works much better but doesn't provide a simple interface/program for cropping images down to the face. I modified the example file to do this, and it seems to work OK:

import cv2
import sys
import os.path

def detect(cascade_file, filename, outputname):
    if not os.path.isfile(cascade_file):
        raise RuntimeError("%s: not found" % cascade_file)

    cascade = cv2.CascadeClassifier(cascade_file)
    image = cv2.imread(filename)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)

    faces = cascade.detectMultiScale(gray,
                                     # detector options
                                     scaleFactor = 1.1,
                                     minNeighbors = 5,
                                     minSize = (50, 50))
    i=0
    for (x, y, w, h) in faces:
        cropped = image[y: y + h, x: x + w]
        cv2.imwrite(outputname+str(i)+".png", cropped)
        i=i+1

if len(sys.argv) != 4:
    sys.stderr.write("usage: detect.py <animeface.xml file>  <input> <output prefix>\n")
    sys.exit(-1)

detect(sys.argv[1], sys.argv[2], sys.argv[3])

Saved as cropy.py, this can then be run on a single file like

python ~/src/lbpcascade_animeface/examples/crop.py ~/src/lbpcascade_animeface/lbpcascade_animeface.xml foo.jpg cropped

or run in parallel on many files using parallel like this:

cropFaces() {
    name=$(basename "$@")
    python ~/src/lbpcascade_animeface/examples/crop.py ~/src/lbpcascade_animeface/lbpcascade_animeface.xml "$@" faces/danbooru/"$name"
    }
export -f cropFaces
find ./danbooru/ -type f -name "*.jpg" | parallel cropFaces

It would be great if you could provide something like this Python crop program in the repo.

lbpcascade_animeface.xml not found?

Hi, sorry if I sound really stupid, but I'm getting this error when I run "python detect.py test.png"

Full response here
Traceback (most recent call last): File "detect.py", line 30, in <module> detect(sys.argv[1]) File "detect.py", line 7, in detect raise RuntimeError("%s: not found" % cascade_file) RuntimeError: ../lbpcascade_animeface.xml: not found

What do I do? I have the xml downloaded in the right place

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.