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

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

本站已经建立2512天!

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