uzh-rpg / dagr

Code for the paper "Low Latency Automotive Vision with Event Cameras", published in Nature
GNU General Public License v3.0
143 stars 13 forks source link

Cannot import name 'extract_image_by_index' from 'dsec_det.io' #1

Open Bin1119 opened 1 month ago

Bin1119 commented 1 month ago

It's a great job. But I got an error when running scripts/visualize_detections.py. I don't know if the code version needs to be updated.

Traceback (most recent call last):
  File "scripts/visualize_detections.py", line 8, in <module>
    from dsec_det.io import extract_from_h5_by_timewindow, extract_image_by_index, load_start_and_end_time
ImportError: cannot import name 'extract_image_by_index' from 'dsec_det.io' (/workspace/jb/dagr/libs/dsec-det/src/dsec_det/io.py)
Zhang-JK commented 1 month ago

Same problem here. I tried to implement the missing functions as below for your reference. (Note that i only tested on the sample data and the function may be wrong)

in io.py:

def extract_image_by_index(image_list, idx):
    # use cv2 to read and return image
    return cv2.imread(str(image_list[idx]))

def load_start_and_end_time(dsec_directory):
    with h5py.File(str(dsec_directory.events.event_file), 'r') as h5f:
        t_offset = h5f['t_offset'][()]
        t = h5f['events/t']
        return t[0] + t_offset, t[-1] + t_offset

in preprocessing.py:

def compute_index(detection_index, discrete_timestamps):    
    mapping = np.zeros_like(discrete_timestamps, dtype="uint64")
    for i, t in enumerate(discrete_timestamps):
        mapping[i] = np.searchsorted(detection_index, t, side='right') - 1 
        mapping[i] = max(mapping[i], 0)
        mapping[i] = min(mapping[i], len(detection_index) - 1) 
    return mapping

Again the code might be wrong, be careful when you do the testing.