Clear Filters
Clear Filters

What is the best way for frame construction?

20 views (last 30 days)
M on 4 Oct 2023
Edited: M on 4 Oct 2023
What is the best way to convert events(x,y,polarity,time stamp) that are obtained from event camera via ROS to Frames?

Answers (1)

recent works
recent works on 4 Oct 2023
Converting events from an event camera (also known as a dynamic vision sensor, DVS) to traditional frames is a process called event-based frame reconstruction. Event cameras capture changes in pixel intensity as a stream of events, typically consisting of (x, y, polarity, timestamp) data, where (x, y) represents the location of the event, polarity indicates whether the event represents an increase or decrease in intensity, and timestamp records the time when the event occurred. To convert these events into frames, you can use various methods and algorithms.
import numpy as np
import cv2
import rospy
from dvs_msgs.msg import EventArray
# Initialize the frame and time variables
frame_width, frame_height = 640, 480 # Set your desired frame resolution
frames = np.zeros((frame_height, frame_width), dtype=np.uint8)
current_time = 0
# Define a time window for accumulating events (in microseconds)
time_window = 10000 # 10 ms
# Callback function for processing incoming events
def event_callback(event_array):
global frames, current_time
for event in
x, y, polarity, timestamp = event.x, event.y, event.polarity, event.ts.to_nsec()
# Check if the event is within the time window
if timestamp - current_time > time_window:
# Visualize or process the accumulated frame(s) here
cv2.imshow("Reconstructed Frame", frames)
# Reset the frame and current time
frames = np.zeros((frame_height, frame_width), dtype=np.uint8)
current_time = timestamp
# Update the pixel based on event polarity
frames[y, x] = 255 if polarity else 0
if __name__ == "__main__":
rospy.Subscriber("/dvs/events", EventArray, event_callback)
This code listens to ROS messages containing events and accumulates them into frames within a specified time window. When the time window is exceeded, it displays the accumulated frame(s) and resets for the next accumulation. You'll need to adapt it to your specific event camera and ROS setup
M on 4 Oct 2023
Edited: M on 4 Oct 2023
@recent works what is current_time ?
I have x y polarity timestamp as matrices
M on 4 Oct 2023
Edited: M on 4 Oct 2023
@recent works I didnt get these lines
if timestamp - current_time > time_window
current_time = timestamp;
% Update the pixel based on event polarity
if polarity
frames(y, x) = 255;
please elaborate

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!