def pytestcase_iterator_float_init(tmpdir, dataset_dir): """Tests initialization with float values !""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") # WHEN mv_iterator = EventsIterator(filename, start_ts=0, delta_t=1e4, max_duration=2E4, relative_timestamps=True) # THEN for _ in mv_iterator: pass # WHEN mv_iterator = EventsIterator(filename, start_ts=0, mode="n_events", n_events=10., max_duration=2E4, relative_timestamps=True) # THEN for _ in mv_iterator: pass
def pytestcase_iterator_init(tmpdir, dataset_dir): """Tests initialization of all member variables after creation of RawReader object from a file""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=0, delta_t=10000, max_duration=1e7, relative_timestamps=True) # WHEN height, width = mv_iterator.get_size() # THEN assert width == 640 assert height == 480
def main(): """ Main """ args = parse_args() # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1e3) global_counter = 0 # This will track how many events we processed global_max_t = 0 # This will track the highest timestamp we processed # Process events for evs in mv_iterator: print("----- New event buffer! -----") if evs.size == 0: print("The current event buffer is empty.") else: min_t = evs['t'][0] # Get the timestamp of the first event of this callback max_t = evs['t'][-1] # Get the timestamp of the last event of this callback global_max_t = max_t # Events are ordered by timestamp, so the current last event has the highest timestamp counter = evs.size # Local counter global_counter += counter # Increase global counter print(f"There were {counter} events in this event buffer.") print(f"There were {global_counter} total events up to now.") print(f"The current event buffer included events from {min_t} to {max_t} microseconds.") print("----- End of the event buffer! -----") # Print the global statistics duration_seconds = global_max_t / 1.0e6 print(f"There were {global_counter} events in total.") print(f"The total duration was {duration_seconds:.2f} seconds.") if duration_seconds >= 1: # No need to print this statistics if the video was too short print(f"There were {global_counter / duration_seconds :.2f} events per second on average.")
def main(): """ Main """ args = parse_args() # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1e3) for evs in mv_iterator: print("Camera is running!")
def main(): """ Main """ args = parse_args() # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1e3) height, width = mv_iterator.get_size() # Camera Geometry # Helper iterator to emulate realtime if not is_live_camera(args.input_path): mv_iterator = LiveReplayEventsIterator(mv_iterator) # Window - Graphical User Interface with MTWindow(title="Metavision Events Viewer", width=width, height=height, mode=BaseWindow.RenderMode.BGR) as window: def keyboard_cb(key, scancode, action, mods): if key == UIKeyEvent.KEY_ESCAPE or key == UIKeyEvent.KEY_Q: window.set_close_flag() window.set_keyboard_callback(keyboard_cb) # Event Frame Generator event_frame_gen = PeriodicFrameGenerationAlgorithm( sensor_width=width, sensor_height=height, fps=25) def on_cd_frame_cb(ts, cd_frame): window.show_async(cd_frame) event_frame_gen.set_output_callback(on_cd_frame_cb) # Process events for evs in mv_iterator: # Dispatch system events to the window EventLoop.poll_and_dispatch() event_frame_gen.process_events(evs) if window.should_close(): break
def pytestcase_iterator_large_shared_pointer_nb(tmpdir, dataset_dir): """Ensures that using a large number of sharedpointers is possible """ # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=0, delta_t=500, relative_timestamps=False) # WHEN & THEN evs = [ev for ev in mv_iterator]
def pytestcase_iterator_n_event_correctness(tmpdir, dataset_dir): """Ensures that events indeed come into slice of n events""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=0, mode="n_events", n_events=10000, max_duration=1e6, relative_timestamps=False) # WHEN for i, ev in enumerate(mv_iterator): # THEN assert ev.size == 10000 or i == 8
def main(): """ Main """ args = parse_args() if not os.path.isfile(args.input_path): print('Fail to access RAW file ' + args.input_path) return # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1e3) with open('cd.csv', 'w') as csv_file: # Read formatted CD events from EventsIterator & write to CSV for evs in mv_iterator: for (x, y, p, t) in evs: csv_file.write("%d,%d,%d,%d\n" % (x, y, p, t))
def pytestcase_rawiterator_dont_do_time_shifting(tmpdir, dataset_dir): """Tests that you can pass an argument to the RawReader ctor""" # GIVEN timeslice = 100000 filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=0, delta_t=timeslice, max_duration=1e6, relative_timestamps=False, do_time_shifting=False) # WHEN current_time = 0 for evs in mv_iterator: current_time += 1 # THEN assert current_time == 10
def pytestcase_rawiterator_max_duration_not_round(tmpdir, dataset_dir): """Tests max_duration parameter effect with a not round value""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") delta_t = 100000 max_duration = 120000 mv_iterator = EventsIterator(filename, start_ts=0, delta_t=delta_t, max_duration=max_duration, relative_timestamps=False) # WHEN counter = 0 for evs in mv_iterator: counter += 1 # THEN assert counter == int(math.ceil(float(max_duration) / delta_t)) assert evs[-1]['t'] < max_duration
def pytestcase_rawiterator_absolute_timestamps(tmpdir, dataset_dir): """Tests that the timestamp are increasing from slice to slice""" # GIVEN timeslice = 100000 filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=0, delta_t=timeslice, max_duration=1e6, relative_timestamps=False) # WHEN & THEN current_time = 0 for evs in mv_iterator: # with absolute timestamp event timestamps are increasing. if evs.size: assert evs['t'][0] >= current_time # abs current_time += timeslice if evs.size: assert evs['t'][-1] < current_time # absolute
def pytestcase_iterator_run_twice(tmpdir, dataset_dir): """Ensures the equivalence between two consecutive runs of the iterator""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=1e5, delta_t=200000, max_duration=1e6) # WHEN evs = [ev for ev in mv_iterator] evs2 = [ev for ev in mv_iterator] # THEN assert len(evs) == len(evs2) for ev, ev2 in zip(evs, evs2): assert all([ np.allclose(ev2[name], ev[name]) for name in ("t", "x", "y", "p") ])
def pytestcase_rawiterator_max_duration(tmpdir, dataset_dir): """Tests max_duration parameter effect""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") delta_t = 100000 for max_duration in (10000, 100000, 400000): mv_iterator = EventsIterator(filename, start_ts=0, delta_t=delta_t, max_duration=max_duration, relative_timestamps=True) # WHEN counter = 0 for evs in mv_iterator: # relative timestamps is True so all timestamp should be less than delta t if evs.size: assert evs['t'][-1] < delta_t # relative counter += 1 # THEN assert counter == int(math.ceil(float(max_duration) / delta_t))
def pytestcase_iterator_equivalence(tmpdir, dataset_dir): """Ensures the equivalence of events coming from a RAW file and its RAW to DAT equivalent""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") mv_iterator = EventsIterator(filename, start_ts=0, delta_t=2000000, max_duration=1e6, relative_timestamps=False) # WHEN evs = np.concatenate([ev for ev in mv_iterator]) dat_evs = load_events(filename.replace(".raw", "_td.dat")) dat_evs = dat_evs[dat_evs['t'] < 1e6] # THEN assert len(dat_evs) == len(evs) assert all([ np.allclose(dat_evs[name], evs[name]) for name in ("t", "x", "y", "p") ])
def pytestcase_rawiterator_start_ts(tmpdir, dataset_dir): """Tests start ts parameter effect""" # GIVEN filename = os.path.join(dataset_dir, "metavision_core", "event_io", "recording.raw") max_duration = 100000 start_ts = 230000 delta_t = 100000 mv_iterator = EventsIterator(filename, start_ts=start_ts, delta_t=delta_t, max_duration=max_duration, relative_timestamps=True) # WHEN counter = 0 for evs in mv_iterator: assert mv_iterator.reader.current_time >= start_ts # relative timestamps is True so all timestamp should be less than delta t if evs.size: assert evs['t'][-1] < delta_t # relative counter += 1 # THEN assert counter == int(math.ceil(max_duration / delta_t))
def events_publisher(): # ros init pub = rospy.Publisher('events', numpy_msg(Floats)) rospy.init_node('events_publisher', anonymous=True) r = rospy.Rate(10) # events init # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path="", delta_t=1e3) height, width = mv_iterator.get_size() # Camera Geometry print(height, width) # while not rospy.is_shutdown(): # print(height,width) # a = numpy.array([1.0,2.1,3.2,4.3,5.4,6.5],dtype=numpy.float32) # pub.publish(a) # r.sleep() # count = 0 # for evs in mv_iterator: # # print(type(evs)) # # ei = evs[0] # # print(ei) # # print(type(evs)) # count += 1 # print(count) # # print(evs) # # a = numpy.array(evs,dtype=numpy.float32) # # a = numpy.array([1.0],dtype=numpy.float32) # pub.publish(evs) # r.sleep() # # exit(0) with Window(title="Metavision SDK Get Started", width=width, height=height, mode=BaseWindow.RenderMode.BGR) as window: def keyboard_cb(key, scancode, action, mods): if action != UIAction.RELEASE: return if key == UIKeyEvent.KEY_ESCAPE or key == UIKeyEvent.KEY_Q: window.set_close_flag() window.set_keyboard_callback(keyboard_cb) # Event Frame Generator event_frame_gen = PeriodicFrameGenerationAlgorithm(width, height, accumulation_time_us) def on_cd_frame_cb(ts, cd_frame): window.show(cd_frame) event_frame_gen.set_output_callback(on_cd_frame_cb) # Process events for evs in mv_iterator: # print(evs) # Dispatch system events to the window EventLoop.poll_and_dispatch() event_frame_gen.process_events(evs) pub.publish(evs) # a = numpy.array([1.0,2.1,3.2,4.3,5.4,6.5],dtype=numpy.float32) # pub.publish(a) if window.should_close(): break
def main(): """ Main """ args = parse_args() print( "Code sample showing how to create a simple application to filter and display events." ) print("Available keyboard options:\n" " - R: Toggle the ROI filter algorithm\n" " - P: Show only events of positive polarity\n" " - N: Show only events of negative polarity\n" " - A: Show all events\n" " - Q/Escape: Quit the application\n") # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1e3) if args.replay_factor > 0 and not is_live_camera(args.input_path): mv_iterator = LiveReplayEventsIterator( mv_iterator, replay_factor=args.replay_factor) height, width = mv_iterator.get_size() # Camera Geometry polarity_filters = { Polarity.OFF: PolarityFilterAlgorithm(0), Polarity.ON: PolarityFilterAlgorithm(1) } roi_filter = RoiFilterAlgorithm(x0=roi_crop_width, y0=roi_crop_width, x1=width - roi_crop_width, y1=height - roi_crop_width) events_buf = RoiFilterAlgorithm.get_empty_output_buffer() use_roi_filter = False polarity = Polarity.ALL # Event Frame Generator event_frame_gen = PeriodicFrameGenerationAlgorithm( width, height, accumulation_time_us=10000) # Window - Graphical User Interface (Display filtered events and process keyboard events) with MTWindow(title="Metavision Filtering", width=width, height=height, mode=BaseWindow.RenderMode.BGR) as window: def on_cd_frame_cb(ts, cd_frame): # Dispatch system events to the window EventLoop.poll_and_dispatch() window.show_async(cd_frame) event_frame_gen.set_output_callback(on_cd_frame_cb) def keyboard_cb(key, scancode, action, mods): nonlocal use_roi_filter nonlocal polarity if action != UIAction.RELEASE: return if key == UIKeyEvent.KEY_ESCAPE or key == UIKeyEvent.KEY_Q: window.set_close_flag() elif key == UIKeyEvent.KEY_A: # Show all events polarity = Polarity.ALL elif key == UIKeyEvent.KEY_N: # Show only negative events polarity = Polarity.OFF elif key == UIKeyEvent.KEY_P: # Show only positive events polarity = Polarity.ON elif key == UIKeyEvent.KEY_R: # Toggle ROI filter use_roi_filter = not use_roi_filter window.set_keyboard_callback(keyboard_cb) # Process events for evs in mv_iterator: if use_roi_filter: roi_filter.process_events(evs, events_buf) if polarity in polarity_filters: polarity_filters[polarity].process_events_(events_buf) event_frame_gen.process_events(events_buf) elif polarity in polarity_filters: polarity_filters[polarity].process_events(evs, events_buf) event_frame_gen.process_events(events_buf) else: event_frame_gen.process_events(evs) if window.should_close(): break
def main(): """ Main """ args = parse_args() # Events iterator on Camera or RAW file mv_iterator = EventsIterator(input_path=args.input_path, delta_t=1e3) height, width = mv_iterator.get_size() # Camera Geometry # Window - Graphical User Interface with Window(title="Metavision SDK Get Started", width=width, height=height, mode=BaseWindow.RenderMode.BGR) as window: def keyboard_cb(key, scancode, action, mods): if action != UIAction.RELEASE: return if key == UIKeyEvent.KEY_ESCAPE or key == UIKeyEvent.KEY_Q: window.set_close_flag() window.set_keyboard_callback(keyboard_cb) # Event Frame Generator event_frame_gen = PeriodicFrameGenerationAlgorithm(width, height, accumulation_time_us) def on_cd_frame_cb(ts, cd_frame): window.show(cd_frame) event_frame_gen.set_output_callback(on_cd_frame_cb) global_counter = 0 # This will track how many events we processed global_max_t = 0 # This will track the highest timestamp we processed # Process events for evs in mv_iterator: # Dispatch system events to the window EventLoop.poll_and_dispatch() event_frame_gen.process_events(evs) print("----- New event buffer! -----") if evs.size == 0: print("The current event buffer is empty.") else: min_t = evs['t'][0] # Get the timestamp of the first event of this callback max_t = evs['t'][-1] # Get the timestamp of the last event of this callback global_max_t = max_t # Events are ordered by timestamp, so the current last event has the highest timestamp counter = evs.size # Local counter global_counter += counter # Increase global counter print(f"There were {counter} events in this event buffer.") print(f"There were {global_counter} total events up to now.") print(f"The current event buffer included events from {min_t} to {max_t} microseconds.") print("----- End of the event buffer! -----") if window.should_close(): break # Print the global statistics duration_seconds = global_max_t / 1.0e6 print(f"There were {global_counter} events in total.") print(f"The total duration was {duration_seconds:.2f} seconds.") if duration_seconds >= 1: # No need to print this statistics if the video was too short print(f"There were {global_counter / duration_seconds :.2f} events per second on average.")