GithubHelp home page GithubHelp logo

anime-face-detection's Introduction

Introduction

This repository is the summary of anime face detection methods based on Python.

Install

There are four methods for anime face detection: lbp, mlp, hog and ssd.

  • lbp: pip install opencv-python
  • mlp: pip install pillow opencv-python animeface
  • hog: pip install opencv-python dlib
  • ssd: pip install opencv-python numpy torch

Usage

For image detection:

python ./image_detect.py ./test/1.jpg lbp

For video detection:

python ./video_detect.py ./test/1.mp4 lbp
  • Param one: path of images/videos
  • Param two: method to be selected

Test Sample

在这里插入图片描述

Test Device

  • CPU:12 Intel(R) Xeon(R) CPU E5-2603 v4 @ 1.70GHz
  • GPU:8 NVIDIA GeForce GTX 1080 Ti

Anime Face Detection

Anime Face Detection Based on LBP

Repository

https://github.com/nagadomi/lbpcascade_animeface

Environment

Example

lbp_anime_face_detect.py

import cv2
import sys


def lbp_anime_face_detect(file_name):
    img = cv2.imread(file_name)
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img_gray = cv2.equalizeHist(img_gray) 
    face_cascade = cv2.CascadeClassifier('../model/lbp_anime_face_detect.xml')
    faces = face_cascade.detectMultiScale(img_gray)
    for x, y, w, h in faces:
        img = cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 255), 5)
    cv2.imwrite(f'../result/lbp_anime_face_detect_{file_name[-5]}.jpg', img) 


if __name__ == '__main__':
    lbp_anime_face_detect(sys.argv[1])

Result

Total Missing Error Time
13 1 1 1.20s

在这里插入图片描述

Anime Face Detection Based on MLP

Repository

https://github.com/nya3jp/python-animeface

Environment

  • System Requirements: Only for Linux system
  • Module: pip install pillow opencv-python animeface

Note: If pip install animeface reports an error, please download the compiled file animeface-1.1.0-cp37-cp37m-manylinux1_x86_64.whl.whl, and then use the following command to install: (It is mandatory that the Python version is 3.7)

pip install animeface-1.1.0-cp37-cp37m-manylinux1_x86_64.whl

Example

mlp_anime_face_detect.py

import cv2
import animeface
from PIL import Image
import sys


def mlp_anime_face_detect(file_name):
    img = cv2.imread(file_name)  
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)  
    img_gray = cv2.equalizeHist(img_gray)  
    faces = animeface.detect(Image.fromarray(img_gray)) 
    for each in faces:  
        temp = each.face.pos
        x = temp.x
        y = temp.y
        w = temp.width
        h = temp.height
        img = cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 255), 5)  
    cv2.imwrite(f'../result/mlp_anime_face_detect_{file_name[-5]}.jpg', img)  


if __name__ == '__main__':
    mlp_anime_face_detect(sys.argv[1])

Result

Total Missing Error Time
17 0 4 28.28s

在这里插入图片描述

Anime Face Detection Based on HOG

Repository

https://github.com/marron-akanishi/AFD

Environment


Note:The dlib library needs to be compiled with the C++ compiler after downloading, so you need to install Visual Studio and configure the C++ compilation environment. If C++ environment have been installed and configured, please ignore; If not, please see this Article.

Example

hog_anime_face_detect.py

import cv2
import dlib
import sys


def hog_anime_face_detect(file_name):
    img = cv2.imread(file_name) 
    img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 
    img_gray = cv2.equalizeHist(img_gray)  
    face_detector = dlib.simple_object_detector('../model/hog_anime_face_detect.svm') 
    faces = face_detector(img_gray)
    for face in faces: 
        left = face.left()
        top = face.top()
        right = face.right()
        bottom = face.bottom()
        cv2.rectangle(img, (left, top), (right, bottom), (255, 0, 255), 5) 
    cv2.imwrite(f'../result/hog_anime_face_detect_{file_name[-5]}.jpg', img)  


if __name__ == '__main__':
    hog_anime_face_detect(sys.argv[1])

Result

Total Missing Error Time
10 3 0 2.42s

在这里插入图片描述

Anime Face Detection Based on SSD

Repository

https://github.com/WynMew/AnimeFaceBoxes

Environment

Example

ssd_anime_face_detect.py (The code is too long to display, Please download and view)

Result

Total Missing Error Time
13 0 0 0.72s

在这里插入图片描述

Other Experiment

Test Sample

在这里插入图片描述

【Painter】ゆりりん【Pixiv ID】88049646

在这里插入图片描述

【Painter】Nahaki【Pixiv ID】84678881

在这里插入图片描述

【Painter】A.one【Pixiv ID】66996496

在这里插入图片描述

【Painter】D.【Pixiv ID】68074033

Test Result

在这里插入图片描述 在这里插入图片描述 在这里插入图片描述 在这里插入图片描述

Analysis

The anime face detection algorithm based on MLP is too slow to meet the requirements of practical applications. The other three algorithms behave differently on different sample image.

Future Work

Cite

https://github.com/nagadomi/lbpcascade_animeface

https://github.com/nya3jp/python-animeface

https://github.com/marron-akanishi/AFD

https://github.com/WynMew/AnimeFaceBoxes

https://github.com/hiromu/AnimeFace

anime-face-detection's People

Stargazers

 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

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.