views:

1624

answers:

5

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

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

Thank you!

+2  A: 

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

Have you tried saving the video in an other format?

OpenCV is probably the best supported python image processing tool

Martin Beckett
+1 for recommending OpenCV.
whatnick
A: 

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.

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.

ZZambia
A: 

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:

mplayer -noconsolecontrols -vo png blah.mov

and then pull the .png files into numpy using:

pylab.imread('blah0000001.png')

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

Drew Wagner
A: 

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

"""
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')
meduz