-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.py
47 lines (45 loc) · 2.07 KB
/
common.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
import cv2
import numpy as np
def parse_args(opt, init):
if len(opt.input_svo_file) > 0 and opt.input_svo_file.endswith(".svo"):
init.set_from_svo_file(opt.input_svo_file)
print("[Sample] Using SVO File input: {0}".format(opt.input_svo_file))
elif len(opt.ip_address) > 0:
ip_str = opt.ip_address
if (
ip_str.replace(":", "").replace(".", "").isdigit()
and len(ip_str.split(".")) == 4
and len(ip_str.split(":")) == 2
):
init.set_from_stream(ip_str.split(":")[0], int(ip_str.split(":")[1]))
print("[Sample] Using Stream input, IP : ", ip_str)
elif ip_str.replace(":", "").replace(".", "").isdigit() and len(ip_str.split(".")) == 4:
init.set_from_stream(ip_str)
print("[Sample] Using Stream input, IP : ", ip_str)
else:
print("Unvalid IP format. Using live stream")
if "HD2K" in opt.resolution:
init.camera_resolution = sl.RESOLUTION.HD2K
print("[Sample] Using Camera in resolution HD2K")
elif "HD1200" in opt.resolution:
init.camera_resolution = sl.RESOLUTION.HD1200
print("[Sample] Using Camera in resolution HD1200")
elif "HD1080" in opt.resolution:
init.camera_resolution = sl.RESOLUTION.HD1080
print("[Sample] Using Camera in resolution HD1080")
elif "HD720" in opt.resolution:
init.camera_resolution = sl.RESOLUTION.HD720
print("[Sample] Using Camera in resolution HD720")
elif "SVGA" in opt.resolution:
init.camera_resolution = sl.RESOLUTION.SVGA
print("[Sample] Using Camera in resolution SVGA")
elif "VGA" in opt.resolution:
init.camera_resolution = sl.RESOLUTION.VGA
print("[Sample] Using Camera in resolution VGA")
elif len(opt.resolution) > 0:
print("[Sample] No valid resolution entered. Using default")
else:
print("[Sample] Using default resolution")
def resize_image(image: np.ndarray, rate: float) -> np.ndarray:
H, W = image.shape[:2]
return cv2.resize(image, (int(W * rate), int(H * rate)))