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

本站现有博文336篇,共被浏览946727

本站已经建立2657天!

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