最常用于视频处理的 Python 模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1480431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 22:21:58  来源:igfitidea点击:

Most used Python module for video processing?

pythonimage-processingvideo-processing

提问by Tarantula

I need to:

我需要:

  1. Open a video file
  2. Iterate over the frames of the file as images
  3. Do some analysis in this image frame of the video
  4. Draw in this image of the video
  5. Create a new video with these changes
  1. 打开视频文件
  2. 将文件的帧作为图像进行迭代
  3. 在视频的这个图像帧中做一些分析
  4. 在视频中绘制此图像
  5. 使用这些更改创建新视频

OpenCV isn't working for my webcam, but python-gst is working. Is this possible using python-gst?

OpenCV 不适用于我的网络摄像头,但 python-gst 正在工作。这可以使用 python-gst 吗?

Thank you!

谢谢!

采纳答案by Martin Beckett

Do you mean opencv can't connect to your webcam or can't read video files recorded by it?

您的意思是opencv无法连接到您的网络摄像头或无法读取其录制的视频文件?

Have you tried saving the video in an other format?

您是否尝试以其他格式保存视频?

OpenCV is probably the best supported python image processing tool

OpenCV 可能是最受支持的 Python 图像处理工具

回答by Andrew Wagner

I'm going through this myself. It's only a couple of lines in MATLAB using mmreader, but I've already blown two work days trying to figure out how to pull frames from a video file into numpy. If you have enough disk space, and it doesn't have to be real time, you can use:

我自己正在经历这个。在使用 mmreader 的 MATLAB 中只有几行代码,但我已经花了两个工作日试图弄清楚如何将视频文件中的帧提取到 numpy 中。如果您有足够的磁盘空间,并且不必是实时的,则可以使用:

mplayer -noconsolecontrols -vo png blah.mov

and then pull the .png files into numpy using:

然后使用以下命令将 .png 文件拉入 numpy:

pylab.imread('blah0000001.png')

I know this is incomplete, but it may still help you. Good luck!

我知道这是不完整的,但它仍然可以帮助你。祝你好运!

回答by meduz

I used this script to convert a movie to a numpy array + binary store:

我使用此脚本将电影转换为 numpy 数组 + 二进制存储:

"""
Takes a MPEG movie and produces a numpy record file with a numpy array.

"""
import os

filename = 'walking'
if not(os.path.isfile(filename + '.npy')): # do nothing if files exists
    N_frame = 42 # number of frames we want to store
    os.system('ffmpeg -i WALK.MOV.qt -f image2 foo-%03d.png')
    # convert them to numpy
    from numpy import zeros, save, mean
    from pylab import imread

    n_x, n_y, n_rgb =  imread('foo-001.png').shape

    mov = zeros((n_y, n_x, N_frame))

    for i_frame in range(N_frame):
        name = 'foo-%03d.png' % (i_frame +1)
        mov[:n_y,:n_x,i_frame] = flipud(mean(imread(name), axis=2)).T

    os.system('rm -f foo-*.png')
    save(filename + '.npy', mov)

note that depending on your conventions you may not want to flip the image. you may then load it using :

请注意,根据您的惯例,您可能不想翻转图像。然后您可以使用以下方法加载它:

load('walking.npy')

回答by ZZambia

Just build a C/C++ wrapper for your webcam and then use SWIG or SIP to access these functions from Python. Then use OpenCV in Python that's the best open sourced computer vision library in the wild.

只需为您的网络摄像头构建一个 C/C++ 包装器,然后使用 SWIG 或 SIP 从 Python 访问这些函数。然后在 Python 中使用 OpenCV,它是目前最好的开源计算机视觉库。

If you worry for performance and you work under Linux, you could download free versions of Intel Performance Primitives (IPP) that could be loaded at runtime with zero effort from OpenCV. For certain algorithms you could get a 200% boost of performances, plus automatic multicore support for most of time consuming functions.

如果您担心性能并且在 Linux 下工作,您可以从 OpenCV 下载免费版本的 Intel Performance Primitives (IPP),该版本可以在运行时轻松加载。对于某些算法,您可以获得 200% 的性能提升,以及对大多数耗时功能的自动多核支持。