- load/save capture parameter for each camera device
This commit is contained in:
@@ -41,6 +41,10 @@ class Detector(abc.ABC):
|
||||
self.src_images = f"{os.path.dirname(source)}/{name}_%0{len(numeric_part)}d.{suffix}"
|
||||
|
||||
Path.mkdir(Path(RESULTS_FOLDER), exist_ok=True)
|
||||
try:
|
||||
self.params_load()
|
||||
except json.decoder.JSONDecodeError:
|
||||
self.params_save()
|
||||
|
||||
self.cap = None
|
||||
if self.device_id is not None:
|
||||
@@ -55,6 +59,7 @@ class Detector(abc.ABC):
|
||||
self.cap = cv.VideoCapture(self.src_images, cv.CAP_IMAGES)
|
||||
self.camera_name = self.name
|
||||
|
||||
print(f"Camera: {self.camera_name}")
|
||||
self.calibration = Calibration()
|
||||
self.calibration.load(f"{RESULTS_FOLDER}/{self.camera_name}_cal.npz")
|
||||
|
||||
@@ -62,6 +67,10 @@ class Detector(abc.ABC):
|
||||
with open(f"{RESULTS_FOLDER}/{self.params["name"]}.json", 'w') as fp:
|
||||
json.dump(self.params, fp, indent=4)
|
||||
|
||||
def params_load(self):
|
||||
with open(f"{RESULTS_FOLDER}/{self.params["name"]}.json", 'r') as fp:
|
||||
self.params = json.load(fp)
|
||||
|
||||
def cap_init(self):
|
||||
backends = {'V4L2': cv.CAP_V4L}
|
||||
cameras = enumerate_cameras(backends[self.cap.getBackendName()])
|
||||
@@ -70,27 +79,29 @@ class Detector(abc.ABC):
|
||||
if cam.index == self.device_id:
|
||||
self.camera_name = cam.name.split(':')[0]
|
||||
|
||||
print(self.camera_name)
|
||||
|
||||
camera_params_default = {
|
||||
"CAP_PROP_FRAME_WIDTH": 1920 * 2,
|
||||
"CAP_PROP_FRAME_HEIGHT": 1080 * 2,
|
||||
"CAP_PROP_FPS": 60,
|
||||
"CAP_PROP_GAIN": 128,
|
||||
"CAP_PROP_EXPOSURE": 200,
|
||||
"CAP_PROP_AUTO_EXPOSURE": 1
|
||||
"CAP_PROP_AUTO_EXPOSURE": 1,
|
||||
"CAP_PROP_FOURCC": 1196444237
|
||||
}
|
||||
camera = {}
|
||||
if not "camera" in self.params:
|
||||
camera = camera_params_default
|
||||
|
||||
if 'camera' not in self.params:
|
||||
self.params['camera'] = {}
|
||||
|
||||
if not self.camera_name in self.params['camera']:
|
||||
self.params['camera'][self.camera_name] = camera_params_default
|
||||
|
||||
camera = self.params['camera'][self.camera_name]
|
||||
for item in camera:
|
||||
key = item
|
||||
value = camera[key]
|
||||
k = getattr(globals()['cv'], key)
|
||||
self.cap.set(k, value)
|
||||
|
||||
self.params['camera'] = {self.camera_name: camera}
|
||||
self.params_save()
|
||||
|
||||
@staticmethod
|
||||
@@ -149,7 +160,7 @@ class Detector(abc.ABC):
|
||||
elif k == ord('c'):
|
||||
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
|
||||
if self.calibration.process(gray):
|
||||
print(f"{self.name}: Camera calibration success")
|
||||
print(f"{self.camera_name}: Camera calibration success")
|
||||
self.calibration.save(f"{RESULTS_FOLDER}/{self.camera_name}_cal.npz")
|
||||
elif k == ord('x'):
|
||||
self.calibration.calibration_clear()
|
||||
|
||||
Reference in New Issue
Block a user