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

本站现有博文332篇,共被浏览875546

本站已经建立2583天!

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