Files
insightface/recognition/tools
2021-02-21 22:31:44 +08:00
..
2020-11-06 13:59:21 +08:00
2020-11-30 14:31:52 +08:00
2021-02-21 20:48:35 +08:00
2021-02-21 20:48:35 +08:00
2021-02-21 22:31:44 +08:00

CPP-Align

Face Mask Renderer

We provide a simple tool to add masks on face images automatically.

We can use this tool to do data augmentation while training our face recognition models.

Face Image OP Mask Image Out
face +F mask mask
face +F mask mask
face +H mask mask

F means FULL while H means HALF.

Data Prepare

Add Mask to Face Image

Please refer to make_renderer.py for detail example. You can get example mask images by checking the image url from the table above.

(1) init renderer:

tool = MaskRenderer('./assets_mask')

(2) load face and mask images

image = cv2.imread("../../deploy/Tom_Hanks_54745.png")
mask_image  = cv2.imread("masks/mask2.jpg")

(3) build necessary params for face image, this can be done in offline.

params = tool.build_params(image)

(4) do mask render, it costs about 10ms on 224x224 UV size, CPU single thread.

mask_out = tool.render_mask(image, mask_image, params)

(5) do half mask render.

mask_half_out = tool.render_mask(image, mask_image, params, positions=[0.1, 0.5, 0.9, 0.7])