EventsIterator can not work rightly

EventsIterator can not work rightly

Dear Community,

I am working on a project involving an event camera and have created a Python class to manage it. One of the class attributes, self.cam, is an initialized HAL device. The class includes a method, continuous_acquire_events, designed to enable real-time preview of event camera data. In this method, I create an EventsIterator to iterate over events and display them until the preview is stopped. After stopping the preview, I explicitly delete the EventsIterator using del.

Theoretically, I should be able to call this method multiple times to start a second, third, or subsequent preview sessions. However, I am encountering inconsistent behavior: sometimes the method works for multiple previews, but other times it fails on the second attempt with an error. Below, I have provided the relevant code and the error traceback.

Additionally, I have noticed that my implementation does not achieve the high real-time performance seen in the official Metavision software. The preview often experiences increasing latency over time, which affects the responsiveness of the application.

my code: 1 2, my error: sometime3 sometime4
  1. self.cam = initiate_device(path=input_path)
  2. def continuous_acquire_events(self, event_callback=None):
    """Continuously acquire events and emit frames via the events_acquired signal.

    Uses PeriodicFrameGenerationAlgorithm to generate fixed-frequency frames, emitted for UI display.

    Parameters:
    event_callback (callable, optional): Callback function to process events before frame conversion, returning a structured event array or None.

    Exceptions:
    Catches and logs all exceptions to ensure program robustness.
    """
    # try:
    # Get sensor geometry information
    if self.i_geometry is None:
    logger.error("Geometry module is not available")
    return
    height = self.i_geometry.get_height()
    width = self.i_geometry.get_width()
    # Initialize frame generation algorithm, set 10ms accumulation time, 100fps, dark color palette
    frame_gen = PeriodicFrameGenerationAlgorithm(
    sensor_width=width,
    sensor_height=height,
    accumulation_time_us=50000, # 50ms accumulation time
    fps=20.0, # 20 frames per second
    palette=ColorPalette.Dark # Use dark color palette
    )

    # Pre-allocate frame buffer (RGB, three channels)
    frame = np.zeros((height, width, 3), dtype=np.uint8)

    # Set frame generation callback to emit generated frames via signal
    def frame_callback(ts, frame_data):
    print(4, time.time())
    self.events_acquired.emit(frame_data) # Emit a copy of the frame to avoid memory issues

    frame_gen.set_output_callback(frame_callback)

    # Initialize EventsIterator to stream events from the device
    iterator = EventsIterator.from_device(
    device=self.cam,
    delta_t=10000, # 10ms time slice, synchronized with frame generation
    mode='delta_t',
    max_duration=None,
    relative_timestamps=False # todo: Should this be set to True for each new recording?
    )
    # live_iterator = LiveReplayEventsIterator(iterator)

    # Iterate over and process events
    for events in iterator:
    if events.size == 0:
    continue
    # If a callback function is provided, apply it
    if event_callback is not None:
    events = event_callback(events)
    if events is None or not isinstance(events, np.ndarray):
    continue
    frame_gen.process_events(events)

    if not self.isPreviewing:
    break

    # Force generation of the last frame when the stream ends
    frame_gen.force_generate()
    self.isPreviewing = False
    del iterator # Explicitly delete the iterator
  3. Exception in thread Thread-4: Traceback (most recent call last): File "D:\ANACONDA\envs\spinnaker\lib\threading.py", line 932, in _bootstrap_inner self.run() File "D:\ANACONDA\envs\spinnaker\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "G:\Post Graduation Study\Project\cam_control\event_camera\event_camera.py", line 117, in continuous_acquire_events for events in iterator: File "D:\Prophesee\lib\python3\site-packages\metavision_core\event_io\events_iterator.py", line 155, in __iter__ events = self._load() File "D:\Prophesee\lib\python3\site-packages\metavision_core\event_io\events_iterator.py", line 73, in <lambda> self._load = lambda: self.reader.load_delta_t(self.delta_t) File "D:\Prophesee\lib\python3\site-packages\metavision_core\event_io\raw_reader.py", line 358, in load_delta_t return self._load_next_buffer() File "D:\Prophesee\lib\python3\site-packages\metavision_core\event_io\raw_reader.py", line 316, in _load_next_buffer self._run() File "D:\Prophesee\lib\python3\site-packages\metavision_core\event_io\raw_reader.py", line 146, in _run self.i_events_stream_decoder.decode(data) RuntimeError: bad function call

  4. Process finished with exit code -1073741819 (0xC0000005)