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

本站现有博文337篇,共被浏览961426次

本站已经建立2673天!

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