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

本站现有博文339篇,共被浏览990209次

本站已经建立2702天!

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