简体   繁体   English

在python中使用pyglet从视频进行运动计算

[英]motion computation from video using pyglet in python

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). 我正在编写一个简单的运动检测程序,但是我希望它是跨平台的,因此即时通讯使用python和pyglet库,因为它提供了一种简单的方式来加载不同格式(特别是wmv和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. 现在我需要:1)在时间t和t-1处抓取帧2)进行减法运算以查看哪些像素在运动检测中处于活动状态。

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? 关于如何获取帧和跳过帧的任何想法,是否有可能将像素值放入numpy或直接从pyglet生成的矩阵中? or should look into using something other than pyglet? 还是应该考虑使用除pyglet以外的其他东西?

thanks kuaywai 谢谢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()  

To me it seems like you have to skip the play function and manually step through the video/animation, maybe using source.get_animation().frames which is a list of frames where each frame is a simple image. 在我看来,您似乎必须跳过播放功能,并手动浏览视频/动画,也许使用source.get_animation()。frames,这是一帧帧,其中每一帧都是一个简单的图像。 I'm guessing this isn't really going to be pracitical with large videos but that is generally not something you should be handling in Python anyway. 我猜想这对于大型视频来说并不会太实用,但这通常不是您应该在Python中处理的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM