Erlo

利用人工智能算法让古代皇帝画像以及古代四大美女画像动起来(模仿偶像胡歌剧中角色表情动作

2020-09-02 13:00:25 发布   462 浏览  
页面报错/反馈
收藏 点赞

CV:利用人工智能算法让古代皇帝画像以及古代四大美女画像动起来(模仿偶像胡歌剧中角色表情动作)
利用人工智能算法让古代四大美女画像动起来(模仿偶像胡歌剧中角色表情动作)

导读:本论文来自NeurIPS2019,该算法中主要采用一阶运动模型的思想,用一组自学习的关键点和局部仿射变换,建立了复杂运动模型。模型由运动估计模块和图像生成模块两个主要部分组成。首先进行关键点检测,然后根据关键点,进行运动估计,最后使用图像生成模块,生成最终效果。
额,哈哈,不好意思了,又拿我的偶像胡歌下手啦,视频截取来源偶像胡歌在《猎场》中的一角色。

 

 

 

目录

利用人工智能算法让经典图片根据自定义动作嗨起来(将一张静态人像图片转为带表情动作视频)

相关论文

输出结果

利用人工智能算法让古代皇帝画像动起来(模仿偶像胡歌《猎场》剧中角色表情动作)

利用人工智能算法让古代四大美女画像动起来

实现代码


 

作品视频链接
利用人工智能算法,让古代皇帝画像动起来(模仿偶像胡歌《猎场》剧中角色表情动作)
利用人工智能算法让古代美女《西施、王昭君、貂蝉、杨玉环四大美女领衔》画像动起来

利用人工智能算法让经典图片根据自定义动作嗨起来(将一张静态人像图片转为带表情动作视频)

相关论文

Paper:《First Order Motion Model for Image Animation》翻译与解读

 

输出结果

利用人工智能算法让古代皇帝画像动起来(模仿偶像胡歌《猎场》剧中角色表情动作)

 

利用人工智能算法让古代四大美女画像动起来

 

 

实现代码

更新中……

  1.  

    import imageio
  2.  

    import torch
  3.  

    from tqdm import tqdm
  4.  

    from animate import normalize_kp
  5.  

    from demo import load_checkpoints
  6.  

    import numpy as np
  7.  

    import matplotlib.pyplot as plt
  8.  

    import matplotlib.animation as animation
  9.  

    from skimage import img_as_ubyte
  10.  

    from skimage.transform import resize
  11.  

    import cv2
  12.  

    import os
  13.  

    import argparse
  14.  

     

  15.  

    ap = argparse.ArgumentParser()
  16.  

    ap.add_argument("-i", "--input_image", required=True,help="Path to image to animate")
  17.  

    ap.add_argument("-c", "--checkpoint", required=True,help="Path to checkpoint")
  18.  

    ap.add_argument("-v","--input_video", required=False, help="Path to video input")
  19.  

     

  20.  

    args = vars(ap.parse_args())
  21.  

     

  22.  

    print("[INFO] loading source image and checkpoint...")
  23.  

    source_path = args['input_image']
  24.  

    checkpoint_path = args['checkpoint']
  25.  

    if args['input_video']:
  26.  

    video_path = args['input_video']
  27.  

    else:
  28.  

    video_path = None
  29.  

    source_image = imageio.imread(source_path)
  30.  

    source_image = resize(source_image,(256,256))[..., :3]
  31.  

     

  32.  

    generator, kp_detector = load_checkpoints(config_path='config/vox-256.yaml', checkpoint_path=checkpoint_path)
  33.  

     

  34.  

    if not os.path.exists('output'):
  35.  

    os.mkdir('output')
  36.  

     

  37.  

     

  38.  

    relative=True
  39.  

    adapt_movement_scale=True
  40.  

    cpu=False
  41.  

     

  42.  

    if video_path:
  43.  

    cap = cv2.VideoCapture(video_path)
  44.  

    print("[INFO] Loading video from the given path")
  45.  

    else:
  46.  

    cap = cv2.VideoCapture(0)
  47.  

    print("[INFO] Initializing front camera...")
  48.  

     

  49.  

    fourcc = cv2.VideoWriter_fourcc(*'MJPG')
  50.  

    out1 = cv2.VideoWriter('output/Animation_HuGe_02.avi', fourcc, 12, (256*3 , 256), True)
  51.  

     

  52.  

    cv2_source = cv2.cvtColor(source_image.astype('float32'),cv2.COLOR_BGR2RGB)
  53.  

    with torch.no_grad() :
  54.  

    predictions = []
  55.  

    source = torch.tensor(source_image[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
  56.  

    if not cpu:
  57.  

    source = source.cuda()
  58.  

    kp_source = kp_detector(source)
  59.  

    count = 0
  60.  

    while(True):
  61.  

    ret, frame = cap.read()
  62.  

    frame = cv2.flip(frame,1)
  63.  

    if ret == True:
  64.  

     

  65.  

    if not video_path:
  66.  

    x = 143
  67.  

    y = 87
  68.  

    w = 322
  69.  

    h = 322
  70.  

    frame = frame[y:y+h,x:x+w]
  71.  

    frame1 = resize(frame,(256,256))[..., :3]
  72.  

     

  73.  

    if count == 0:
  74.  

    source_image1 = frame1
  75.  

    source1 = torch.tensor(source_image1[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
  76.  

    kp_driving_initial = kp_detector(source1)
  77.  

     

  78.  

    frame_test = torch.tensor(frame1[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
  79.  

     

  80.  

    driving_frame = frame_test
  81.  

    if not cpu:
  82.  

    driving_frame = driving_frame.cuda()
  83.  

    kp_driving = kp_detector(driving_frame)
  84.  

    kp_norm = normalize_kp(kp_source=kp_source,
  85.  

    kp_driving=kp_driving,
  86.  

    kp_driving_initial=kp_driving_initial,
  87.  

    use_relative_movement=relative,
  88.  

    use_relative_jacobian=relative,
  89.  

    adapt_movement_scale=adapt_movement_scale)
  90.  

    out = generator(source, kp_source=kp_source, kp_driving=kp_norm)
  91.  

    predictions.append(np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0])
  92.  

    im = np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0]
  93.  

    im = cv2.cvtColor(im,cv2.COLOR_RGB2BGR)
  94.  

    joinedFrame = np.concatenate((cv2_source,im,frame1),axis=1)
  95.  

     

  96.  

    cv2.imshow('Test',joinedFrame)
  97.  

    out1.write(img_as_ubyte(joinedFrame))
  98.  

    count += 1
  99.  

    if cv2.waitKey(20) & 0xFF == ord('q'):
  100.  

    break
  101.  

    else:
  102.  

    break
  103.  

     

  104.  

    cap.release()
  105.  

    out1.release()
  106.  

    cv2.destroyAllWindows()
  107.  

    本文首发于python黑洞网,博客园同步更新

登录查看全部

参与评论

评论留言

还没有评论留言,赶紧来抢楼吧~~

手机查看

返回顶部

给这篇文章打个标签吧~

棒极了 糟糕透顶 好文章 PHP JAVA JS 小程序 Python SEO MySql 确认