CV:利用人工智能演算法讓古代皇帝畫像以及古代四大美女畫像動起來(模仿偶像胡歌劇中角色表情動作)
利用人工智能演算法讓古代四大美女畫像動起來(模仿偶像胡歌劇中角色表情動作)
導讀:本論文來自NeurIPS2019,該演算法中主要采用一階運動模型的思想,用一組自學習的關鍵點和區域仿射變換,建立了復雜運動模型,模型由運動估計模塊和影像生成模塊兩個主要部分組成,首先進行關鍵點檢測,然后根據關鍵點,進行運動估計,最后使用影像生成模塊,生成最終效果,
額,哈哈,不好意思了,又拿我的偶像胡歌下手啦,視頻截取來源偶像胡歌在《獵場》中的一角色,
目錄
利用人工智能演算法讓經典圖片根據自定義動作嗨起來(將一張靜態人像圖片轉為帶表情動作視頻)
相關論文
輸出結果
利用人工智能演算法讓古代皇帝畫像動起來(模仿偶像胡歌《獵場》劇中角色表情動作)
利用人工智能演算法讓古代四大美女畫像動起來
實作代碼
作品視頻鏈接
利用人工智能演算法,讓古代皇帝畫像動起來(模仿偶像胡歌《獵場》劇中角色表情動作)
利用人工智能演算法讓古代美女《西施、王昭君、貂蟬、楊玉環四大美女領銜》畫像動起來
利用人工智能演算法讓經典圖片根據自定義動作嗨起來(將一張靜態人像圖片轉為帶表情動作視頻)
相關論文
Paper:《First Order Motion Model for Image Animation》翻譯與解讀
輸出結果
利用人工智能演算法讓古代皇帝畫像動起來(模仿偶像胡歌《獵場》劇中角色表情動作)




利用人工智能演算法讓古代四大美女畫像動起來



實作代碼
更新中……
- import imageio
- import torch
- from tqdm import tqdm
- from animate import normalize_kp
- from demo import load_checkpoints
- import numpy as np
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- from skimage import img_as_ubyte
- from skimage.transform import resize
- import cv2
- import os
- import argparse
- ap = argparse.ArgumentParser()
- ap.add_argument("-i", "--input_image", required=True,help="Path to image to animate")
- ap.add_argument("-c", "--checkpoint", required=True,help="Path to checkpoint")
- ap.add_argument("-v","--input_video", required=False, help="Path to video input")
- args = vars(ap.parse_args())
- print("[INFO] loading source image and checkpoint...")
- source_path = args['input_image']
- checkpoint_path = args['checkpoint']
- if args['input_video']:
- video_path = args['input_video']
- else:
- video_path = None
- source_image = imageio.imread(source_path)
- source_image = resize(source_image,(256,256))[..., :3]
- generator, kp_detector = load_checkpoints(config_path='config/vox-256.yaml', checkpoint_path=checkpoint_path)
- if not os.path.exists('output'):
- os.mkdir('output')
- relative=True
- adapt_movement_scale=True
- cpu=False
- if video_path:
- cap = cv2.VideoCapture(video_path)
- print("[INFO] Loading video from the given path")
- else:
- cap = cv2.VideoCapture(0)
- print("[INFO] Initializing front camera...")
- fourcc = cv2.VideoWriter_fourcc(*'MJPG')
- out1 = cv2.VideoWriter('output/Animation_HuGe_02.avi', fourcc, 12, (256*3 , 256), True)
- cv2_source = cv2.cvtColor(source_image.astype('float32'),cv2.COLOR_BGR2RGB)
- with torch.no_grad() :
- predictions = []
- source = torch.tensor(source_image[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
- if not cpu:
- source = source.cuda()
- kp_source = kp_detector(source)
- count = 0
- while(True):
- ret, frame = cap.read()
- frame = cv2.flip(frame,1)
- if ret == True:
- if not video_path:
- x = 143
- y = 87
- w = 322
- h = 322
- frame = frame[y:y+h,x:x+w]
- frame1 = resize(frame,(256,256))[..., :3]
- if count == 0:
- source_image1 = frame1
- source1 = torch.tensor(source_image1[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
- kp_driving_initial = kp_detector(source1)
- frame_test = torch.tensor(frame1[np.newaxis].astype(np.float32)).permute(0, 3, 1, 2)
- driving_frame = frame_test
- if not cpu:
- driving_frame = driving_frame.cuda()
- kp_driving = kp_detector(driving_frame)
- kp_norm = normalize_kp(kp_source=kp_source,
- kp_driving=kp_driving,
- kp_driving_initial=kp_driving_initial,
- use_relative_movement=relative,
- use_relative_jacobian=relative,
- adapt_movement_scale=adapt_movement_scale)
- out = generator(source, kp_source=kp_source, kp_driving=kp_norm)
- predictions.append(np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0])
- im = np.transpose(out['prediction'].data.cpu().numpy(), [0, 2, 3, 1])[0]
- im = cv2.cvtColor(im,cv2.COLOR_RGB2BGR)
- joinedFrame = np.concatenate((cv2_source,im,frame1),axis=1)
- cv2.imshow('Test',joinedFrame)
- out1.write(img_as_ubyte(joinedFrame))
- count += 1
- if cv2.waitKey(20) & 0xFF == ord('q'):
- break
- else:
- break
- cap.release()
- out1.release()
- cv2.destroyAllWindows()
本文首發于python黑洞網,博客園同步更新
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/3678.html
標籤:Python
上一篇:MYSQL雜碎小知識
