Beispiel #1
0
        wfmf.show_arena = arena
    wfmf.show_lxly = args.show_laser
    wfmf.show_fxfy = args.show_target
    wfmf.show_timestamp = args.show_timestamp
    wfmf.show_epoch = args.show_epoch

    fmfwidth = wfmf.width
    fmfheight = wfmf.height

    try:
        print 'loading w timestamps'
        wts = wfmf.fmf.get_all_timestamps()
    except AttributeError:
        wts = df['t_framenumber'].dropna().unique()

    pbar = madplot.get_progress_bar("computing frames", len(wts))

    frames = []
    for i, (wt0, wt1) in enumerate(madplot.pairwise(wts)):

        pbar.update(i)

        fdf = madplot.get_framedf(df, wt1)
        lfdf = len(fdf)

        if lfdf:
            try:
                most_recent_time = madplot.get_framedf(df, wt1).index[-1]

                minidf = df[madplot.get_framedf(df, wt0).
                            index[0]:most_recent_time]
Beispiel #2
0
                          device_y0=actual_h - PH,
                          device_y1=actual_h)

    moviemaker = madplot.MovieMaker(basename=os.path.basename(BAG_FILE))

    ass = Assembler(
        actual_w,
        actual_h,
        panels,
        wfmf,
        zfmf,
        ttlplotter,
        moviemaker,
    )

    pbar = madplot.get_progress_bar(moviemaker.movie_fname, len(frames))

    for i, desc in enumerate(frames):
        ass.render_frame(desc)
        pbar.update(i)

        if 'TEST_MOVIES' in os.environ:
            if i > 50: break

    pbar.finish()

    moviefname = moviemaker.render(
        args.outdir if args.outdir else os.path.dirname(BAG_FILE))
    print "wrote", moviefname

    moviemaker.cleanup()
Beispiel #3
0
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('path', nargs=1, help='path to fmf file')
    parser.add_argument('--fps', type=int, default=30)
    parser.add_argument('--outdir', help='destination directory for mp4')

    args = parser.parse_args()
    path = args.path[0]

    fmf = madplot.FMFImagePlotter(path, 'none')
    fmf.enable_color_correction(brightness=20, contrast=1.5)

    frames = fmf.fmf.get_all_timestamps()
    moviemaker = madplot.MovieMaker(basename=os.path.basename(path)+'_plain', fps=args.fps)
    pbar = madplot.get_progress_bar(moviemaker.movie_fname, len(frames))

    for i,ts in enumerate(frames):
        f = fmf.get_frame_number(i)
        png = moviemaker.next_frame()
        cv2.imwrite(png, f)
        pbar.update(i)

        if 'TEST_MOVIES' in os.environ:
            if i > 50: break

    pbar.finish()

    moviefname = moviemaker.render(args.outdir if args.outdir else os.path.dirname(path))
    print "wrote", moviefname
def doit_using_framenumber(user_data):
    match, mp4_dir, show_theta, show_velocity, pre_frames, post_frames = user_data

    zoomf = match.fmf
    rosbagf = match.bag
    maxt = match.maxt

    moviemaker = madplot.MovieMaker(basename=os.path.basename(zoomf), fps=15)
    target_moviefname = moviemaker.get_target_movie_name(mp4_dir)
    if os.path.exists(target_moviefname):
        print 'target %r exists: skipping movie'%(target_moviefname,)
        moviemaker.cleanup()
        return

    arena = madplot.Arena(False)
    zoom = madplot.FMFImagePlotter(zoomf, 'z_frame')
    zoom.enable_color_correction(brightness=15, contrast=1.5)
    wide = madplot.ArenaPlotter(arena,tzname=TZNAME)

    wide.show_theta = show_theta
    wide.show_velocity = show_velocity
    wide.show_epoch = True
    wide.show_framenumber = True
    wide.show_lxly = True
    wide.show_fxfy = True

    renderlist = []

    zoom_ts = zoom.fmf.get_all_timestamps().tolist()
    df = madplot.load_bagfile_single_dataframe(rosbagf, arena, ffill=True,
                                               tzname=TZNAME)
    t0 = df.index[0].asm8.astype(np.int64) / 1e9

    # find start and stop frames based on laser transition ----
    laser_power = df['laser_power'].values
    framenumber = df['h_framenumber'].values

    laser_power = np.array( laser_power, copy=True )
    laser_power[ np.isnan(laser_power) ] = 0

    dlaser = laser_power[1:]-laser_power[:-1]
    laser_transitions = np.nonzero(dlaser)[0]
    startframenumber = -np.inf
    stopframenumber = np.inf
    if pre_frames is None:
        assert post_frames is None
    if pre_frames is not None:
        assert post_frames is not None

        for i,idx in enumerate(laser_transitions):
            if i==0:
                startframenumber = framenumber[idx-pre_frames]
            elif i==1:
                stopframenumber = framenumber[idx+post_frames]
            else:
                print 'ERROR: unknown laser transition in %r'%zoomf
                moviemaker.cleanup()
                return

    # got start and stop frames -----

    for idx,group in df.groupby('h_framenumber'):
        # limit movies to only frames we want
        this_framenumber = group['h_framenumber'].values[0]
        if not (startframenumber <= this_framenumber and this_framenumber <= stopframenumber):
            continue

        #did we save a frame ?
        try:
            frameoffset = zoom_ts.index(idx)
        except ValueError:
            #missing frame (probbably because the video was not recorded at
            #full frame rate
            continue

        frame = madplot.FMFFrame(offset=frameoffset, timestamp=idx)
        row = group.dropna(subset=['tobj_id']).tail(1)
        if len(row):
            if maxt > 0:
                dt = (row.index[0].asm8.astype(np.int64) / 1e9) - t0
                if dt > maxt:
                    break

            desc = madplot.FrameDescriptor(
                                None,
                                frame,
                                row,
                                row.index[0].asm8.astype(np.int64) / 1e9)

            renderlist.append(desc)

    if len(renderlist)==0:
        moviemaker.cleanup()
        return

    wide.t0 = t0

    panels = {}
    #left half of screen
    panels["wide"] = wide.get_benu_panel(
            device_x0=0, device_x1=0.5*TARGET_OUT_W,
            device_y0=0, device_y1=TARGET_OUT_H
    )
    panels["zoom"] = zoom.get_benu_panel(
            device_x0=0.5*TARGET_OUT_W, device_x1=TARGET_OUT_W,
            device_y0=0, device_y1=TARGET_OUT_H
    )

    actual_w, actual_h = benu.utils.negotiate_panel_size_same_height(panels, TARGET_OUT_W)

    ass = Assembler(actual_w, actual_h,
                    panels,
                    wide,zoom,
                    moviemaker,
    )


    if not USE_MULTIPROCESSING:
        pbar = madplot.get_progress_bar(moviemaker.movie_fname, len(renderlist))

    for i,desc in enumerate(renderlist):
        ass.render_frame(desc)
        if not USE_MULTIPROCESSING:
            pbar.update(i)

    if not USE_MULTIPROCESSING:
        pbar.finish()

    if not os.path.exists(mp4_dir):
        os.makedirs(mp4_dir)

    moviefname = moviemaker.render(mp4_dir)
    print "wrote", moviefname

    moviemaker.cleanup()
def doit_using_framenumber(user_data):
    match, mdir, show_theta, show_velocity = user_data

    zoomf = match.fmf
    rosbagf = match.bag
    maxt = match.maxt

    arena = madplot.Arena(False)
    zoom = madplot.FMFImagePlotter(zoomf, 'z_frame')
    zoom.enable_color_correction(brightness=15, contrast=1.5)
    wide = madplot.ArenaPlotter(arena)

    wide.show_theta = show_theta
    wide.show_velocity = show_velocity
    wide.show_epoch = True
    wide.show_framenumber = True
    wide.show_lxly = True
    wide.show_fxfy = True

    renderlist = []

    zoom_ts = zoom.fmf.get_all_timestamps().tolist()
    df = madplot.load_bagfile_single_dataframe(rosbagf, arena, ffill=True)
    t0 = df.index[0].asm8.astype(np.int64) / 1e9

    for idx,group in df.groupby('h_framenumber'):
        #did we save a frame ?
        try:
            frameoffset = zoom_ts.index(idx)
        except ValueError:
            #missing frame (probbably because the video was not recorded at
            #full frame rate
            continue

        frame = madplot.FMFFrame(offset=frameoffset, timestamp=idx)
        row = group.dropna(subset=['tobj_id']).tail(1)
        if len(row):
            if maxt > 0:
                dt = (row.index[0].asm8.astype(np.int64) / 1e9) - t0
                if dt > maxt:
                    break

            desc = madplot.FrameDescriptor(
                                None,
                                frame,
                                row,
                                row.index[0].asm8.astype(np.int64) / 1e9)

            renderlist.append(desc)

    wide.t0 = t0

    panels = {}
    #left half of screen
    panels["wide"] = wide.get_benu_panel(
            device_x0=0, device_x1=0.5*TARGET_OUT_W,
            device_y0=0, device_y1=TARGET_OUT_H
    )
    panels["zoom"] = zoom.get_benu_panel(
            device_x0=0.5*TARGET_OUT_W, device_x1=TARGET_OUT_W,
            device_y0=0, device_y1=TARGET_OUT_H
    )

    actual_w, actual_h = benu.utils.negotiate_panel_size_same_height(panels, TARGET_OUT_W)

    moviemaker = madplot.MovieMaker(basename=os.path.basename(zoomf), fps=30)
    target_moviefname = moviemaker.get_target_movie_name(mdir)
    if os.path.exists(target_moviefname):
        print 'target %r exists: skipping movie'%(target_moviefname,)
        return

    ass = Assembler(actual_w, actual_h,
                    panels, 
                    wide,zoom,
                    moviemaker,
    )


    if not USE_MULTIPROCESSING:
        pbar = madplot.get_progress_bar(moviemaker.movie_fname, len(renderlist))

    for i,desc in enumerate(renderlist):
        ass.render_frame(desc)
        if not USE_MULTIPROCESSING:
            pbar.update(i)

    if not USE_MULTIPROCESSING:
        pbar.finish()

    if not os.path.exists(mdir):
        os.makedirs(mdir)

    moviefname = moviemaker.render(mdir)
    print "wrote", moviefname

    moviemaker.cleanup()
def doit_using_framenumber(user_data):
    match, mp4_dir, show_theta, show_velocity, pre_frames, post_frames = user_data

    zoomf = match.fmf
    rosbagf = match.bag
    maxt = match.maxt

    moviemaker = madplot.MovieMaker(basename=os.path.basename(zoomf), fps=15)
    target_moviefname = moviemaker.get_target_movie_name(mp4_dir)
    if os.path.exists(target_moviefname):
        print 'target %r exists: skipping movie' % (target_moviefname, )
        moviemaker.cleanup()
        return

    arena = madplot.Arena(False)
    zoom = madplot.FMFImagePlotter(zoomf, 'z_frame')
    zoom.enable_color_correction(brightness=15, contrast=1.5)
    wide = madplot.ArenaPlotter(arena, tzname=TZNAME)

    wide.show_theta = show_theta
    wide.show_velocity = show_velocity
    wide.show_epoch = True
    wide.show_framenumber = True
    wide.show_lxly = True
    wide.show_fxfy = True

    renderlist = []

    zoom_ts = zoom.fmf.get_all_timestamps().tolist()
    df = madplot.load_bagfile_single_dataframe(rosbagf,
                                               arena,
                                               ffill=True,
                                               tzname=TZNAME)
    t0 = df.index[0].asm8.astype(np.int64) / 1e9

    # find start and stop frames based on laser transition ----
    laser_power = df['laser_power'].values
    framenumber = df['h_framenumber'].values

    laser_power = np.array(laser_power, copy=True)
    laser_power[np.isnan(laser_power)] = 0

    dlaser = laser_power[1:] - laser_power[:-1]
    laser_transitions = np.nonzero(dlaser)[0]
    startframenumber = -np.inf
    stopframenumber = np.inf
    if pre_frames is None:
        assert post_frames is None
    if pre_frames is not None:
        assert post_frames is not None

        for i, idx in enumerate(laser_transitions):
            if i == 0:
                startframenumber = framenumber[idx - pre_frames]
            elif i == 1:
                stopframenumber = framenumber[idx + post_frames]
            else:
                print 'ERROR: unknown laser transition in %r' % zoomf
                moviemaker.cleanup()
                return

    # got start and stop frames -----

    for idx, group in df.groupby('h_framenumber'):
        # limit movies to only frames we want
        this_framenumber = group['h_framenumber'].values[0]
        if not (startframenumber <= this_framenumber
                and this_framenumber <= stopframenumber):
            continue

        #did we save a frame ?
        try:
            frameoffset = zoom_ts.index(idx)
        except ValueError:
            #missing frame (probbably because the video was not recorded at
            #full frame rate
            continue

        frame = madplot.FMFFrame(offset=frameoffset, timestamp=idx)
        row = group.dropna(subset=['tobj_id']).tail(1)
        if len(row):
            if maxt > 0:
                dt = (row.index[0].asm8.astype(np.int64) / 1e9) - t0
                if dt > maxt:
                    break

            desc = madplot.FrameDescriptor(
                None, frame, row, row.index[0].asm8.astype(np.int64) / 1e9)

            renderlist.append(desc)

    if len(renderlist) == 0:
        moviemaker.cleanup()
        return

    wide.t0 = t0

    panels = {}
    #left half of screen
    panels["wide"] = wide.get_benu_panel(device_x0=0,
                                         device_x1=0.5 * TARGET_OUT_W,
                                         device_y0=0,
                                         device_y1=TARGET_OUT_H)
    panels["zoom"] = zoom.get_benu_panel(device_x0=0.5 * TARGET_OUT_W,
                                         device_x1=TARGET_OUT_W,
                                         device_y0=0,
                                         device_y1=TARGET_OUT_H)

    actual_w, actual_h = benu.utils.negotiate_panel_size_same_height(
        panels, TARGET_OUT_W)

    ass = Assembler(
        actual_w,
        actual_h,
        panels,
        wide,
        zoom,
        moviemaker,
    )

    if not USE_MULTIPROCESSING:
        pbar = madplot.get_progress_bar(moviemaker.movie_fname,
                                        len(renderlist))

    for i, desc in enumerate(renderlist):
        ass.render_frame(desc)
        if not USE_MULTIPROCESSING:
            pbar.update(i)

    if not USE_MULTIPROCESSING:
        pbar.finish()

    if not os.path.exists(mp4_dir):
        os.makedirs(mp4_dir)

    moviefname = moviemaker.render(mp4_dir)
    print "wrote", moviefname

    moviemaker.cleanup()
def doit_using_framenumber(user_data):
    match, mdir, show_theta, show_velocity = user_data

    zoomf = match.fmf
    rosbagf = match.bag
    maxt = match.maxt

    arena = madplot.Arena(False)
    zoom = madplot.FMFImagePlotter(zoomf, 'z_frame')
    zoom.enable_color_correction(brightness=15, contrast=1.5)
    wide = madplot.ArenaPlotter(arena)

    wide.show_theta = show_theta
    wide.show_velocity = show_velocity
    wide.show_epoch = True
    wide.show_framenumber = True
    wide.show_lxly = True
    wide.show_fxfy = True

    renderlist = []

    zoom_ts = zoom.fmf.get_all_timestamps().tolist()
    df = madplot.load_bagfile_single_dataframe(rosbagf, arena, ffill=True)
    t0 = df.index[0].asm8.astype(np.int64) / 1e9

    for idx, group in df.groupby('h_framenumber'):
        #did we save a frame ?
        try:
            frameoffset = zoom_ts.index(idx)
        except ValueError:
            #missing frame (probbably because the video was not recorded at
            #full frame rate
            continue

        frame = madplot.FMFFrame(offset=frameoffset, timestamp=idx)
        row = group.dropna(subset=['tobj_id']).tail(1)
        if len(row):
            if maxt > 0:
                dt = (row.index[0].asm8.astype(np.int64) / 1e9) - t0
                if dt > maxt:
                    break

            desc = madplot.FrameDescriptor(
                None, frame, row, row.index[0].asm8.astype(np.int64) / 1e9)

            renderlist.append(desc)

    wide.t0 = t0

    panels = {}
    #left half of screen
    panels["wide"] = wide.get_benu_panel(device_x0=0,
                                         device_x1=0.5 * TARGET_OUT_W,
                                         device_y0=0,
                                         device_y1=TARGET_OUT_H)
    panels["zoom"] = zoom.get_benu_panel(device_x0=0.5 * TARGET_OUT_W,
                                         device_x1=TARGET_OUT_W,
                                         device_y0=0,
                                         device_y1=TARGET_OUT_H)

    actual_w, actual_h = benu.utils.negotiate_panel_size_same_height(
        panels, TARGET_OUT_W)

    moviemaker = madplot.MovieMaker(basename=os.path.basename(zoomf), fps=30)
    target_moviefname = moviemaker.get_target_movie_name(mdir)
    if os.path.exists(target_moviefname):
        print 'target %r exists: skipping movie' % (target_moviefname, )
        return

    ass = Assembler(
        actual_w,
        actual_h,
        panels,
        wide,
        zoom,
        moviemaker,
    )

    if not USE_MULTIPROCESSING:
        pbar = madplot.get_progress_bar(moviemaker.movie_fname,
                                        len(renderlist))

    for i, desc in enumerate(renderlist):
        ass.render_frame(desc)
        if not USE_MULTIPROCESSING:
            pbar.update(i)

    if not USE_MULTIPROCESSING:
        pbar.finish()

    if not os.path.exists(mdir):
        os.makedirs(mdir)

    moviefname = moviemaker.render(mdir)
    print "wrote", moviefname

    moviemaker.cleanup()