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

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

本站已经建立2466天!

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