我们经常会遇到这样的问题,报名参加考某种考试, 需要提交符合指定背景、尺寸要求的照片,但是手上只有生活中,或者照片尺寸符合要求,但是背景不符合要求的情况。 今天我教大家基于人脸识别和图像分割技术制作证件照,其关键代码不足10行。
1. 读取图像节点,使用PIL库的Image对象的Open方法打开图片
Image.open(fp)
2. 修改尺寸节点,使用if……else判断语句 3. 人脸轮廓检测节点,使用paddlepaddle深度学习框架,调用模face_landmark_localization推理
face_landmark = hub.Module(name="face_landmark_localization")
result = face_landmark.keypoint_detection(images=[np.array(raw_img)])
face = np.array(result[0]['data'][0], dtype=np.int64)
4. 裁剪尺寸节点,依据步骤3人脸轮廓,根据人脸裁剪一定大小的图片
face[:, 0].min()
right = face[:, 0].max()
w = right - left
cw = (right+left) // 2
upper = face[