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

本站现有博文321篇,共被浏览775413

本站已经建立2466天!

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