EADST

Python: Subtract the Background Image from A video

Python: Subtract the Background Image from A video.

import cv2
import numpy as np

def get_video_median(video_path, save_path):
    # Open Video
    cap = cv2.VideoCapture(video_path)

    # Randomly select 100 frames
    frame_num = 100
    frameIds = cap.get(cv2.CAP_PROP_FRAME_COUNT) * np.random.uniform(size=frame_num)

    # Store selected frames in an array
    frames = []
    for fid in frameIds:
        cap.set(cv2.CAP_PROP_POS_FRAMES, fid)
        ret, frame = cap.read()
        frames.append(frame)

    # Calculate the pixel median along the time axis
    medianFrame = np.median(frames, axis=0).astype(dtype=np.uint8) 
    img_save = '{}/median.jpg'.format(save_path)
    cv2.imwrite(img_save, medianFrame)


if __name__ == '__main__':
    video_path = 'test.mp4'
    save_path = '/data/video'
    get_video_median(video_path, save_path)
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
CLAP scipy Crawler BeautifulSoup Pillow 图形思考法 LaTeX Quantization Anaconda 算法题 Miniforge CSV XML Pickle Bipartite Algorithm Review Rebuttal Paddle Permission HaggingFace LoRA XGBoost OpenAI Food logger BF16 Shortcut Tiktoken Website 多进程 LLM printf Conda Augmentation UNIX SVR CV QWEN FP32 NLP CTC Domain Knowledge torchinfo CC Qwen Bitcoin OpenCV PIP Hungarian Data Bert 腾讯云 关于博主 GIT Ubuntu WebCrawler Bin Freesound uwsgi Pytorch SAM NLTK Logo FP16 EXCEL Diagram Color ResNet-50 Zip VGG-16 版权 AI ms-swift CUDA Tensor Streamlit RGB 阿里云 PDF git PDB Transformers Agent TensorRT API InvalidArgumentError Attention TensorFlow YOLO icon Math Django Card tqdm v2ray TTS Base64 Mixtral Qwen2.5 mmap Proxy 搞笑 Safetensors Pandas Michelin RL 强化学习 Dataset uWSGI Git GPTQ 多线程 transformers Gemma Nginx Animate PyTorch VSCode MD5 Jupyter Translation GGML Web News IndexTTS2 Llama 论文 Breakpoint git-lfs GoogLeNet Markdown 论文速读 Disk WAN UI HuggingFace Distillation Hotel 顶会 COCO Video SQLite 递归学习法 OCR Linux Statistics Vmess Random 证件照 Plate PyCharm 音频 DeepStream Heatmap v0.dev Land CEIR Firewall Vim DeepSeek Claude 域名 Password Qwen2 Template FlashAttention Quantize Datetime SQL Jetson TSV 继承 财报 FP8 diffusers Interview 飞书 RAR Excel ModelScope GPT4 Cloudreve hf Windows Hilton ChatGPT Docker 图标 第一性原理 Image2Text Baidu FastAPI Plotly 报税 CAM Sklearn LeetCode Github FP64 NameSilo Numpy Ptyhon Use C++ LLAMA Input Python SPIE 签证 ONNX Search 云服务器 BTC Google Clash Magnet tar llama.cpp 公式 Paper VPN 净利润 JSON Tracking
站点统计

本站现有博文333篇,共被浏览929280

本站已经建立2637天!

热门文章
文章归档
回到顶部