ZhenglinZhou / STAR

[CVPR 2023] STAR Loss: Reducing Semantic Ambiguity in Facial Landmark Detection
157 stars 17 forks source link

Output Visualization in tester #12

Closed aylinSyntonym closed 12 months ago

aylinSyntonym commented 1 year ago

Hi, I want to visualize test results. I can not see landmark on an image or draw it because of the normalization the landmarks comes normalized way such as negatives. How to convert them to unnormalized version to print the image?

ZhenglinZhou commented 1 year ago

Hi @aylinSyntonym, sorry for the late reply.

The de-normalization function can be found here, which is used to denormalize points from [-1, 1] to [-0.5, SIZE - 0.5]. Furthermore, the full post-process can be found here.

To visualize the test results, the following code could be considered:

def draw_pts(img, pts, shift=4, color=(0, 255, 0), radius=1, save_path=None):
    img_draw = copy.deepcopy(img)
    for cnt, p in enumerate(pts):
        if len(img_draw.shape) > 2:
            img_draw = cv2.cvtColor(img_draw, cv2.COLOR_BGR2RGB)
            img_draw = cv2.cvtColor(img_draw, cv2.COLOR_RGB2BGR)
        cv2.circle(img_draw, (int(p[0] * (1 << shift)), int(p[1] * (1 << shift))), radius << shift, color, -1,
                   cv2.LINE_AA, shift=shift)
    if save_path is not None:
        cv2.imwrite(save_path, img_draw)
    return img_draw

image_draw = draw_pts(image, landmarks_pv)

If you have any question, please let me know.