Mediapipe 面部网格使用通过 mediaipipe 生成的边界框裁剪时不会检测到面部(仅面部)

问题描述 投票:0回答:1

所以我一直在尝试使用mediapipefacemesh地标点来检测和裁剪面部来计算边界框。但是当我通过mediapipe运行裁剪后的图像时,它根本无法检测到某些图像的面部。 谁能解释一下为什么会这样?

我的印象是,如果 mediapipe 检测到同一张脸,那么在使用相同的 mediapipe 模型裁剪后应该给出相同的检测结果。

提前致谢

crop face-detection mediapipe face-mesh
1个回答
0
投票

我通过检测人脸解决了这个问题,然后在附加到crop_face之前添加25%的边距,并进行其他预处理,这就是函数 def preprocess_image(图像, input_size, 检测器): 原始图像 = 图像.copy() img_res = detector.detectFaces(original_image)

if len(img_res.boxes) > 0:
    bbox = img_res.boxes[0]  # Get لاbox
    x1, y1, x2, y2 = bbox
    x1 = int(x1 * image.shape[1])
    x2 = int(x2 * image.shape[1])
    y1 = int(y1 * image.shape[0])-28
    y2 = int(y2 * image.shape[0])+28

    # Adding  margin
    w = x2 - x1
    h = y2 - y1
    margin_h = int(0.25 * h)
    margin_w = int(0.25 * w)

    y1 = max(0, y1 - margin_h)
    y2 = min(original_image.shape[0], y2 + margin_h)
    x1 = max(0, x1 - margin_w)
    x2 = min(original_image.shape[1], x2 + margin_w)
    
    extended_image = original_image[y1:y2, x1:x2]

    if extended_image.size == 0:
        print("Extended crop results in empty image. Check bounding box and margin calculations.")
        return None, original_image, None

    # Resize the extended image to the input size required by the model
    image = cv2.resize(extended_image, input_size)
    image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    image = image.astype(np.float32)
    image = (image - 127.5) / 127.5  # Normalize the image (0,1)
    image = np.expand_dims(image, axis=0)
    return image, original_image, (x1, y1, x2, y2)
return None, original_image, None
© www.soinside.com 2019 - 2024. All rights reserved.