+
75
-

python如何提取视频中人物的深度信息?

python如何提取视频中人物的深度信息?


网友回复

+
15
-

可使用 Depth Anything V2

import cv2
import numpy as np
import torch
import mediapipe as mp
from PIL import Image
from transformers import pipeline


def load_depth_model():
    device = 0 if torch.cuda.is_available() else -1

    depth_pipe = pipeline(
        task="depth-estimation",
        model="depth-anything/Depth-Anything-V2-Small-hf",
        device=device
    )

    return depth_pipe


def load_person_segmenter():
    mp_selfie = mp.solutions.selfie_segmentation
    return mp_selfie.SelfieSegmentation(model_selection=1)


def get_person_mask(frame_rgb, segmenter):
    result = segmenter.process(frame_rgb)
    mask = result.segmentation_mask > 0.5
    return mask


def main(video_path, output_path="person_depth_da.mp4"):
    cap = cv2.VideoCapture(video_path)

  ...

点击查看剩余70%

我知道答案,我要回答