I was studying face recognition to do various things with machine learning, but I made it without taking a break. If you put an image of a person, it will judge whether it is an animation or a photo. Since it is based on the face, it may be judged as a photo if you include a realistic picture. I think it can be used by a pc to determine whether it is really close to reality through a live-action realistic picture.
python3.○ OpenCV for python version Cascade classifier for photographic animation (described later)
It's a simple thing, so let's code it as soon as you get what you need.
(Folder) img-Image storage
(Folder) haarcascade-Cascade classifier storage
(File) auto_anime_classifier.py
Please place the above items in the same directory The files to put in the haarcascade folder this time
Source code
auto_anime_classifier.py
import cv2
import numpy as np
if __name__ == '__main__':
CASCADE_PATH = 'haarcascade/'
face_count = []
print('Plz input filename')
img_name = input('>> ')
img = cv2.imread('img/'+str(img_name), cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
photo = cv2.CascadeClassifier(CASCADE_PATH + 'haarcascade_frontalface_alt.xml')
anime = cv2.CascadeClassifier(CASCADE_PATH + 'lbpcascade_animeface.xml')
face_count.append(len(photo.detectMultiScale(gray, 1.1, 3)))
face_count.append(len(anime.detectMultiScale(gray, 1.1, 3)))
if face_count[0] > face_count[1]:
print('Maybe photo.')
elif face_count[1] > face_count[0]:
print('Maybe anime.')
elif face_count[0] >= 1 and face_count[1] >= 1:
print('Both attributes.')
elif face_count[0] == 0 and face_count[1] == 0:
print('Undeciable.')
About OpenCV, I will omit most of it because there are a lot of commentary blogs with wonderful contents. Enter the image in the img folder and read it with imread (). After that, it is grayed.
print('Plz input filename')
img_name = input('>> ')
img = cv2.imread('img/'+str(img_name), cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Create a classifier that reads the cascade classification files for each photo and animation.
photo = cv2.CascadeClassifier(CASCADE_PATH + 'haarcascade_frontalface_alt.xml')
anime = cv2.CascadeClassifier(CASCADE_PATH + 'lbpcascade_animeface.xml')
Store the number read by each classifier in face_count. The presence or absence of this is the criterion.
face_count.append(len(photo.detectMultiScale(gray, 1.1, 3)))
face_count.append(len(anime.detectMultiScale(gray, 1.1, 3)))
Finally, the judgment part. Compare whether it is simply recognized or not.
if face_count[0] > face_count[1]:
print('Maybe photo.')
elif face_count[1] > face_count[0]:
print('Maybe anime.')
elif face_count[0] >= 1 and face_count[1] >= 1:
print('Both attributes.')
elif face_count[0] == 0 and face_count[1] == 0:
print('Undeciable.')
Closeness to reality Maybe photo (probably a live-action film) → Both attributes (either one works) → Maybe anime (maybe a picture) → Undeciable (I don't know.
Let's play the explanation moderately.
The Beatles. It is cool~
Plz input filename
>> beatles.jpeg
Maybe photo.
It looks like a photo. That's right.
The main character of NEW GAME. cute~
Plz input filename
>> aoba.jpeg
Maybe anime.
It seems to be an anime. Well, you can see it if you look at it.
Even if I did it normally, nothing was interesting, so let's put in a video that I do not know which one the program shows.
This is Mr. Layer SeeU from China. The image is a quote from his Twitter account.
Plz input filename
>> seeu.png
Maybe anime.
It seems to be an anime. From a human perspective, it doesn't look like a picture. Does image processing mean anything?
It is a character created by MMORPG called Black Desert. A type of game that takes hours to characterize.
Plz input filename
>> kuroisabaku.png
Both attributes.
It seems that you can go either way. Except for the big black eyes and the small nose, I don't think it feels like a picture.
It is a male character made in a game called Honey Select. You can make illusion characters without any discomfort even for characters other than young people.
Plz input filename
>> honey.png
Maybe photo.
It seems to be a photo. I wonder if the shape of the nose is an important turning point. By the way, the male character made with PSO2 was treated as a picture.
A doll from Orient Industry. It's very real.
Plz input filename
>> orient.jpg
Both attributes.
There was an anime element. I wonder why ...
The program this time was just about whether each judge could recognize the face. If it were to be improved, I felt that it was necessary to output detailed judgment elements from each judgment device and create parameters as numerical values. You have to study cascading classification. It's been a long time, but thank you for watching so far! !!
Recommended Posts