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

本站现有博文327篇,共被浏览833201

本站已经建立2538天!

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