I am writing a simple motion detection program but i want it to be cross platform so im using python and the pyglet library since it provides a simple way to load videos in different formats (specially wmv and mpeg). So far i have the code given below which loads the movie and plays it in a window. Now i need to: 1) grab frame at time t and t-1 2) do a subtraction to see which pixels are active for motion detection.
any ideas on how to grab frames and to skip over frames and is it possible to put the pixel values into a matrix in numpy or something directly from pyglet? or should look into using something other than pyglet?
thanks kuaywai
import pyglet
import sys
window = pyglet.window.Window(resizable=True)
window.set_minimum_size(320,200)
window.set_caption( Motion detect 1.0 )
video_intro = pyglet.resource.media( movie1.wmv )
player = pyglet.media.Player()
player.queue(video_intro)
print calculating movie size...
if not player.source or not player.source.video_format:
sys.exit
myWidth = player.source.video_format.width
myHeight = player.source.video_format.height
if player.source.video_format.sample_aspect > 1:
myWidth *= player.source.video_format.sample_aspect
elif player.source.video_format.sample_aspect < 1:
myHeight /= player.source.video_format.sample_aspect
print its size is %d,%d % (myWidth,myHeight)
player.play()
@window.event
def on_draw():
window.clear()
(w,h) = window.get_size()
player.get_texture().blit(0, h-myHeight,
width=myWidth,
height=myHeight)
pyglet.app.run()