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

本站现有博文322篇,共被浏览791219

本站已经建立2487天!

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