将.dat文件转换为.jpg或.png

时间:2020-07-11 15:11:44

标签: python numpy machine-learning

我需要将.dat格式的图像转换为.jpg.png格式。我在stackoverflow周围搜索,但是找不到正确的答案。我尝试了以下代码:

   import numpy as np
   datfile = "car_image.dat"
   # Read file into Numpy array as uint8
   na = np.fromfile(datfile , dtype=np.uint8)
   print(na.shape)

上面的代码打印(65269,0),但是我不知道下一步要怎么将其转换为.png.jpg图像。您能帮我吗,谢谢!

1 个答案:

答案 0 :(得分:1)

您误解了所下载的内容。

这些不是图像,它们是基于事件的数据集,这就是为什么它们提供.dat文件而不是图像的原因。这写在您发布的下载链接的正下方:

Prophesee的N-CARS数据集,这是大型的基于事件的现实世界数据集,用于汽车分类

并且来自Prophesee发布的GEN-1, another dataset,它似乎使用了相同的编码:

每个dat文件都是一个二进制文件,其中的事件使用时间戳记的4个字节(无符号int32)和数据使用4个字节(无符号int32)进行编码,编码方式为小端顺序。

他们还提供an ipynb tutorial,说明如何与他们互动。总结:

import numpy as np
from src.io.psee_loader import PSEELoader

# open a file
video = PSEELoader("some_file_td.dat")
print(video)  # show some metadata
video.event_count()  # number of events in the file
video.total_time()  # duration of the file in mus

# let's read some Events , there are two ways by number of events or by time slices
events = video.load_n_events(10)  # this loads the 10 next events
events

# let's randomly drop some events
np.random.choice(events, len(events)//2)

# let's now try to read 10ms worth of events
events = video.load_delta_t(10000)

以此类推...