Skip to content

Commit

Permalink
Change camera default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
karakurai committed Sep 6, 2023
1 parent b36f267 commit 504324d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
20 changes: 18 additions & 2 deletions camera_setting_screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ def load_camera_parameter(self, camera_num):
tmp_cap.set(
cv2.CAP_PROP_AUTOFOCUS, camera_param_dict["CAP_PROP_AUTOFOCUS"]
)
if camera_param_dict["EDIT_AUTO_WB"]:
tmp_cap.set(
cv2.CAP_PROP_AUTO_WB, camera_param_dict["CAP_PROP_AUTO_WB"]
)
if camera_param_dict["EDIT_WB_TEMPERATURE"]:
tmp_cap.set(
cv2.CAP_PROP_WB_TEMPERATURE,
camera_param_dict["CAP_PROP_WB_TEMPERATURE"],
)
return True
return False

Expand Down Expand Up @@ -165,9 +174,14 @@ def active_camera(self, camera_num):
self.screen.ids["parameter_settings_button"].disabled = False
self.screen.ids["save_settings_button"].disabled = False
self.screen.ids["delete_saved_settings_button"].disabled = False
Clock.schedule_interval(self.update, 1.0 / float(self.app.confini["settings"]["display_fps"]))
Clock.schedule_interval(
self.update, 1.0 / float(self.app.confini["settings"]["display_fps"])
)
Clock.schedule_interval(self.update_parameter, 5)
Clock.schedule_interval(self._disp_canvas, 1.0 / float(self.app.confini["settings"]["display_fps"]))
Clock.schedule_interval(
self._disp_canvas,
1.0 / float(self.app.confini["settings"]["display_fps"]),
)

def _disp_canvas(self, dt):
if self.texture is not None:
Expand Down Expand Up @@ -278,6 +292,8 @@ def update_parameter(self, dt):
"CAP_PROP_AUTO_EXPOSURE": self.cap.get(cv2.CAP_PROP_AUTO_EXPOSURE),
"CAP_PROP_FOCUS": self.cap.get(cv2.CAP_PROP_FOCUS),
"CAP_PROP_AUTOFOCUS": self.cap.get(cv2.CAP_PROP_AUTOFOCUS),
"CAP_PROP_AUTO_WB": self.cap.get(cv2.CAP_PROP_AUTO_WB),
"CAP_PROP_WB_TEMPERATURE": self.cap.get(cv2.CAP_PROP_WB_TEMPERATURE),
}
self.app.camera_parameter_list[self.app.camera_num].update(camera_para)
self.pt.display_parameter(None)
Expand Down
30 changes: 22 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import pickle

import cv2
from aimodel_setting_screen import AimodelSettingScreen
from camera_setting_screen import CameraSettingScreen
from inspection_setting_screen import InspectionSettingScreen
from kivy.core.text import DEFAULT_FONT, LabelBase
from kivy.core.window import Window
from kivy.lang import Builder
Expand All @@ -18,6 +15,10 @@
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.screen import MDScreen
from kivymd.uix.screenmanager import MDScreenManager

from aimodel_setting_screen import AimodelSettingScreen
from camera_setting_screen import CameraSettingScreen
from inspection_setting_screen import InspectionSettingScreen
from main_screen import MainScreen
from making_dataset_screen import MakingDatasetScreen
from preprocessing_screen import PreprocessingScreen
Expand Down Expand Up @@ -123,9 +124,8 @@ def get_cameras(self):
"CAP_PROP_GAIN": cap.get(cv2.CAP_PROP_GAIN),
"CAP_PROP_GAMMA": cap.get(cv2.CAP_PROP_GAMMA),
"CAP_PROP_EXPOSURE": cap.get(cv2.CAP_PROP_EXPOSURE),
"CAP_PROP_AUTO_EXPOSURE": cap.get(cv2.CAP_PROP_AUTO_EXPOSURE),
"CAP_PROP_FOCUS": cap.get(cv2.CAP_PROP_FOCUS),
"CAP_PROP_AUTOFOCUS": cap.get(cv2.CAP_PROP_AUTOFOCUS),
"CAP_PROP_WB_TEMPERATURE": cap.get(cv2.CAP_PROP_WB_TEMPERATURE),
}
editable_para = {
"EDIT_FRAME_WIDTH": cap.set(
Expand Down Expand Up @@ -162,16 +162,25 @@ def get_cameras(self):
),
"EDIT_AUTO_EXPOSURE": cap.set(
cv2.CAP_PROP_AUTO_EXPOSURE,
camera_para["CAP_PROP_AUTO_EXPOSURE"],
0.1,
),
"EDIT_FOCUS": cap.set(
cv2.CAP_PROP_FOCUS, camera_para["CAP_PROP_FOCUS"]
),
"EDIT_AUTOFOCUS": cap.set(
cv2.CAP_PROP_AUTOFOCUS, camera_para["CAP_PROP_AUTOFOCUS"]
"EDIT_AUTOFOCUS": cap.set(cv2.CAP_PROP_AUTOFOCUS, 0.1),
"EDIT_AUTO_WB": cap.set(cv2.CAP_PROP_AUTO_WB, 0.1),
"EDIT_WB_TEMPERATURE": cap.set(
cv2.CAP_PROP_WB_TEMPERATURE,
camera_para["CAP_PROP_WB_TEMPERATURE"],
),
}
camera_para.update(editable_para)
update_auto_para = {
"CAP_PROP_AUTO_EXPOSURE": cap.get(cv2.CAP_PROP_AUTO_EXPOSURE),
"CAP_PROP_AUTOFOCUS": cap.get(cv2.CAP_PROP_AUTOFOCUS),
"CAP_PROP_AUTO_WB": cap.get(cv2.CAP_PROP_AUTO_WB),
}
camera_para.update(update_auto_para)
self.camera_parameter_list[i] = camera_para
self.camera_list[i] = cap
self.camera_count += 1
Expand Down Expand Up @@ -342,6 +351,11 @@ def open_inspection_cameras(self):
cv2.CAP_PROP_AUTOFOCUS,
camera_param_dict["CAP_PROP_AUTOFOCUS"],
)
if camera_param_dict["EDIT_AUTO_WB"]:
self.camera_list[camera_num].set(
cv2.CAP_PROP_AUTO_WB,
camera_param_dict["CAP_PROP_AUTO_WB"],
)
if "RATIO_1" in camera_param_dict:
self.current_ratio1[camera_num] = camera_param_dict[
"RATIO_1"
Expand Down

0 comments on commit 504324d

Please sign in to comment.