利用GAN学习二次元动漫画风

工具和资源:

1.动漫人脸探测轮子

2.DCGAN轮子

3.Python截取动漫代码

4.中二病的RAW视频资源

流程:

1.取t时间间隔截取动漫截图

2.识别每一张截图中的人脸,裁剪成96x96

3.作为样本喂给DCGAN

实验结果:

t=1s,图片和上面不一样取了128x128

代码:

import cv2  
import sys
import os.path

if len(sys.argv) != 3:
    sys.stderr.write("usage: get_frame.py <filename> <delta_time>\n")
    sys.exit(-1)

def detect(image, 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)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)

    faces = cascade.detectMultiScale(gray,
                                     # detector options
                                     scaleFactor=1.5,
                                     minNeighbors=5,
                                     minSize=(128, 128))
    for i, (x, y, w, h) in enumerate(faces):
        face = image[y: y + h, x:x + w, :]
        face = cv2.resize(face, (128, 128))
        save_filename = 'chu2byo_faces/' + sys.argv[1] + '.' + str(c/23) + '.' + str(i) + '.jpg' #存储为图像  
        print (save_filename)
        cv2.imwrite(save_filename, face)

vc = cv2.VideoCapture(sys.argv[1]) #读入视频文件  
c = 1  

if vc.isOpened(): #判断是否正常打开  
    rval , frame = vc.read()  
else:  
    rval = False  

timeF = int(sys.argv[2])

while rval:   #循环读取视频帧  
    rval, frame = vc.read()  
    if(c%timeF == 0): #每隔timeF帧进行存储操作  
        detect(frame) #提取人脸
        # exit()
    c = c + 1
    # print(c)
vc.release()  

得到的截图:

DCGAN实验的结果:

epoch 100

epoch200

epoch259(终止轮)

感觉上有点儿过拟合啊……

2017-05-31 16:5181