-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
41 lines (26 loc) · 847 Bytes
/
utils.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
import cv2
import os
from importlib import import_module
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DATA_DIR = os.path.join(BASE_DIR, 'data')
def load_agent(name):
agent = 'agents.' + name
return import_module(agent)
def load_module(name):
module = 'modules.' + name
return import_module(module)
def load_modules(config):
modules = {}
for name in config.keys():
if not config[name]['enabled']:
continue
module = load_module(name)
modules[name] = module.load(config[name])
return modules
def load_image(dir, name):
img = cv2.imread(os.path.join(dir, name))
return cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
def save_image(dir, name, img):
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
filename = os.path.join(dir, name)
cv2.imwrite(filename, img)