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

本站现有博文324篇,共被浏览821373

本站已经建立2526天!

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