4/19/2022

rectangle, box face -> mosaic, pixelate

 

refer to mosaic function

..

def mosaic(img, rect, size):
(x1, y1, x2, y2) = rect
w = x2 - x1
h = y2 - y1
i_rect = img[y1:y2, x1:x2]
i_small = cv2.resize(i_rect, ( size, size))
i_mos = cv2.resize(i_small, (w, h), interpolation=cv2.INTER_AREA)
img2 = img.copy()
img2[y1:y2, x1:x2] = i_mos
return img2

#.... detect face
for face_dict in faces_dict:
x1,y1 = ( int(face_dict['x1']), int(face_dict['y1']))
x2,y2 = ( int(face_dict['x2']), int(face_dict['y2']))

# image = anonymize_face_pixelate(image[y1:y2, x1:x2, :] , blocks=3)
image = mosaic(image, (x1, y1, x2, y2), 10 )
#.... face mosaic

..


Ex) result


Thank you.

www.marearts.com