0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

#アニメ画像から顔を切り抜く方法です

#アニメデータセットをつくりたい
画風変換などで、アニメ画像のデータセットを作るときに、顔だけ切り抜きたい時があります。
大量の画像を自動で処理したい。

#animefaceで切り抜ける

OpenCVでanimefaceを使うことで、自動処理できます。

#コード

lbpcascade_animefaceをダウンロードします。

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

def crop_anime_face(path,write_path):
  face_detector = cv2.CascadeClassifier('lbpcascade_animeface.xml') # initialize detector
  input_img_name = path
  img = cv2.imread(input_img_name)

  faces = face_detector.detectMultiScale(img) # detect
  for x, y, w, h in faces:
    left = x
    top = y
    right = x + w
    bottom = y + h
    face_img = bg[int(top):int(bottom), int(left):int(right)] # crop
    cv2.imwrite(write_path,face_img)

🐣


フリーランスエンジニアです。
お仕事のご相談こちらまで
rockyshikoku@gmail.com

Core MLやARKitを使ったアプリを作っています。
機械学習/AR関連の情報を発信しています。

Twitter
Medium

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?