-
Notifications
You must be signed in to change notification settings - Fork 28
/
simulator.py
70 lines (60 loc) · 2.4 KB
/
simulator.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
import time
import configparser
from pathlib import Path
from PIL import Image, ImageOps
DEBUG = False
END = 100000000 # max number of images to process
SKIP = 0 # 5000
def run_simulator(
input_dir, imgs, output_dir="./imgs", ext="jpg", step=1, sleep=0.1, equalize=False, n_camera=1,
):
print(len(imgs))
for i in range(len(imgs)):
if i < SKIP:
continue
if i == END:
print(
f"Processed {END} images. Change the END variable in simulator.py to process more."
)
quit()
# Process only every STEP-th image
if i % step != 0:
continue
if DEBUG:
print(f"processing {i}-th img ({i}/{len(imgs)})")
for c in reversed(range(n_camera)):
im_name = imgs[i].name
#im_name = im_name[8:] # for ant3d
im = Image.open(input_dir / f"cam{c}/data" / im_name)
#im = Image.open(input_dir / f"cam{c}/data" / f"ANT3D_{c+1}_{im_name}") # for ant3d
rgb_im = im.convert("RGB")
if equalize == True:
rgb_im = ImageOps.equalize(rgb_im)
#rgb_im.thumbnail((960, 600), Image.Resampling.LANCZOS) # for ant3d
rgb_im.save(Path(output_dir) / f"cam{c}" / f"{Path(im_name).stem}.{ext}")
time.sleep(sleep)
print("No more images available")
if __name__ == "__main__":
config = configparser.ConfigParser()
config.read("config.ini", encoding="utf-8")
input_dir = Path(config["DEFAULT"]["SIMULATOR_IMG_DIR"])
output_dir = config["DEFAULT"]["IMGS_FROM_SERVER"]
ext = config["DEFAULT"]["IMG_FORMAT"]
step = int(config["DEFAULT"]["STEP"])
sleep = float(config["DEFAULT"]["SIMULATOR_SLEEP_TIME"])
equalize = config["DEFAULT"].getboolean("EQUALIZE")
n_camera = int(config["CALIBRATION"]["N_CAMERAS"])
path_to_kfrms_cam0 = Path(input_dir / "cam0/data")
if not path_to_kfrms_cam0.exists():
print(
'\nERROR: Keyframe directory cam0:',
Path(input_dir / "cam0/data"),
'\nKeframe dir do not exist, check the input path:',
'\nExpected dir structures:'
'\ninput_path',
'\n--> cam0',
'\n----> data',
'\n------> 00000.jpg',
)
imgs = sorted(Path(input_dir / "cam0/data").glob("*"))
run_simulator(input_dir, imgs, output_dir, ext, step, sleep, equalize, n_camera)