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

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

本站已经建立2583天!

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