示例#1
0
def poker_to_es(filepath_in, filepath_out, verbose=False):
    """ Converts a file from the POKER-DVS dataset into the .es format with dimensions 35x35"""

    if filepath_in.split('.')[1] == 'dat':

        # create the output directory if it doesn't exist
        basepath_out = os.path.dirname(filepath_out)
        if not os.path.exists(basepath_out):
            os.makedirs(basepath_out)

        # read file
        data = loris.read_file(filepath_in)

        # parse data according to the POKER-DVS specs
        data['width'] = 35
        data['height'] = 35

        for event in data['events']:
            event[2] = 239 - event[2]

        # write to es
        loris.write_events_to_file(data, filepath_out)
    else:
        if verbose:
            print(filepath_in, "is not an accepted file")
示例#2
0
 def test_write_es_generic(self):
     parsed_file = loris.read_file(examples_path_es + 'generic.es')
     new_file = 'new_generic.es'
     loris.write_events_to_file(parsed_file, new_file)
     self.assertEqual(os.path.getsize(new_file),
                      os.path.getsize(examples_path_es + 'generic.es'))
     os.remove(new_file)
示例#3
0
 def test_write_es_atis(self):
     file_atis = loris.read_file(examples_path_es + 'atis.es')
     new_file = 'new_atis.es'
     loris.write_events_to_file(file_atis, new_file)
     self.assertEqual(os.path.getsize(new_file),
                      os.path.getsize(examples_path_es + 'atis.es'))
     os.remove(new_file)
示例#4
0
def nmnist_to_es(filepath_in, filepath_out, verbose=False):
    """ Converts a file from the N-MNIST dataset into the .es format with dimensions 34x34"""

    if filepath_in.split('.')[1] == 'bin':

        # create the output directory if it doesn't exist
        basepath_out = os.path.dirname(filepath_out)
        if not os.path.exists(basepath_out):
            os.makedirs(basepath_out)

        # read file
        events = read_bin(filepath_in)

        # build the dictionary for .es compatibility
        data = {'type': 'dvs', 'width': 34, 'height': 34, 'events': events}

        # write to es
        loris.write_events_to_file(data, filepath_out)
    else:
        if verbose:
            print(filepath_in, "is not an accepted file")
示例#5
0
def ncar_to_es(filepath_in, filepath_out, verbose=False):
    if filepath_in.split('.')[1] == 'dat':
        # create the output directory if it doesn't exist
        basepath_out = os.path.dirname(filepath_out)
        if not os.path.exists(basepath_out):
            os.makedirs(basepath_out)

        # read file
        data = loris.read_file(filepath_in)

        # parse data according to the N-CAR specs
        data['width'] = 64
        data['height'] = 56

        for event in data['events']:
            event[2] = 55 - event[2]

        # write to es
        loris.write_events_to_file(data, filepath_out)

    else:
        if verbose:
            print(filepath_in, "is not an accepted file")
示例#6
0
def gesture_to_es(filepath_in, filepath_out, verbose=False):
    """ Converts a file from the DVS128 GESTURE dataset into the .es format with dimensions 128x128"""

    if filepath_in.split('.')[1] == 'aedat':

        # create the output directory if it doesn't exist
        basepath_out = os.path.dirname(filepath_out)
        if not os.path.exists(basepath_out):
            os.makedirs(basepath_out)

        # read file
        events = read_aedat(filepath_in)

        for event in events:
            event[2] = 127 - event[2]

        # build the dictionary for .es compatibility
        data = {'type': 'dvs', 'width': 128, 'height': 128, 'events': events}

        # write to es
        loris.write_events_to_file(data, filepath_out)
    else:
        if verbose:
            print(filepath_in, "is not an accepted file")
示例#7
0
 def test_write_dvs_from_event_array_xytp(self):
     new_file = 'new_dvs.es'
     loris.write_events_to_file(self.event_array_xytp, new_file,
                                self.ordering_xytp)
     parsed_file = loris.read_file(new_file)
     self.assertEqual(len(parsed_file['events']), 10000)
示例#8
0
 def test_write_dvs_from_event_array_txyp_without_ordering(self):
     new_file = 'new_dvs.es'
     loris.write_events_to_file(self.event_array_txyp, new_file)
     parsed_file = loris.read_file(new_file)
     self.assertEqual(len(parsed_file['events']), 10000)
示例#9
0
import argparse
import loris

parser = argparse.ArgumentParser(
    description=
    'Fix tcommon issues in recorded files, and mnormalize the timestamps')
parser.add_argument('input', type=str, help='the input .es file')
parser.add_argument('output', type=str, help='the output .es file')
arguments = parser.parse_args()

if arguments.input == arguments.output:
    raise Exception('the input and output files must be different')

stream = loris.read_file(arguments.input)
if len(stream['events']) > 0:
    previous_t = stream['events'][0][0]
    for index in range(1, 1000):
        t = stream['events'][index][0]
        if t - previous_t > 1000000:
            stream['events'] = stream['events'][index:]
            break
        previous_t = t
    stream['events']['ts'] -= stream['events'][0][0]
loris.write_events_to_file(stream, arguments.output)