示例#1
0
 def __init__(self, filename):
     try:
         self.video = pgm.PGMReader(filename)
     except:
         traceback.print_exc()
     else:
         self.filename = filename
         self.init_video(self)
示例#2
0
 def __init__(self, pgmfile):
     try:
         self.video = pgm.PGMReader(pgmfile)
     except:
         traceback.print_exc()
     else:
         self.pgmfile = pgmfile
         self.init_video()
示例#3
0
def process_pgm(filename, n):
    import matplotlib.pyplot as plt
    video = pgm.PGMReader(filename)
    fig = plt.figure(1)
    plt.clf()
    nth = np.int(np.floor(video.length / n))
    for i, frame_no in enumerate(range(0, video.length, nth), 1):
        video.seek_frame(frame_no)
        ax = fig.add_subplot(n, 1, i)
        ix = video.img_buffer < 50
        video.img_buffer[ix] = 255
        if i == 1:
            plt.title('Frame=%d W=%d H=%d' %
                      (video.length, video.width, video.height))
        plt.title('Frame' + str(i))
    ax.set_axis_off()
    plt.show()
    return i
示例#4
0
 def __init__(self, pgmfile=None, **kwargs):
     super(VideoFile, self).__init__(**kwargs)
     self.video = None
     self.width = 50
     self.height = 50
     self.length = 10
     self.img_buffer = None
     self.frame_no = 0
     try:
         if pgmfile:
             self.video = pgm.PGMReader(pgmfile)
             self.width = self.video.width
             self.height = self.video.height
             self.length = self.video.length
             self.img_buffer = self.video.img_buffer
         else:
             self.img_buffer = \
             np.uint8(np.random.rand(self.height,self.width)*255)
     except:
         traceback.print_exc()
示例#5
0
def showpgm(pgmfile, n):
    import matplotlib.pyplot as plt

    video = pgm.PGMReader(pgmfile)

    fig = plt.figure(1)
    plt.clf()

    nth = np.int(np.floor(video.length / n))

    for i, frame_no in enumerate(range(0, video.length, nth), 1):
        video.seek_frame(frame_no)

        ax = fig.add_subplot(n, 1, i)
        ax.imshow(video.img_buffer, cmap='gray')
        if i == 1:
            plt.title("Frames=%d Width=%d Height=%d" %
                      (video.length, video.width, video.height))
        ax.set_axis_off()

    plt.show()
    return i
示例#6
0
 def test_1(self):
     video = pgm.PGMReader('sakkade.pgm')
     self.assertEqual(3, process_pgm('sakkade.pgm', 3))
示例#7
0
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 29 11:36:36 2019

@author: shir-
"""

import pgm
import matplotlib.pyplot as plt
from scipy import ndimage
import numpy as np

pgmfile = "p00001s001e016c001t001.pgm"

video = pgm.PGMReader(pgmfile)
frames = video[0::1]

co_y = np.arange(0, video.height, 1)
co_x = np.arange(0, video.width, 1)
com = np.full((2,video.length), np.nan, dtype=float) 

doplot = False
if doplot:
    fig = plt.figure(figsize=(10,5))
    
for i, frame in enumerate(frames):
    img = frame['data']
    img[100:-1,0:25] = 100
    #img1 = ndimage.median_filter(img, 1)
    #img1 = ndimage.uniform_filter(img, 3)
    img1 = ndimage.gaussian_filter(img, sigma=1)