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

本站现有博文339篇,共被浏览995692次

本站已经建立2706天!

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