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

本站现有博文340篇,共被浏览1018382次

本站已经建立2718天!

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