I was able to get image data out of a .mpg file using the OpenCV Python wrapper.
After installing the following:
sudo apt-get install
OpenCV was able to to read the .mpg file form the “CaputreFromFile” function.
I then grabbed the frame with “QueryFrame” which returned an iplImage object which has useful information such as width, height and nChannels among other things.
The raw pixel data can be retrieved by calling Get2D and passing in the image and the [x,y] coordinates, which retrieves a pixel. The pixel is an array of 3 (nChannels) different integers which can be accessed like so: pixel pixel pixel.
After all that here is the code:
#!/usr/bin/env python import cv2.cv as cv import sys files = sys.argv[1:] for f in files: print f capture = cv.CaptureFromFile(f) frame = cv.QueryFrame(capture) width = frame.width height = frame.height #just get the first 10 frame for brevity for i in xrange(10): frame = cv.QueryFrame(capture) if frame: cloned_frame = cv.CloneImage(frame) print "pixel BGR" for i in range(0, int(height)): for j in range(0, int(width)): pixel = cv.Get2D(frame, i, j)
#in the order: Blue Green Red print repr(pixel) + ", " + repr(pixel) + ", " + repr(pixel)
It prints out all the pixel values, which does take quite some time, but isn’t necessary for any other reason but demonstration.