File size: 1,546 Bytes
bfbecd6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
visulize event frame (npy file).
"""
import argparse
from pathlib import Path
import numpy as np
from tqdm import tqdm
import cv2 as cv

parser = argparse.ArgumentParser(description="Convert the event file to frame.")
parser.add_argument("--input", type=str, help="the path of npz file or dir.")
parser.add_argument("--output", type=str, help="the dir of out event.")
parser.add_argument("--show", action="store_true", help="show the event frame on screen.")
parser.add_argument("--save", action="store_true", help="write the visualization results to dir.")
args = parser.parse_args()

def render_ev_accumulation(ev_frame) -> np.ndarray:
    
    
    img= np.full((*ev_frame.shape, 3), fill_value=255, dtype="uint8")
    
    # img[ev_frame == 0] = [255, 255, 255]
    # img[ev_frame < 0] = [255, 0, 0]
    # img[ev_frame > 0] = [0, 0, 255]
    
    img[ev_frame < -1] = [255, 0, 0]
    img[ev_frame > 1] = [0, 0, 255]
    
    return img

if __name__ == "__main__":
    print(args)
    in_path = Path(args.input)
    out_path = Path(args.output)
    out_path.mkdir(parents=True, exist_ok=True)

    if in_path.is_dir():
        ev_list = list(in_path.glob("*.npy"))
    else:
        ev_list = [in_path]
    
    for ev_path in tqdm(ev_list):
        ev_frame = np.load(ev_path)
        img = render_ev_accumulation(ev_frame)
        if args.save:
            cv.imwrite(str(out_path / ev_path.stem) + ".png", img)
        
        if args.show:
            cv.imshow("img", img)
            cv.waitKey(0)
            cv.destroyAllWindows()