Ask Your Question
-1

How to fit mask on face using facial feature points on face opencv c++ / ios ?

asked 2017-09-08 02:25:31 -0600

Sandeep gravatar image

i want to put mask on face and i have detected facial feature point using haar cadcase detector . Can be fit mask on face properly on facial feature points in 3d

edit retag flag offensive close merge delete

Comments

I don't think this is possible without further processing. May be you can try calcBackproject

LBerger gravatar imageLBerger ( 2017-09-08 04:42:59 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-01-14 23:59:43 -0600

hanifalisohag gravatar image

You can easily mask upon an image using the following funciton:

def transparentOverlay(src, overlay, pos=(0, 0), scale=1):
    overlay = cv2.resize(overlay, (0, 0), fx=scale, fy=scale)
    h, w, _ = overlay.shape  # Size of foreground
    rows, cols, _ = src.shape  # Size of background Image
    y, x = pos[0], pos[1]  # Position of foreground/overlay image

    # loop over all pixels and apply the blending equation
    for i in range(h):
        for j in range(w):
            if x + i >= rows or y + j >= cols:
                continue
            alpha = float(overlay[i][j][3] / 255.0)  # read the alpha channel
            src[x + i][y + j] = alpha * overlay[i][j][:3] + (1 - alpha) * src[x + i][y + j]
    return src

You need to pass the source image, then the overlay mask and position where you want to set the mask. You can even set the masking scale. by calling it like this way.

transparentOverlay(face_cigar_roi_color,cigar,(int(w/2),int(sh_cigar/2)))

For details you can look at this link: Face masking and Overlay using OpenCV python

Output:

Face Masking Demo

edit flag offensive delete link more

Question Tools

Stats

Asked: 2017-09-08 02:25:31 -0600

Seen: 1,363 times

Last updated: Sep 08 '17