Exemplo n.º 1
0
kwargs['output_folder'] = exportFilePathOrName
kwargs['auto_hdr'] = True
kwargs['display'] = True
kwargs['show_events'] = True
kwargs['channelName'] = 'right'

run_reconstruction(**kwargs)
pathToFrames = os.path.join(kwargs['output_folder'], 'reconstruction')

#%% Now take those frames and put them in the right place ...

#%% Import frames

from bimvee.importAe import importAe

containerFrames = importAe(filePathOrName=pathToFrames)

#%% You may like to check that the container looks correct

from bimvee.info import info

info(containerFrames)

#%%  You may like to visualise the container - Start Mustard

cwd = os.getcwd()

import threading
import mustard
app = mustard.Mustard()
thread = threading.Thread(target=app.run)
Exemplo n.º 2
0
from bimvee.importSecDvs import importSecDvs

filePathOrName = os.path.join(
    prefix, "data/2020_03_23 SecDvs from Ander/2020-03-24-12-45-13.bin")
container = importSecDvs(filePathOrName=filePathOrName)

visualizerApp.root.data_controller.data_dict = container

#%% Load some generic data

from bimvee.importAe import importAe

filePathOrName = os.path.join(
    prefix, "data/2020_03_23 SecDvs from Ander/2020-03-24-12-45-13.bin")
container = importAe(filePathOrName=filePathOrName)

visualizerApp.root.data_controller.data_dict = container

#%% Simulated DAVIS data

# This example demonstrates the use of a template to limit what data is imported,
# and therefore what data gets visualised.
# You can also create a container with just the data you want before passing
# it to the visualiser.

# http://rpg.ifi.uzh.ch/davis_data.html
from importRpgDvsRos import importRpgDvsRos

filePathOrName = os.path.join(prefix, 'data/rpg/simulation_3walls.bag')
Exemplo n.º 3
0
#%% Preliminaries

import os, sys
prefix = 'C:/' if os.name == 'nt' else '/home/sbamford/'
sys.path.insert(0, os.path.join(prefix, 'repos'))
sys.path.insert(0, os.path.join(prefix, 'repos/bimvee'))
sys.path.insert(0, os.path.join(prefix, 'repos/mustard'))

#%% Load event data

from bimvee.importAe import importAe

filePathOrName = os.path.join(prefix, 'data', '2020_06_Aiko_Checkerboard',
                              'trial08', 'StEFI')

containerEvents = importAe(filePathOrName=filePathOrName)

#%% Run reconstruction

from rpg_e2vid.run_reconstruction import run_reconstruction

exportFilePathOrName = os.path.join(
    prefix,
    'data',
    '2020_06_26_Aiko_Checkerboard',
    'trial08',
    'frames',
)

kwargs = {}
kwargs['input_file'] = filePathOrName
def run_reconstruction(**kwargs):

    parser = argparse.ArgumentParser(
        description='Evaluating a trained network')
    parser.add_argument('-c',
                        '--path_to_model',
                        type=str,
                        help='path to model weights')
    parser.add_argument('-i', '--input_file', type=str)
    parser.add_argument('--fixed_duration',
                        dest='fixed_duration',
                        action='store_true')
    parser.set_defaults(fixed_duration=False)
    parser.add_argument(
        '-N',
        '--window_size',
        default=None,
        type=int,
        help=
        "Size of each event window, in number of events. Ignored if --fixed_duration=True"
    )
    parser.add_argument(
        '-T',
        '--window_duration',
        default=33.33,
        type=float,
        help=
        "Duration of each event window, in milliseconds. Ignored if --fixed_duration=False"
    )
    parser.add_argument(
        '--num_events_per_pixel',
        default=0.35,
        type=float,
        help='in case N (window size) is not specified, it will be \
                              automatically computed as N = width * height * num_events_per_pixel'
    )
    parser.add_argument('--skipevents', default=0, type=int)
    parser.add_argument('--suboffset', default=0, type=int)
    parser.add_argument('--compute_voxel_grid_on_cpu',
                        dest='compute_voxel_grid_on_cpu',
                        action='store_true')
    parser.add_argument('--channelName', default=None, type=str)
    parser.set_defaults(compute_voxel_grid_on_cpu=False)

    set_inference_options(parser)

    args = parser.parse_args()

    argsDict = vars(args)
    argsDict.update(kwargs)

    # Load model
    model = load_model(args.path_to_model)
    device = get_device(args.use_gpu)

    model = model.to(device)
    model.eval()

    path_to_events = args.input_file

    container = importAe(filePathOrName=path_to_events, **kwargs)
    channelName = args.channelName
    if channelName is not None:
        dvs = container['data'][channelName]['dvs']
    else:  # use Container functionality to find the right channel
        containerObj = Container(container)
        dvs = containerObj.getDataType('dvs')
    width = dvs.get('dimX', np.max(dvs['x']) + 1)
    height = dvs.get('dimY', np.max(dvs['y']) + 1)

    reconstructor = ImageReconstructor(model, height, width, model.num_bins,
                                       args)
    """ Read chunks of events using Pandas """

    # Loop through the events and reconstruct images
    N = args.window_size
    if not args.fixed_duration:
        if N is None:
            N = int(width * height * args.num_events_per_pixel)
            print(
                'Will use {} events per tensor (automatically estimated with num_events_per_pixel={:0.2f}).'
                .format(N, args.num_events_per_pixel))
        else:
            print('Will use {} events per tensor (user-specified)'.format(N))
            mean_num_events_per_pixel = float(N) / float(width * height)
            if mean_num_events_per_pixel < 0.1:
                print(
                    '!!Warning!! the number of events used ({}) seems to be low compared to the sensor size. \
                    The reconstruction results might be suboptimal.'.format(N))
            elif mean_num_events_per_pixel > 1.5:
                print(
                    '!!Warning!! the number of events used ({}) seems to be high compared to the sensor size. \
                    The reconstruction results might be suboptimal.'.format(N))

    initial_offset = args.skipevents
    sub_offset = args.suboffset
    start_index = initial_offset + sub_offset

    if args.compute_voxel_grid_on_cpu:
        print('Will compute voxel grid on CPU.')

    if args.fixed_duration:
        event_window_iterator = FixedDurationEventReader(
            dvs, duration_ms=args.window_duration, start_index=start_index)
    else:
        event_window_iterator = FixedSizeEventReader(dvs,
                                                     num_events=N,
                                                     start_index=start_index)

    print('Sensor size: {} x {}'.format(width, height))

    with Timer('Processing entire dataset'):
        for event_window in event_window_iterator:

            last_timestamp = event_window[-1, 0]

            with Timer('Building event tensor'):
                if args.compute_voxel_grid_on_cpu:
                    event_tensor = events_to_voxel_grid(
                        event_window,
                        num_bins=model.num_bins,
                        width=width,
                        height=height)
                    event_tensor = torch.from_numpy(event_tensor)
                else:
                    event_tensor = events_to_voxel_grid_pytorch(
                        event_window,
                        num_bins=model.num_bins,
                        width=width,
                        height=height,
                        device=device)

            num_events_in_window = event_window.shape[0]
            reconstructor.update_reconstruction(
                event_tensor, start_index + num_events_in_window,
                last_timestamp)

            start_index += num_events_in_window
Exemplo n.º 5
0
import argparse

#### Argument Parsing ####
parser = argparse.ArgumentParser(
    description='To convert into yarp-readable data')
parser.add_argument(
    '--data',
    type=str,
    default=
    '/home/aniket/event-driven-gaze-tracking/Data/Raw_Data/out_2020-10-29_13-46-33.raw',
    help='path to the raw event-data')
args = parser.parse_args()

# import matplotlib.pyplot as plt
from bimvee.importAe import importAe
from bimvee.exportIitYarp import exportIitYarp
from bimvee.info import info

PATH = os.path.abspath(os.getcwd())

file_path = os.path.join(PATH, args.data)
outPath = os.path.join(PATH, "yarp_out")
container1 = importAe(filePathOrName=file_path, zeroTime=True)

info(container1)

exportIitYarp(container1,
              exportFilePath=os.path.join(outPath, "batch05"),
              pathForPlayback=os.path.join(outPath, "batch05"))
print('Done!')