-
Notifications
You must be signed in to change notification settings - Fork 434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add_mask_one #23
Comments
|
我就是这样做的,先输入原图和一个脸的关键点得到加mask的image,然后输入另一个脸landmark和image,而且这个image我还深拷贝了一下,但是输出的是如上图,想不通怎么回事。你可以试一下,谢谢------------------ 原始邮件 ------------------
发件人: "Champagne&nbsp;Jin"<notifications@github.com>
发送时间: 2021年1月31日(星期天) 中午1:47
收件人: "JDAI-CV/FaceX-Zoo"<FaceX-Zoo@noreply.github.com>;
抄送: "zengwb-lx"<1303281435@qq.com>;"Author"<author@noreply.github.com>;
主题: Re: [JDAI-CV/FaceX-Zoo] add_mask_one (#23)
|
I made a simple implementation: First, you need to get the corresponding facial landmark detection results by the Second, add the following codes into class """
@author: Yinglu Liu, Jun Wang
@modifier: Champagne Jin (643683905@qq.com)
@date: 20210201
"""
def add_mask_several(self, image_path, face_lmses, template_name, masked_face_path):
"""Add mask to one image.
Args:
image_path(str): the image to add mask.
face_lmses(str): list of face landmarks, [[x1, y1, x2, y2, ..., x106, y106], [x1, y1, x2, y2, ..., x106, y106], ...]
template_name(str): the mask template to be added on the current image,
got to '/Data/mask-data' for all template.
masked_face_path(str): the path to save masked image.
"""
import copy
image = imread(image_path)
ref_texture_src = self.template_name2ref_texture_src[template_name]
uv_mask_src = self.template_name2uv_mask_src[template_name]
if image.ndim == 2:
image = cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
[h, w, c] = image.shape
if c == 4:
image = image[:,:,:3]
image = image/255. #!!
image = copy.deepcopy(image)
for face_lms in face_lmses:
pos, vertices = self.get_vertices(face_lms, image) #3d reconstruction -> get texture.
texture = cv2.remap(image, pos[:,:,:2].astype(np.float32), None,
interpolation=cv2.INTER_NEAREST,
borderMode=cv2.BORDER_CONSTANT,borderValue=(0)) # 原来的人脸texture
new_texture = self.get_new_texture(ref_texture_src, uv_mask_src, texture) # 加上mask的人脸texture
#remap to input image.(render)
vis_colors = np.ones((vertices.shape[0], 1))
face_mask = mesh.render.render_colors(vertices, self.prn.triangles, vis_colors, h, w, c = 1)
face_mask = np.squeeze(face_mask > 0).astype(np.float32)
new_colors = self.prn.get_colors_from_texture(new_texture)
new_image = mesh.render.render_colors(vertices, self.prn.triangles, new_colors, h, w, c = 3)
image = image * (1 - face_mask[:, :, np.newaxis]) + new_image * face_mask[:, :, np.newaxis]
image = np.clip(image, -1, 1) #must clip to (-1, 1)!
imsave(masked_face_path, image) At last, add a new file called """
@author: Yinglu Liu, Jun Wang
@modifier: Champagne Jin (643683905@qq.com)
@date: 20210201
"""
from face_masker import FaceMasker
if __name__ == '__main__':
is_aug = True
image_path = 'Data/test-data/test1.jpg'
template_name = '0.png'
masked_face_path = 'test1_mask1_several.jpg'
face_lms_files = ['Data/test-data/test1_landmark_res0.txt', 'Data/test-data/test1_landmark_res1.txt']
face_lmses = []
for face_lms_file in face_lms_files:
face_lms_str = open(face_lms_file).readline().strip().split(' ')
face_lmses.append([float(num) for num in face_lms_str])
face_masker = FaceMasker(is_aug)
face_masker.add_mask_several(image_path, face_lmses, template_name, masked_face_path) Tips: the Then, you just need to run it. |
thanks for you reply. |
😸 |
好喽,您好 我在用face-3d时没有找到readme中由a-f相关的代码,请问一下 这个您有实现吗 |
你好,add_mask如果一张图有两个脸的话,无法同时给两个脸加上口罩,在遍历face_lms时会把前一次加的口罩去除掉,有什么好的建议修改加载一图多脸的情况吗? 谢谢
The text was updated successfully, but these errors were encountered: