Ejemplo n.º 1
0
 def __init__(self, filename, *args,**kwargs):
     super(MoviePlayer, self).__init__(*args,**kwargs)        
     TS_VIDEO_RGB24={ 'video1':(0, -1, {'pixel_format':PixelFormats.PIX_FMT_RGB24}), 'audio1':(1,-1,{})}
     ## create the reader object
     self.mp = FFMpegReader(seek_before=0)
     ## open an audio-video file
     self.mp.open(filename,TS_VIDEO_RGB24,buf_size=4096)
Ejemplo n.º 2
0
class MoviePlayer(Process):
    def __init__(self, filename, *args,**kwargs):
        super(MoviePlayer, self).__init__(*args,**kwargs)        
        TS_VIDEO_RGB24={ 'video1':(0, -1, {'pixel_format':PixelFormats.PIX_FMT_RGB24}), 'audio1':(1,-1,{})}
        ## create the reader object
        self.mp = FFMpegReader(seek_before=0)
        ## open an audio-video file
        self.mp.open(filename,TS_VIDEO_RGB24,buf_size=4096)
            
    def get_size(self):
        tracks = self.mp.get_tracks()
        return tracks[0].get_size()
    
    def set_buffer(self, buffer_data):
        self.buffer_data = buffer_data
        
    def render_to_buffer(self, frame):
        buffer_array = np.frombuffer(self.buffer_data, 'B')
        frame = np.flipud(frame)
        frame = frame.reshape((1, -1))
        buffer_array[:] = frame
        
    def run(self):
        tracks = self.mp.get_tracks()
        tracks[0].set_observer(self.render_to_buffer)
        rate = tracks[1].get_samplerate()
        channels = tracks[1].get_channels()
        fps = tracks[0].get_fps()
        ap = AlsaSoundLazyPlayer(rate, channels, fps)
        tracks[1].set_observer(ap.push_nowait)
        self.mp.run()
    
    def seek(self, pos=0):
        if pos is not None and pos > 0:
            self.mp.seek_to_seconds(pos)
    
    def stop(self):
        self.mp.close()
        os.kill(self.pid, signal.SIGKILL)
        
Ejemplo n.º 3
0
        0] * 0.02  #We only accept vertical lines  where two edges of the laser line are close to each other
    good_points = float(numpy.sum(numpy.where(mask1, 1, 0)))
    if (good_points < 10):
        return
    good_indices = numpy.arange(maxes.shape[0])[mask1]
    good_range = good_indices[-1] - good_indices[0]
    fraction = good_points / float(good_range)  #fraction of good points
    goldenratio = 1.618
    frameno += 1
    if fraction > 0.7:
        print fraction
        extract_data(
            numpy.arange(maxes.shape[0])[mask1], maxes[mask1, 1], camera)
        scipy.misc.imsave("/tmp/saved-%03d.png" % frameno, r)
        lab.figure(frameno, figsize=(5.0 * goldenratio, 5.0))
        lab.plot(numpy.arange(0, maxes.shape[0])[mask1], maxes[mask1, 1], 'bo')
        lab.plot(numpy.arange(0, maxes.shape[0]), 20 * (1 - mask1),
                 'g+')  #mask out the ranges where maximums are bad
        lab.ylabel("Position of maximum")
        lab.savefig("/tmp/saved-%03d-plt2.png" % frameno)


mp = FFMpegReader()
print sys.argv[1]
mp.open(sys.argv[1])
tracks = mp.get_tracks()
video_track = tracks[0]
video_track.set_observer(observer)
#cProfile.run('mp.run()')
mp.run()
Ejemplo n.º 4
0
  maxes = numpy.asarray([maxesgrad(r[:,i]) for i in xrange(r.shape[1])])
  mask1 = (maxes[:,1]-maxes[:,0])<r.shape[0]*0.02 #We only accept vertical lines  where two edges of the laser line are close to each other
  good_points = float(numpy.sum(numpy.where(mask1,1,0)))
  if(good_points<10):
    return
  good_indices=numpy.arange(maxes.shape[0])[mask1]
  good_range = good_indices[-1]-good_indices[0]
  fraction = good_points/float(good_range) #fraction of good points
  goldenratio=1.618
  frameno += 1
  if fraction >0.7:
      print fraction
      extract_data(numpy.arange(maxes.shape[0])[mask1],maxes[mask1,1],camera)
      scipy.misc.imsave("/tmp/saved-%03d.png" % frameno,r)
      lab.figure(frameno,figsize=(5.0*goldenratio,5.0))
      lab.plot(numpy.arange(0,maxes.shape[0])[mask1],maxes[mask1,1],'bo')
      lab.plot(numpy.arange(0,maxes.shape[0]),20*(1-mask1),'g+') #mask out the ranges where maximums are bad
      lab.ylabel("Position of maximum")
      lab.savefig("/tmp/saved-%03d-plt2.png" % frameno)
  
  

mp = FFMpegReader()
print sys.argv[1]
mp.open(sys.argv[1])
tracks = mp.get_tracks()
video_track=tracks[0]
video_track.set_observer(observer)
#cProfile.run('mp.run()')
mp.run()