Comments (8)
from facex-zoo.
add_mask_one
本质上就是一张脸一张脸进行处理的,但是 add_mask_one
会在最后存储加了mask的图像,一种很简单的方法就是在处理一张人脸之后得到的新图像上继续使用 add_mask_one
给另外一个人脸加mask。这个应该并不算难,只要有对应的人脸的landmark坐标就可以实现。
from facex-zoo.
from facex-zoo.
I made a simple implementation:
First, you need to get the corresponding facial landmark detection results by the face_sdk
and copy them (.txt
files) into /FaceX-Zoo/addition_module/face_mask_adding/FMA-3D/Data/test-data/
directory.
Second, add the following codes into class FaceMasker
in /FaceX-Zoo/addition_module/face_mask_adding/FMA-3D/face_masker.py
:
"""
@author: Yinglu Liu, Jun Wang
@modifier: Champagne Jin ([email protected])
@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 add_mask_several.py
in directory /FaceX-Zoo/addition_module/face_mask_adding/FMA-3D/
, and paste the codes below into it:
"""
@author: Yinglu Liu, Jun Wang
@modifier: Champagne Jin ([email protected])
@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 face_lms_files
is the corresponding facial landmark detection files list.
Then, you just need to run it.
Good luck!
from facex-zoo.
This is the result I got just now 😄
from facex-zoo.
thanks for you reply.
from facex-zoo.
😸
from facex-zoo.
你你,add_mask如果一张脸个脸,无法,无法无法给给给两两两个个,face_lms face_lms时会时会时会时会把把前前一次一次除掉的加加的情况如何? 谢谢
好喽,您好 我在用face-3d时没有找到readme中由a-f相关的代码,请问一下 这个您有实现吗
from facex-zoo.
Related Issues (20)
- 请问有没有pytorch安装接口?
- add a mask
- [face_sdk] Error when detect and align face-down
- render_cy error
- loading pretrained backbones
- model4 is missing on net disk
- semi-siamese traning error
- semi-siamese training error
- multi-processing
- Questions about DMUE training on different datasets HOT 3
- FileNotFoundError: [Errno 2] No such file or directory: './weights/AffectNet_res18_acc0.6285.pth'
- CASIA-MFSD Dataset
- swin transformer depoly HOT 1
- face_parsing first time inference waits too long
- Training and Testing Image Format - Was the training done on BGR images and testing on RGB?
- face_sdk的face_pipeline里,人脸检测模型已经输出了5个关键点,为什么还要用faceAlignModel再检测关键点?
- DMUE pre-trained models
- 请问,我在lfw测试上效果不好?
- File "logging.conf" has a redundant ']' in line 32
- Model weights are trash
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facex-zoo.