Audio-driven-TalkingFace-HeadPose
Audio-driven-TalkingFace-HeadPose copied to clipboard
how to transfer alpha_blend_newsold.m to python?
how to transfer alpha_blend_newsold.m to python?
如何将alpha_blend_newsold.m传输到python? I also encountered the same problem, have you solved it?
I borrow it from other issue. The python code for alpha_blend_newsold.m
import sys
import glob
import os
import cv2
import numpy as np
video = sys.argv[1]
starti = int(sys.argv[2])
framenum = int(sys.argv[3])
srcdir = os.path.join('render',video)
tardir = os.path.join('render',video,'bm')
if not os.path.exists(tardir):
os.makedirs(tardir)
for i in range(starti,starti+framenum):
file = 'frame%s.png'% i
filepath = os.path.join(srcdir,file)
im1 = cv2.imread(filepath)
im2 = cv2.imread(os.path.join(srcdir,file[:-4]+'_render.png'),cv2.IMREAD_UNCHANGED)
alpha = im2[:,:,3]
contours,hierarchy = cv2.findContours(alpha,mode=cv2.RETR_TREE,method=cv2.CHAIN_APPROX_SIMPLE)
mask = np.zeros_like(im1)
cv2.drawContours(mask,contours,0,(1,1,1),-1)
im = im1*(1-mask)+im2[:,:,:3]*mask
print(os.path.join(tardir,file[:-4]+'_renderold_bm.png'))
cv2.imwrite(os.path.join(tardir,file[:-4]+'_renderold_bm.png'),im)
The python code for alpha_blend_vbg.m
import sys
import glob
import os
import cv2
import numpy as np
srcdirbg = sys.argv[1]
srcdir = sys.argv[2]
files = glob.glob(os.path.join(srcdir, '*.png'))
for file in files:
file = os.path.basename(file)
if len(file) >= 10 and file[-10:] == '_blend.png':
continue
if len(file) >= 11 and file[-11:] == '_blend2.png':
continue
im1 = cv2.imread(os.path.join(srcdirbg, file))
im2 = cv2.imread(os.path.join(srcdir, file), cv2.IMREAD_UNCHANGED)
alpha = im2[:, :, 3]
contours, hierarchy = cv2.findContours(alpha, mode=cv2.RETR_TREE, method=cv2.CHAIN_APPROX_SIMPLE)
mask = np.zeros_like(im1)
cv2.drawContours(mask,contours,0,(1,1,1),-1)
im = im1*(1-mask)+im2[:,:,:3]*mask
tarname = file[0:-4] + '_blend2.png'
cv2.imwrite(os.path.join(srcdir, tarname), im)
Hello, how do you need to modify the code in train_19news_1.py after converting the matlab code (alpha_blend.m/alpha_blend_vlog.m ) into python code?
Excuse me, could you tell me the version of matlab you use?