forked from SensorsINI/v2e
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evs_visualiser.py
76 lines (58 loc) · 1.76 KB
/
evs_visualiser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Python code for visualising evs videos saved in AEDAT4 format.
@author: Piotr Baryczkowski
@contact: [email protected]
"""
import argparse
import sys
import aedat # https://pypi.org/project/aedat/
import cv2 # https://pypi.org/project/opencv-python/
import numpy as np
def parse_args(argv: list[str]) -> argparse.Namespace:
arg_parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
arg_parser.add_argument(
"-i",
"--input",
type=str,
action="store",
required=True,
help="Path to file with AEDAT4 format",
)
arg_parser.add_argument(
"--width",
type=int,
action="store",
required=True,
help="Width of output DVS data in pixels.",
)
arg_parser.add_argument(
"--height",
type=int,
action="store",
required=True,
help="Height of output DVS data in pixels.",
)
return arg_parser.parse_args()
def visualise(decoder: aedat.Decoder, resolution: tuple[int, int]) -> None:
for packet in decoder:
image = np.full(resolution, 128, dtype=np.uint8)
for event in packet["events"]:
_, w, h, val = event
if val != 0 and val != 1:
print(val)
pixel_color = 255 if val else 0
if image[h, w] != pixel_color:
image[h, w] = pixel_color
cv2.imshow("event", image)
if cv2.waitKey(33) == ord("q"):
cv2.destroyAllWindows()
sys.exit()
def main():
args = parse_args(sys.argv[1:])
decoder = aedat.Decoder(args.input)
resolution = (args.height, args.width)
visualise(decoder, resolution)
if __name__ == "__main__":
main()