Use inc arg in apply_setting(), fix saved picture file case
This commit is contained in:
parent
9d5a49da21
commit
ae7e582d58
|
@ -157,21 +157,22 @@ class webcam():
|
||||||
return capture_ok
|
return capture_ok
|
||||||
|
|
||||||
def increment_setting(self, setting:str, inc:int=-1):
|
def increment_setting(self, setting:str, inc:int=-1):
|
||||||
# If value has default -1 value, increment setting
|
if setting in self.camera_current_settings:
|
||||||
if inc == -1:
|
if inc == -1:
|
||||||
if setting in self.camera_current_settings:
|
if self.camera_current_settings[setting]['value'] - self.camera_current_settings[setting]['step'] in range(self.camera_current_settings[setting]['min'],self.camera_current_settings[setting]['max']+1):
|
||||||
|
self.camera_current_settings[setting]['value'] -= self.camera_current_settings[setting]['step']
|
||||||
|
else:
|
||||||
|
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['max']
|
||||||
|
elif inc == 1:
|
||||||
if self.camera_current_settings[setting]['value'] + self.camera_current_settings[setting]['step'] in range(self.camera_current_settings[setting]['min'],self.camera_current_settings[setting]['max']+1):
|
if self.camera_current_settings[setting]['value'] + self.camera_current_settings[setting]['step'] in range(self.camera_current_settings[setting]['min'],self.camera_current_settings[setting]['max']+1):
|
||||||
self.camera_current_settings[setting]['value'] += self.camera_current_settings[setting]['step']
|
self.camera_current_settings[setting]['value'] += self.camera_current_settings[setting]['step']
|
||||||
else:
|
else:
|
||||||
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['min']
|
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['min']
|
||||||
# Apply special cases
|
|
||||||
else:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def build_v4l2_cmd(self, to_set:list=None):
|
def build_v4l2_cmd(self, to_set:list=None, inc:int=-1):
|
||||||
cmd = '{} -d /dev/video0'.format(project_settings['v4l2-ctl_path'])
|
cmd = '{} -d /dev/video0'.format(project_settings['v4l2-ctl_path'])
|
||||||
args = []
|
args = []
|
||||||
value = -1
|
value = inc
|
||||||
for setting in self.camera_current_settings:
|
for setting in self.camera_current_settings:
|
||||||
if to_set is None:
|
if to_set is None:
|
||||||
# Apply defaults
|
# Apply defaults
|
||||||
|
@ -205,8 +206,8 @@ class webcam():
|
||||||
v4l2_ctl_process = subprocess.Popen(cmd.split(' '))
|
v4l2_ctl_process = subprocess.Popen(cmd.split(' '))
|
||||||
return v4l2_ctl_process
|
return v4l2_ctl_process
|
||||||
|
|
||||||
def apply_setting(self, to_set:list=None, inc:int=0):
|
def apply_setting(self, to_set:list=None, inc:int=-1):
|
||||||
cmd = self.build_v4l2_cmd(to_set)
|
cmd = self.build_v4l2_cmd(to_set, inc)
|
||||||
self.run_v4l2_ctl(cmd)
|
self.run_v4l2_ctl(cmd)
|
||||||
return self.camera_current_settings
|
return self.camera_current_settings
|
||||||
|
|
||||||
|
@ -244,8 +245,8 @@ class showmewebcam(webcam):
|
||||||
'exposure': 'exposure_time_absolute'
|
'exposure': 'exposure_time_absolute'
|
||||||
}
|
}
|
||||||
|
|
||||||
def apply_setting(self, to_set:list=None, inc:int=0):
|
def apply_setting(self, to_set:list=None, inc:int=-1):
|
||||||
cmd = self.build_v4l2_cmd(to_set)
|
cmd = self.build_v4l2_cmd(to_set, inc)
|
||||||
self.serialutils.send_serial_cmd(self.serialutils.find_cam_port(), cmd)
|
self.serialutils.send_serial_cmd(self.serialutils.find_cam_port(), cmd)
|
||||||
return self.camera_current_settings
|
return self.camera_current_settings
|
||||||
|
|
||||||
|
@ -422,7 +423,7 @@ class dslr():
|
||||||
'whitebalance' : dict(min=0, max=7, step=1, default=2, value=1), # 0 Automatic 1 Daylight 2 Fluorescent 3 Tungsten 4 Flash 5 Cloudy 6 Shade 7 Preset
|
'whitebalance' : dict(min=0, max=7, step=1, default=2, value=1), # 0 Automatic 1 Daylight 2 Fluorescent 3 Tungsten 4 Flash 5 Cloudy 6 Shade 7 Preset
|
||||||
'capturetarget' : dict(min=0, max=1, step=1, default=0, value=0), # Internal memory
|
'capturetarget' : dict(min=0, max=1, step=1, default=0, value=0), # Internal memory
|
||||||
'iso' : dict(min=0, max=5, default=0, step=1, value=0), # 0:100, 5:3200
|
'iso' : dict(min=0, max=5, default=0, step=1, value=0), # 0:100, 5:3200
|
||||||
'shutterspeed' : dict(min=0, max=51, step=1, default=0, value=30), # 0 : 1/4000, 51: 30s
|
'shutterspeed' : dict(min=0, max=51, step=1, default=30, value=30), # 0 : 1/4000, 51: 30s
|
||||||
# ~ 'manualfocusdrive' : dict(min=0, max=1, step=1, default=0, value=0), # Trigger autofocus # manualfocusdrive
|
# ~ 'manualfocusdrive' : dict(min=0, max=1, step=1, default=0, value=0), # Trigger autofocus # manualfocusdrive
|
||||||
}
|
}
|
||||||
# Map generic config name to specific picamera setting name
|
# Map generic config name to specific picamera setting name
|
||||||
|
@ -480,7 +481,7 @@ class dslr():
|
||||||
# if the path doesn't contain file name, return camera's FS filename
|
# if the path doesn't contain file name, return camera's FS filename
|
||||||
if not full_path.endswith(('.jpg', '.JPG', '.raw')):
|
if not full_path.endswith(('.jpg', '.JPG', '.raw')):
|
||||||
return gp_name
|
return gp_name
|
||||||
suffix = gp_name.split('.')[-1]
|
suffix = gp_name.split('.')[-1].lower()
|
||||||
prefix = new_name.split('.')[:-1]
|
prefix = new_name.split('.')[:-1]
|
||||||
prefix.insert(len(prefix), suffix)
|
prefix.insert(len(prefix), suffix)
|
||||||
return os.path.join(dirname, '.'.join(prefix))
|
return os.path.join(dirname, '.'.join(prefix))
|
||||||
|
@ -518,7 +519,7 @@ class dslr():
|
||||||
)
|
)
|
||||||
capture_ok = camera_file.save(img_path)
|
capture_ok = camera_file.save(img_path)
|
||||||
except self.gp.GPhoto2Error as ex:
|
except self.gp.GPhoto2Error as ex:
|
||||||
print(ex.code)
|
print(ex)
|
||||||
# This is the way to find which error code is returned by gphoto
|
# This is the way to find which error code is returned by gphoto
|
||||||
# See http://gphoto.org/doc/api/gphoto2-result_8h.html for error codes
|
# See http://gphoto.org/doc/api/gphoto2-result_8h.html for error codes
|
||||||
# Cam was turned off/on
|
# Cam was turned off/on
|
||||||
|
@ -565,10 +566,16 @@ class dslr():
|
||||||
|
|
||||||
def increment_setting(self, setting:str, inc:int=-1):
|
def increment_setting(self, setting:str, inc:int=-1):
|
||||||
if setting in self.camera_current_settings:
|
if setting in self.camera_current_settings:
|
||||||
if self.camera_current_settings[setting]['value'] + self.camera_current_settings[setting]['step'] in range(self.camera_current_settings[setting]['min'],self.camera_current_settings[setting]['max']+1):
|
if inc == -1:
|
||||||
self.camera_current_settings[setting]['value'] += self.camera_current_settings[setting]['step']
|
if self.camera_current_settings[setting]['value'] - self.camera_current_settings[setting]['step'] in range(self.camera_current_settings[setting]['min'],self.camera_current_settings[setting]['max']+1):
|
||||||
else:
|
self.camera_current_settings[setting]['value'] -= self.camera_current_settings[setting]['step']
|
||||||
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['min']
|
else:
|
||||||
|
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['max']
|
||||||
|
elif inc == 1:
|
||||||
|
if self.camera_current_settings[setting]['value'] + self.camera_current_settings[setting]['step'] in range(self.camera_current_settings[setting]['min'],self.camera_current_settings[setting]['max']+1):
|
||||||
|
self.camera_current_settings[setting]['value'] += self.camera_current_settings[setting]['step']
|
||||||
|
else:
|
||||||
|
self.camera_current_settings[setting]['value'] = self.camera_current_settings[setting]['min']
|
||||||
|
|
||||||
def apply_setting(self, to_set:list=None, inc:int=0):
|
def apply_setting(self, to_set:list=None, inc:int=0):
|
||||||
if self.cam is None:
|
if self.cam is None:
|
||||||
|
@ -578,7 +585,7 @@ class dslr():
|
||||||
if to_set is None:
|
if to_set is None:
|
||||||
for setting in self.camera_current_settings:
|
for setting in self.camera_current_settings:
|
||||||
if inc:
|
if inc:
|
||||||
self.increment_setting(setting)
|
self.increment_setting(setting, inc)
|
||||||
self.apply_gphoto_setting(setting)
|
self.apply_gphoto_setting(setting)
|
||||||
else:
|
else:
|
||||||
# Get corresponding setting name if possible
|
# Get corresponding setting name if possible
|
||||||
|
@ -586,7 +593,7 @@ class dslr():
|
||||||
if setting in self.cam_settings_map:
|
if setting in self.cam_settings_map:
|
||||||
setting = self.cam_settings_map[setting]
|
setting = self.cam_settings_map[setting]
|
||||||
if inc:
|
if inc:
|
||||||
self.increment_setting(setting)
|
self.increment_setting(setting, inc)
|
||||||
self.apply_gphoto_setting(setting)
|
self.apply_gphoto_setting(setting)
|
||||||
# validate config
|
# validate config
|
||||||
status = self.gp.check_result(self.gp.gp_camera_set_config(self.cam, self.camera_current_config))
|
status = self.gp.check_result(self.gp.gp_camera_set_config(self.cam, self.camera_current_config))
|
||||||
|
@ -598,7 +605,10 @@ class dslr():
|
||||||
self.flip_img = True
|
self.flip_img = True
|
||||||
|
|
||||||
def focus(self, direction:str='-'):
|
def focus(self, direction:str='-'):
|
||||||
self.apply_setting(['shutterspeed'], 1)
|
if direction == '-':
|
||||||
|
self.apply_setting(['shutterspeed'], -1)
|
||||||
|
elif direction == '+':
|
||||||
|
self.apply_setting(['shutterspeed'], 1)
|
||||||
|
|
||||||
def reset_picture_settings(self):
|
def reset_picture_settings(self):
|
||||||
if self.cam is None:
|
if self.cam is None:
|
||||||
|
@ -611,7 +621,8 @@ class dslr():
|
||||||
status = self.gp.check_result(self.gp.gp_camera_set_config(self.cam, self.camera_current_config))
|
status = self.gp.check_result(self.gp.gp_camera_set_config(self.cam, self.camera_current_config))
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.cam.exit()
|
if self.cam is not None:
|
||||||
|
self.cam.exit()
|
||||||
|
|
||||||
|
|
||||||
def get_cam_class(camera_type):
|
def get_cam_class(camera_type):
|
||||||
|
@ -818,7 +829,7 @@ def get_before_last_frame(folder:str):
|
||||||
def get_onionskin_frame(folder:str):
|
def get_onionskin_frame(folder:str):
|
||||||
prev_image = get_last_frame(folder)
|
prev_image = get_last_frame(folder)
|
||||||
prev_image = '.'.join(prev_image)
|
prev_image = '.'.join(prev_image)
|
||||||
if os.path.exists( os.path.expanduser(os.path.join(savepath, prev_image))):
|
if os.path.exists(os.path.expanduser(os.path.join(savepath, prev_image))):
|
||||||
frm = cv2.imread(os.path.join(savepath, prev_image))
|
frm = cv2.imread(os.path.join(savepath, prev_image))
|
||||||
frm = cv2.resize(frm, (project_settings['screen_w'], project_settings['screen_h']))
|
frm = cv2.resize(frm, (project_settings['screen_w'], project_settings['screen_h']))
|
||||||
# Img does not exist, load blank image
|
# Img does not exist, load blank image
|
||||||
|
@ -1131,6 +1142,7 @@ def main(args):
|
||||||
elif (k%256 == 115) or (k%256 == 65):
|
elif (k%256 == 115) or (k%256 == 65):
|
||||||
print(_("Inc. exposure"))
|
print(_("Inc. exposure"))
|
||||||
cam.apply_setting(['exposure'], 1)
|
cam.apply_setting(['exposure'], 1)
|
||||||
|
# Exposure: key Maj Q
|
||||||
elif (k%256 == 90):
|
elif (k%256 == 90):
|
||||||
print(_("Dec. exposure"))
|
print(_("Dec. exposure"))
|
||||||
cam.apply_setting(['exposure'], -1)
|
cam.apply_setting(['exposure'], -1)
|
||||||
|
@ -1149,6 +1161,8 @@ def main(args):
|
||||||
index += 1
|
index += 1
|
||||||
cam.frame = get_onionskin_frame(savepath)
|
cam.frame = get_onionskin_frame(savepath)
|
||||||
cam.o_frame = cam.frame.copy()
|
cam.o_frame = cam.frame.copy()
|
||||||
|
else:
|
||||||
|
print(_("Error during capture. Try again."))
|
||||||
# Display a message if capture was not successfull
|
# Display a message if capture was not successfull
|
||||||
# This happens when you try to take too much pictures in a short span of time with the DSLR.
|
# This happens when you try to take too much pictures in a short span of time with the DSLR.
|
||||||
# With a long exposure, gphoto will sometimes throw a GP_ERROR_CAMERA_BUSY (-110) error.
|
# With a long exposure, gphoto will sometimes throw a GP_ERROR_CAMERA_BUSY (-110) error.
|
||||||
|
|
Loading…
Reference in New Issue