-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyconfig.py
34 lines (26 loc) · 1.13 KB
/
myconfig.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
import cv2
class Config:
@classmethod
def __init__(self,filename):
self.file_ = cv2.FileStorage(filename, cv2.FILE_STORAGE_READ)
if (self.file_.isOpened() == False ):
self.file_.release()
raise IOError(f"{filename} does not exist.")
#@classmethod
# def setParameterFile(self,filename):
# self.file_ = cv2.FileStorage(filename, cv2.FILE_STORAGE_READ)
# if (self.file_.isOpened() == False ):
# print("parameter file ",filename," does not exist.")
# self.file_.release()
# return None
@classmethod
def get(self,nodename):
# self.file_ = cv2.FileStorage(filename, cv2.FILE_STORAGE_READ) 在setParameterFile设置过路径了
return self.file_.getNode(nodename)
def __del__(self): # 并没有创建对象,一致在用classmethod, 所以可能file_一直没release
if self.file_.isOpened():
self.file_.release()
if __name__ == "__main__":
#Config.setParameterFile("config.yml")
config = Config("config.yml")
print(config.get("realNode").real())