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

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

本站已经建立2442天!

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