def process_movie(MOVIE_ID, movie_info=None, dataset=None): if movie_info is None: filename = '/home/floris/data/windtunnel/SA1/movie_info' fname = (filename) fd = open( fname, mode='r' ) movie_info = pickle.load(fd) fd.close() movie_filename = movie_info[MOVIE_ID]['Path'] + MOVIE_ID + '.avi' print 'loading: ', movie_filename movie = pm.Movie(movie_filename) npmovie = pm.npMovie() npmovie.objid = movie_info[MOVIE_ID]['Obj_ID'] npmovie.epochtime = movie_info[MOVIE_ID]['EpochTime'] npmovie.filename = MOVIE_ID npmovie.id = MOVIE_ID npmovie.behavior = movie_info[MOVIE_ID]['Behavior'] npmovie.path = movie_info[MOVIE_ID]['Path'] npmovie.posttype = movie_info[MOVIE_ID]['PostType'] npmovie.extras = movie_info[MOVIE_ID]['Extras'] npmovie.trigger_stamp = movie_info[MOVIE_ID]['Trigger Stamp'] npmovie.timestamps = movie_info[MOVIE_ID]['Timestamps'] # make a mask mask = np.ones([movie.height, movie.width]) mask[0:movie.height-movie.width, :] = 0 movie.mask = mask # make a tracking mask -- 0 where no tracking desired tracking_mask = np.abs(nim.plot_circle(1024,1024,[512,512], 150)-1) npmovie.tracking_mask = tracking_mask npmovie.calc_background(movie) npmovie.load_frames(movie, timerange=None) npmovie.fps = 5000. npmovie.obj = pm.Object(npmovie) pm.auto_adjust_uimg(npmovie) pm.segment_fly(npmovie) frames = smp.get_active_frames(npmovie) if len(frames) < 5: del(movie) return npmovie pm.calc_obj_pos(npmovie) pm.calc_obj_motion(npmovie) pm.smooth_legs(npmovie) pm.calc_polarpos(npmovie) pm.smooth_axis_ratio(npmovie) trajec, time_err = sa1a.get_flydra_trajectory(npmovie, dataset) print 'trajectory in process_movie: ', trajec npmovie.trajec = copy.copy(trajec) clas.calc_fly_coordinates(npmovie) smp.calc_frame_of_landing(npmovie) if trajec is not None: smp.sync_2d_3d_data(npmovie) if len(npmovie.sync2d3d.frames3d) > 2: smp.calc_body_orientations(npmovie) smp.calc_smoothyaw(npmovie, plot=False) else: npmovie.sync2d3d = None npmovie.cluster = None #strobe_img = pm.strobe_image(movie) #movie_info[MOVIE_ID].setdefault('StrobeImg', strobe_img) #npmovie_filename = '/home/floris/data/windtunnel/SA1/sa1_npmovie_' + MOVIE_ID #pm.save(npmovie, npmovie_filename) del(movie) return npmovie
self.uframes[i].flydraframe = self.uframes[i-1].flydraframe uframe.indices = None if __name__ == '__main__': filename = '/media/SA1_movies_2/sa1_movies/20101028_C001H001S0008.avi' movie = Movie(filename) npmovie = npMovie() # make a mask mask = np.ones([movie.height, movie.width]) mask[0:movie.height-movie.width, :] = 0 movie.mask = mask # make a tracking mask -- 0 where no tracking desired tracking_mask = np.abs(nim.plot_circle(1024,1024,[512,512], 150)-1) npmovie.tracking_mask = tracking_mask npmovie.calc_background(movie) npmovie.load_frames(movie) npmovie.obj = Object(npmovie) calc_obj_pos(npmovie) calc_obj_motion(npmovie, 5000.) save(npmovie, 'sa1_movie_obj_flyby_20101028_C001H001S0008')
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