Пример #1
0
def reprocess_uframes(movieinfo):
    print movieinfo.id
    
    framerange = movieinfo.framenumbers
    print framerange[0], framerange[-1]
    
    nframes = len(framerange)
    
    movieinfo.obj_centers = np.zeros([nframes, 2])
    movieinfo.obj_longaxis = np.zeros([nframes, 2])
    movieinfo.obj_shortaxis = np.zeros([nframes, 2])
    movieinfo.obj_ratio = np.zeros([nframes, 2])
    
    for f, framenumber in enumerate(framerange):
        print f
        frame = movieinfo.frames[f] 
        uimg = frame.uimg
        zero = frame.zero
        
        
        ubackground = nim.extract_uimg(movieinfo.background, uimg.shape, zero)
            
        relative_center_of_body, longaxis, shortaxis, body, ratio = nim.find_ellipse(uimg, background=ubackground, threshrange=[150,254], sizerange=[10,600], dist_thresh=10, erode=False, check_centers=True)
        
        center_of_body = relative_center_of_body + zero
        #center_of_body = center
        
        movieinfo.obj_centers[f,:] = center_of_body
        movieinfo.obj_longaxis[f,:] = longaxis
        movieinfo.obj_shortaxis[f,:] = shortaxis
        movieinfo.obj_ratio[f,:] = ratio
        print ratio
Пример #2
0
def process_movie(movieinfo, framerange=None, nframes=None):

    filename = movieinfo.path + movieinfo.id + '.avi'
    movie = Movie(filename)
    
    # make a mask to remove text and such of the top part of the movie
    mask = np.ones([movie.height, movie.width])
    mask[0:movie.height-movie.width, :] = 0
    movie.mask = mask
    tracking_mask = np.abs(nim.plot_circle(1024,1024,[512,512], 150)-1)
    
    first_frame = (movie.get_frame_at_timestamp(0)[::-1, :])
    last_frame = (movie.get_frame_at_timestamp(movie.duration-1)[::-1, :])
    background = nim.lighten(first_frame, last_frame)
    movieinfo.background = copy.copy(background)
    
    if framerange is None:
        framerange = movieinfo.framenumbers
    else:
        framerange = np.arange(framerange[0], framerange[1]+1, 1).tolist()
    if nframes is not None:
        framerange = framerange[0:nframes]
    nframes = len(framerange)
    
    movieinfo.obj_centers = np.zeros([nframes, 2])
    movieinfo.obj_longaxis = np.zeros([nframes, 2])
    movieinfo.obj_shortaxis = np.zeros([nframes, 2])
    movieinfo.obj_ratio = np.zeros([nframes, 2])
    movieinfo.frames = [Frame() for frame in framerange]
    
    print 'framerange = ', framerange[0]
    for f, framenumber in enumerate(framerange):
        frame = movieinfo.frames[f]
        
        print f, framenumber
        raw = (movie.get_frame(framenumber)[::-1, :])
        
        if f < 3:
            guess = None
            guess_radius = None
        else:
            try:
                vel_est = movieinfo.obj_centers[f-1,:] - movieinfo.obj_centers[f-2,:]
                guess = movieinfo.obj_centers[f-1,:] + vel_est
                guess_radius = 35
            except:
                guess = None
                guess_radius = None
                
        
        center, uimg, zero = nim.find_object_with_background_subtraction(raw, background, mask=tracking_mask, guess=guess, guess_radius=guess_radius, sizerange=[10,600], thresh=10, uimg_roi_radius=30, return_uimg=True, return_mimg=False)
        
        print '********pygmovie********', uimg.shape, zero
        
        ubackground = nim.extract_uimg(background, uimg.shape, zero)
        
        relative_center_of_body, longaxis, shortaxis, body, ratio = nim.find_ellipse(uimg, background=ubackground, threshrange=[150,254], sizerange=[10,600], dist_thresh=10, erode=False, check_centers=True)
        
        center_of_body = relative_center_of_body + zero
        #center_of_body = center
        
        frame.uimg = copy.copy(uimg)
        #frame.mimg = mimg
        frame.zero = zero
        frame.framenumber = framenumber
        
        movieinfo.obj_centers[f,:] = copy.copy(center_of_body)
        movieinfo.obj_longaxis[f,:] = copy.copy(longaxis)
        movieinfo.obj_shortaxis[f,:] = copy.copy(shortaxis)
        movieinfo.obj_ratio[f,:] = copy.copy(ratio)
        
        del(raw)
    del(movie)
    
    return