def cProfile_test(movie_id):
    dataset = "square_accelerating"
    movie = dataset + "_" + str(movie_id)
    save_img_dir = os.path.join("run", "square_tracker_bounce-%i.pngvin"%(movie_id))
    if(not os.path.exists(save_img_dir)):
        os.makedirs(save_img_dir)
    video = wvideo(os.path.join("video", movie+".pngvin")) # Dimensions: x, y, rgba
    db = StateTransitionDatabase(dataset)
    
    correct_states = numpy.load(os.path.join("video", movie+".pngvin", "state_sequence.npy"))
    
    PendulumTracker(db, video).run(correct_states[0,:], 100)
    def generate_testing_movie(self, all_states):
        surfaces = [cairo.ImageSurface(cairo.FORMAT_ARGB32, IMAGE_WIDTH, IMAGE_HEIGHT) for i in xrange(len(all_states[0]))]
        contexts = [cairo.Context(surface) for surface in surfaces]
        
        for context in contexts:
            #context.scale(IMAGE_WIDTH, IMAGE_HEIGHT) # Normalize the canvas

            context.rectangle(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT)
            context.set_source_rgb(0,0,0)
            context.fill()

        for i, states in enumerate(all_states):
            for particle, context in izip(states, contexts):
                self.renderers[i].render(context, particle)
        
        return wvideo(surfaces)
Пример #3
0
import numpy
import pylab

from common import make_video_path

from wview.gwhisker import GWhiskerLayer 


#selftest
if __name__=="__main__":
    layermanager = wlayermanager()
    tries = 8

    testrange=range(-tries,tries+1)

    whisker3=wvideo(map(lambda b:
        GWhiskerLayer((float(b*(16/float(tries)))/(512**2),0,0,0),rotation=0,translate=(256.,256.)),testrange),alpha=0.3)
    whisker2=wvideo(map(lambda b:
        GWhiskerLayer((0,float(b*(16/float(tries)))/512,0,0),rotation=0,translate=(256.,256.)),testrange),alpha=0.3)
    whisker1=wvideo(map(lambda b:
        GWhiskerLayer((0,0,float(b*(16/float(tries)))/8,0),rotation=0,translate=(256.,256.)),testrange),alpha=0.3)
    zero=wvideo(map(lambda b:
        GWhiskerLayer((0,0,0,0),rotation=0.,translate=(256.,256.)),testrange),alpha=0.3)
    
    x1=numpy.array(map(lambda b:float(b*(16/float(tries)))/(512**2),testrange))
    x2=numpy.array(map(lambda b:float(b*(16/float(tries)))/512,testrange))
    x3=numpy.array(map(lambda b:float(b*(16/float(tries)))/8,testrange))
    
    
    #phi
    zerot=zero
    whisker1t=whisker1

#selftest
if __name__=="__main__":
    layermanager = wlayermanager()
    
    tries = 64*4

    testrange=range(-tries,tries+1)
    testalpha=0.3


    pos=(272.,126.)
    w=3

    whisker3=wvideo(map(lambda b:
        GWhiskerLayer((float(b*(16/float(tries)))/(512**2),0,0,0),rotation=0,width=w,translate=pos),testrange),alpha=testalpha)
    whisker2=wvideo(map(lambda b:
        GWhiskerLayer((0,float(b*(16/float(tries)))/512,0,0),rotation=0,width=w,translate=pos),testrange),alpha=testalpha)
    whisker1=wvideo(map(lambda b:
        GWhiskerLayer((0,0,float(b*(16/float(tries)))/8,0),rotation=0,width=w,translate=pos),testrange),alpha=testalpha)

    testimage=wimage("/misc/projects/whisker/video/m8_multi-frames/preprocessed_whiskers/frame-0488.png")
    zero=wvideo([testimage]*len(testrange),alpha=testalpha)
    
    x1=numpy.array(map(lambda b:float(b*(16/float(tries)))/(512**2),testrange))
    x2=numpy.array(map(lambda b:float(b*(16/float(tries)))/512,testrange))
    x3=numpy.array(map(lambda b:float(b*(16/float(tries)))/8,testrange))
    
    #phi
    zerot=zero
    whisker1t=whisker1
Пример #5
0
def filter_video(video, f=None):
    """
    @param video the video in which to filter all the frames in 
    @param f function f:img->img
    """
    return wvideo(map(lambda img: f(img.data), video))
from wmedia import wvideo,testscreen
from wimageprocessing import normalize

from scipy.ndimage import filters

import math
import numpy

from common import make_video_path, make_run_path

#selftest
if __name__=="__main__":
    layermanager = wlayermanager()
    #layermanager.add_layer(wvideo("../video/square_simple.pngvin",0.5)) #load video from file
    
    bounce=wvideo(make_video_path("square_simple.pngvin"),0.2)
    #layermanager.add_layer(bounce) 

    blur5 = lambda img: filters.gaussian_filter(img,5)

    blurbounce=bounce.transform(blur5)
 #   edge_filter=filters.prewitt
 #   abs_edge_filter=lambda img:numpy.sqrt(edge_filter(img,axis=0)**2+edge_filter(img,axis=1)**2)
 #   edgebounce=blurbounce.transform(abs_edge_filter)
    
    #badedgebounce=bounce.transform(abs_edge_filter)
    #bluredbadedgebounce=badedgebounce.transform(blur5)
    #layermanager.add_layer(bluredbadedgebounce.transform(normalize))
    
    #layermanager.add_layer(wvideo(testscreen(alpha=0.1)))