def get_face(img, pnet, rnet, onet, image_size): minsize = 20 threshold = [0.6, 0.7, 0.7] factor = 0.709 margin = 44 input_image_size = image_size img_size = np.asarray(img.shape)[0:2] bounding_boxes, _ = detect_face.detect_face(img=img, minsize=minsize, pnet=pnet, rnet=rnet, onet=onet, threshold=threshold, factor=factor) all_faces = [] all_bb = [] if not len(bounding_boxes) == 0: for face in bounding_boxes: det = np.squeeze(face[0:4]) bb = np.zeros(4, dtype=np.int32) bb[0] = np.maximum(det[0] - margin / 2, 0) bb[1] = np.maximum(det[1] - margin / 2, 0) bb[2] = np.minimum(det[2] + margin / 2, img_size[1]) bb[3] = np.minimum(det[3] + margin / 2, img_size[0]) cropped = img[bb[1]:bb[3], bb[0]:bb[2], :] face_img = imresize(arr=cropped, size=(input_image_size, input_image_size), mode='RGB') all_faces.append(face_img) all_bb.append(bb) return all_faces, all_bb else: return all_faces, all_bb
def get_face(img, pnet, rnet, onet, image_size): """ to get the face from the image Args: img: image file Returns: numpy arrays of faces and corresponding faces """ logger.info(msg="get_face called") minsize = 20 threshold = [0.6, 0.7, 0.7] factor = 0.709 margin = 44 input_image_size = image_size img_size = np.asarray(img.shape)[0:2] bounding_boxes, _ = detect_face.detect_face(img=img, minsize=minsize, pnet=pnet, rnet=rnet, onet=onet, threshold=threshold, factor=factor) all_faces = [] all_bb = [] if not len(bounding_boxes) == 0: for face in bounding_boxes: det = np.squeeze(face[0:4]) bb = np.zeros(4, dtype=np.int32) bb[0] = np.maximum(det[0] - margin / 2, 0) bb[1] = np.maximum(det[1] - margin / 2, 0) bb[2] = np.minimum(det[2] + margin / 2, img_size[1]) bb[3] = np.minimum(det[3] + margin / 2, img_size[0]) cropped = img[bb[1]:bb[3], bb[0]:bb[2], :] # face_img = imresize(arr=cropped, size=( # input_image_size, input_image_size), mode='RGB') face_img = skimage.transform.resize( cropped, (input_image_size, input_image_size)) all_faces.append(face_img) all_bb.append(bb) return all_faces, all_bb