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

本站现有博文341篇,共被浏览1048105次

本站已经建立2729天!

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