def setConfig(config_item, config_value): child_type = gp.check_result(gp.gp_widget_get_type( config_all[config_item])) if child_type == gp.GP_WIDGET_RADIO: value = gp.check_result( gp.gp_widget_get_choice(config_all[config_item], int(config_value))) gp.check_result(gp.gp_widget_set_value(config_all[config_item], value)) gp.check_result(gp.gp_camera_set_config(camera, config, context)) elif child_type == gp.GP_WIDGET_TEXT: gp.check_result( gp.gp_widget_set_value(config_all[config_item], config_value)) gp.check_result(gp.gp_camera_set_config(camera, config, context)) elif child_type == gp.GP_WIDGET_RANGE: gp.check_result( gp.gp_widget_set_value(config_all[config_item], int(config_value))) gp.check_result(gp.gp_camera_set_config(camera, config, context)) elif child_type == gp.GP_WIDGET_TOGGLE: value = gp.check_result(gp.gp_widget_get_value( config_all[config_item])) if value: gp.check_result(gp.gp_widget_set_value(config_all[config_item], 0)) else: gp.check_result(gp.gp_widget_set_value(config_all[config_item], 1)) gp.check_result(gp.gp_camera_set_config(camera, config, context)) return "done"
def configure(self): with open_camera() as (camera, context): config = gp.check_result(gp.gp_camera_get_config(camera, context)) for param, choice in CAMERA_CONFIG.iteritems(): widget = gp.check_result( gp.gp_widget_get_child_by_name(config, param)) value = gp.check_result(gp.gp_widget_get_choice( widget, choice)) gp.gp_widget_set_value(widget, value) gp.gp_camera_set_config(camera, config, context)
def focus_nearer(self, steps): with open_camera() as (camera, context): config = gp.check_result(gp.gp_camera_get_config(camera, context)) widget = gp.check_result( gp.gp_widget_get_child_by_name(config, 'viewfinder')) gp.gp_widget_set_value(widget, 1) gp.gp_camera_set_config(camera, config, context) time.sleep(0.5) self._focus_nearer(steps, camera, config, context) gp.gp_widget_set_value(widget, 1) gp.gp_camera_set_config(camera, config, context)
def _change_focus(self, direction, camera, config, context): """ :param direction: 1 further, 0 nearer """ widget = gp.check_result( gp.gp_widget_get_child_by_name(config, 'manualfocusdrive')) value = gp.check_result( gp.gp_widget_get_choice(widget, 6 if direction else 2)) gp.gp_widget_set_value(widget, value) gp.gp_camera_set_config(camera, config, context) value = gp.check_result(gp.gp_widget_get_choice(widget, 3)) gp.gp_widget_set_value(widget, value) gp.gp_camera_set_config(camera, config, context)
def focus(self, steps=settings.CAMERA_FOCUS_STEPS): with open_camera() as (camera, context): config = gp.check_result(gp.gp_camera_get_config(camera, context)) widget = gp.check_result( gp.gp_widget_get_child_by_name(config, 'viewfinder')) gp.gp_widget_set_value(widget, 1) gp.gp_camera_set_config(camera, config, context) time.sleep(0.5) # focus is relative so we need to focus the furthest possible before adjusting self._focus_further(80, camera, config, context) self._focus_nearer(steps, camera, config, context) gp.gp_widget_set_value(widget, 1) gp.gp_camera_set_config(camera, config, context)
def synchronize_camera_timestamp(self): def set_datetime(config): OK, date_config = gp.gp_widget_get_child_by_name( config, 'datetime') if OK >= gp.GP_OK: widget_type = gp.check_result( gp.gp_widget_get_type(date_config)) if widget_type == gp.GP_WIDGET_DATE: now = int(time.time()) gp.check_result(gp.gp_widget_set_value(date_config, now)) else: now = time.strftime('%Y-%m-%d %H:%M:%S') gp.check_result(gp.gp_widget_set_value(date_config, now)) return True return False # get configuration tree config = gp.check_result(gp.gp_camera_get_config( self.camera)) #, self.context)) # find the date/time setting config item and set it if set_datetime(config): # apply the changed config gp.check_result(gp.gp_camera_set_config(self.camera, config)) #, self.context)) else: print('Could not set date & time') # clean up gp.check_result(gp.gp_camera_exit(self.camera)) #, self.context)) return 0
def connect_camera(): global CAMERA logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) CAMERA = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(CAMERA)) # required configuration will depend on camera type! print "Checking camera config" # get configuration tree config = gp.check_result(gp.gp_camera_get_config(CAMERA)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) # make sure it's not raw if 'raw' in value.lower(): raise PeripheralStatusError('Camera is setup to record raw, but we need previs, and preview does not work with raw images') # find the capture size class config item # need to set this on my Canon 350d to get preview to work at all OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(CAMERA, config))
def set_config_item(name): global CAMERA # Handle getting the camera ensure_camera() if CAMERA == None: return 'The camera is not connected', 500 value = request.data.decode('UTF-8') # Get the config config = CAMERA.get_config() # Get the widget OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK != gp.GP_OK: CAMERA = None ensure_camera() # This will also not be okay if the camera disconnects return 'There are no widgets with the name of ' + name, 500 OK = gp.gp_widget_set_value(widget, value) if OK != gp.GP_OK: return 'Could not set the value', 500 OK = gp.gp_camera_set_config(CAMERA, config) if OK != gp.GP_OK: return 'Could not set the config', 500 return 'Value updated successfully'
def main(): # use Python logging logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) callback_obj = gp.check_result(gp.use_python_logging()) # get user value if len(sys.argv) != 2: print('One command line parameter required') return 1 try: value = int(sys.argv[1]) except: print('Integer parameter required') return 1 # open camera connection camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def set_config(self, config_name, value): self.log("Setting '{}' to '{}'".format(config_name, value)) config, widget = self._get_widget(config_name) gp.check_result(gp.gp_widget_set_value(widget, value)) gp.check_result( gp.gp_camera_set_config(self.camera, config, self.context)) self.log("Set '{}' to '{}'".format(config_name, value))
def update_exposure_settings(camera, speed=None, fnum=None, iso=None): ''' Set exposure combination. ''' # get config config = gp.check_result(gp.gp_camera_get_config(camera)) # update shutter speed if speed is not None: speed_cfg = gp.check_result( \ gp.gp_widget_get_child_by_name(config, 'shutterspeed')) gp.check_result(gp.gp_widget_set_value(speed_cfg, speed)) # update aperture if fnum is not None: fnum_cfg = gp.check_result( \ gp.gp_widget_get_child_by_name(config, 'f-number')) gp.check_result(gp.gp_widget_set_value(fnum_cfg, fnum)) # update iso if iso is not None: iso_cfg = gp.check_result( \ gp.gp_widget_get_child_by_name(config, 'iso')) gp.check_result(gp.gp_widget_set_value(iso_cfg, iso)) # write value. gp.check_result(gp.gp_camera_set_config(camera, config))
def set_camera_config(camera, exp, iso, f_val): if DEBUG: print('Getting previous camera configuration...', file=sys.stderr) camera_config = camera.get_config() error, exp_conf = gp.gp_widget_get_child_by_name(camera_config, 'shutterspeed') assert error == 0, "ERROR while retrieving current exposure" error, iso_conf = gp.gp_widget_get_child_by_name(camera_config, 'iso') assert error == 0, "ERROR while retrieving current ISO" error, f_conf = gp.gp_widget_get_child_by_name(camera_config, 'f-number') assert error == 0, "ERROR while retrieving current aperture" error = gp.check_result(gp.gp_widget_set_value(exp_conf, exp)) assert error == 0, "ERROR while setting exposure to {}".format(exp) error = gp.check_result(gp.gp_widget_set_value(iso_conf, iso)) assert error == 0, "ERROR while setting ISO to {}".format(iso) error = gp.check_result(gp.gp_widget_set_value(f_conf, f_val)) assert error == 0, "ERROR while setting aperture to {}".format(f_val) if DEBUG: print("Setting new camera configuration (exp {}, iso {}, f {})...". format(exp, iso, f_val), file=sys.stderr) error = gp.check_result(gp.gp_camera_set_config(camera, camera_config)) assert error == 0, "ERROR while setting camera configuration" if DEBUG: print('New camera configuration set', file=sys.stderr)
def main(): # use Python logging logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) callback_obj = gp.check_result(gp.use_python_logging()) # get user value if len(sys.argv) != 2: print('One command line parameter required') return 1 try: value = int(sys.argv[1]) except: print('Integer parameter required') return 1 # open camera connection camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def open(self): context = gp.Context() camera = gp.Camera() camera.init(context) config = camera.get_config(context) # find and check the image format config item ok, image_format = gp.gp_widget_get_child_by_name( config, 'imageformat') if ok >= gp.GP_OK: value = gp.check_result(gp.gp_widget_get_value(image_format)) if value == 'raw': raise RuntimeError('Cannot preview raw images!') # find and set the capture size class config item # this is required for some canon cameras and does not hurt for others ok, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if ok >= gp.GP_OK: value = gp.check_result( gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) gp.check_result(gp.gp_camera_set_config(camera, config, context)) self.context = context self.camera = camera self.config = config
def initCamera(): global camera global context print("Init camera") # SLR Setup # GPhoto init / testing context = gp.gp_context_new() error, camera = gp.gp_camera_new() error = gp.gp_camera_init(camera, context) error, text = gp.gp_camera_get_summary(camera, context) #print('Summary') #print('=======') #print(text.text) # required configuration will depend on camera type! print('Checking camera config') config = gp.check_result(gp.gp_camera_get_config(camera)) OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: value = gp.check_result(gp.gp_widget_get_value(image_format)) if 'raw' in value.lower(): print('Cannot preview raw images') # find the capture size class config item OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) gp.check_result(gp.gp_camera_set_config(camera, config))
def __init__(self, resolution=(320, 240), framerate=32, **kwargs): print("Init camera") # SLR Setup self.shotRequested = False # GPhoto init / testing self.context = gp.gp_context_new() self.error, self.camera = gp.gp_camera_new() self.error = gp.gp_camera_init(self.camera, self.context) self.error, self.text = gp.gp_camera_get_summary( self.camera, self.context) # required configuration will depend on camera type! print('Checking camera config') self.config = gp.check_result(gp.gp_camera_get_config(self.camera)) OK, image_format = gp.gp_widget_get_child_by_name( self.config, 'imageformat') if OK >= gp.GP_OK: value = gp.check_result(gp.gp_widget_get_value(image_format)) if 'raw' in value.lower(): print('Cannot preview raw images') # find the capture size class config item OK, capture_size_class = gp.gp_widget_get_child_by_name( self.config, 'capturesizeclass') if OK >= gp.GP_OK: value = gp.check_result( gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) gp.check_result(gp.gp_camera_set_config(self.camera, config)) self.frame = None self.shot = None self.stopped = False
def init_camera(self): self.log.debug("Init GPhoto2 camera") callback_obj = gp.check_result(gp.use_python_logging()) self.camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(self.camera)) # required configuration will depend on camera type! self.log.info('Checking camera config') # get configuration tree config = gp.check_result(gp.gp_camera_get_config(self.camera)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name( config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) # make sure it's not raw if 'raw' in value.lower(): self.log.error('Cannot preview raw images') return None # find the capture size class config item # need to set this on my Canon 350d to get preview to work at all OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result( gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(self.camera, config)) return True
def setPropertyTo(camera, parameter, index): config = getConfigurationOf(camera) capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, parameter)) value = gp.check_result(gp.gp_widget_get_choice(capture_target, index)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) gp.check_result(gp.gp_camera_set_config(camera, config)) return
def my_set(name, value): OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: widget_type = gp.check_result(gp.gp_widget_get_type(widget)) gp.check_result(gp.gp_widget_set_value(widget, value)) gp.check_result(gp.gp_camera_set_config(camera, config)) else: print("Error setting value %s for %s using widget %s" % (value, name, widget))
def _set_config_value_checked(self, name, value): value = str(value) ret = False for t in range(0, 20): try: config = gp.check_result( gp.gp_camera_get_config(self.camera, self.context)) OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: num = None choice_count = gp.check_result( gp.gp_widget_count_choices(widget)) logging.info("count %d", choice_count) for i in range(choice_count): vi = gp.check_result(gp.gp_widget_get_choice( widget, i)) if vi.lower() == value.lower(): num = i value = vi break try: if abs(float(vi) - float(value)) < 0.000001: value = vi num = i break except ValueError: pass try: if '/' in vi: fr = vi.split('/') fr = float(fr[0]) / float(fr[1]) if abs(fr - float(value)) < abs(fr * 0.001): value = vi num = i break except: pass if num is not None: logging.info("set %s => %s (choice %d)" % (name, value, num)) # set value gp.check_result(gp.gp_widget_set_value(widget, value)) ret = True else: logging.info("cant't set %s => %s" % (name, value)) # set config gp.check_result( gp.gp_camera_set_config(self.camera, config, self.context)) break except gp.GPhoto2Error as ex: logging.exception('failed') time.sleep(0.1) ret = False continue return ret
def set_config_value (camera, config, context, config_name, value): OK, config_child = gp.gp_widget_get_child_by_name(config,config_name) if OK >= gp.GP_OK: gp.check_result(gp.gp_widget_set_value(config_child, value)) gp.check_result(gp.gp_camera_set_config(camera, config, context)) return True else: return False
def _set_config_value(self, config, name, value): error, window = gp.gp_widget_get_child_by_name(config, name) gp.check_result(error) error = gp.gp_widget_set_value(window, value) gp.check_result(error) error = gp.gp_camera_set_config(self.camera, config) gp.check_result(error)
def set_capture_target(self, value): config = gp.check_result(gp.gp_camera_get_config(self.camera)) capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') value = 1 value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) gp.check_result(gp.gp_camera_set_config(self.camera, config)) gp.check_result(gp.gp_camera_exit(self.camera))
def app_capture_image(): global CAMERA # Handle getting the camera ensure_camera() if CAMERA == None: return 'The camera is not connected', 500 # Get the config config = CAMERA.get_config() # Get the widgets OK, capturetarget_widget = gp.gp_widget_get_child_by_name(config, 'capturetarget') if OK != gp.GP_OK: CAMERA = None ensure_camera() # This will also not be okay if the camera disconnects return 'There are no widgets with the name of capturetarget or the camera is disconnected', 500 OK, viewfinder_widget = gp.gp_widget_get_child_by_name(config, 'viewfinder') if OK != gp.GP_OK: CAMERA = None ensure_camera() # This will also not be okay if the camera disconnects return 'There are no widgets with the name of viewfinder or the camera is disconnected', 500 OK, imagequality_widget = gp.gp_widget_get_child_by_name(config, 'imagequality') if OK != gp.GP_OK: CAMERA = None ensure_camera() # This will also not be okay if the camera disconnects return 'There are no widgets with the name of imagequality or the camera is disconnected', 500 # Set the capture target to 'Memory card' OK = gp.gp_widget_set_value(capturetarget_widget, 'Memory card') if OK != gp.GP_OK: return 'Could not set the capture target to Memory card', 500 # Set the view finder to 0 (in case it it 1 from the capture preview) OK = gp.gp_widget_set_value(viewfinder_widget, 0) if OK != gp.GP_OK: return 'Could not set the view finder to 0', 500 # Set the image format back to 'NEF (Raw)' OK = gp.gp_widget_set_value(imagequality_widget, 'NEF (Raw)') if OK != gp.GP_OK: return 'Could not set the image quality to NEF (Raw)', 500 OK = gp.gp_camera_set_config(CAMERA, config) if OK != gp.GP_OK: return 'Could not update the camera configuration', 500 # Capture the image (to the memory card) CAMERA.capture(gp.GP_CAPTURE_IMAGE) return '', 301
def main(): logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.ERROR) gp.check_result(gp.use_python_logging()) camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # required configuration will depend on camera type! print('Checking camera config') # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) # make sure it's not raw if 'raw' in value.lower(): print('Cannot preview raw images') return 1 # find the capture size class config item # need to set this on my Canon 350d to get preview to work at all OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # capture preview image (not saved to camera memory card) print('Capturing preview image') for x in xrange(1,100): millis = int(round(time.time() * 1000)) camera_file = gp.check_result(gp.gp_camera_capture_preview(camera)) print("capture %d %s\n" % (int(round(time.time() * 1000)) - millis, camera_file)) file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) print("download %d\n" % (int(round(time.time() * 1000)) - millis)) data = memoryview(file_data) # display image #image = Image.open(io.BytesIO(file_data)) #image.show() gp.check_result(gp.gp_camera_exit(camera)) return 0
def set_parameter(self, parameter_name, set_value): error, parameter = gphoto2.gp_widget_get_child_by_name(self.config, parameter_name) if error < 0: print "Parameter does not exist" return if parameter_name != 'bulb' and parameter_name != 'capture': error, value = gphoto2.gp_widget_get_choice(parameter, set_value) else: error = 0 value = set_value if error < 0: print "Value out of range" return error = gphoto2.gp_widget_set_value(parameter, value) error = gphoto2.gp_camera_set_config(self.camera, self.config, self.context)
def set_config_value(self, name, value): for t in range(0, 20): try: config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context)) OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: print "set %s => %s" % (name, value) # set value gp.check_result(gp.gp_widget_set_value(widget, value)) # set config gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context)) break except gp.GPhoto2Error as ex: print ex.code time.sleep(0.1) continue
def focus(closer=True, small_step=False, custom=None, debug=False): config = camera.get_config() param = 'manualfocusdrive' if small_step: choice = near_small_step if closer else far_small_step else: choice = near if closer else far if custom: choice = custom widget = gp.check_result(gp.gp_widget_get_child_by_name(config, param)) value = gp.check_result(gp.gp_widget_get_choice(widget, choice)) if debug: print("value: {}".format(value), file=sys.stderr) gp.gp_widget_set_value(widget, value) return gp.gp_camera_set_config(camera, config, context)
def set_config(camera, context, config, path, value): """ Given a gphoto camera, context, and config traverse the path of the config tree and set a parameter value. The path is basically the nodes to address in the control structure. Once the config object has been modified we have to set it on the camera. """ current = config for p in path: current = current.get_child_by_name(p) current.acquire() current.set_value(value) current.disown() gp.check_result(gp.gp_camera_set_config(camera, config, context)) print "Set {0} to {1}".format(current.get_name(), current.get_value())
def getPicture(self): #restore the original shutterspeed changed in getPreview if (self.BrightPreview): config = self._cap.get_config() shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) gp.check_result(gp.gp_widget_set_value(shutterspeed, self._shutter)) gp.check_result(gp.gp_camera_set_config(self._cap, config)) self.FirstPreview = True file_path = self._cap.capture(gp.GP_CAPTURE_IMAGE) camera_file = self._cap.file_get(file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL) file_data = camera_file.get_data_and_size() return Image.open(io.BytesIO(file_data))
def set_capture_target(camera, value:int): config = gp.check_result(gp.gp_camera_get_config(camera)) # find the capture target config item capture_target = gp.check_result(gp.gp_widget_get_child_by_name(config, 'capturetarget')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(capture_target)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value value = gp.check_result(gp.gp_widget_get_choice(capture_target, value)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # clean up # gp.check_result(gp.gp_camera_exit(camera)) return 0
def take_a_pic(): logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # required configuration will depend on camera type! print('Checking camera config') # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) # make sure it's not raw if 'raw' in value.lower(): print('Cannot preview raw images') return 1 # find the capture size class config item # need to set this on my Canon 350d to get preview to work at all OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result( gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result( gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) # capture preview image (not saved to camera memory card) print('Capturing preview image') camera_file = gp.check_result( gp.gp_camera_capture_preview(camera)) file_data = gp.check_result( gp.gp_file_get_data_and_size(camera_file)) # display image data = memoryview(file_data) print(type(data), len(data)) print(data[:10].tolist()) image = Image.open(io.BytesIO(file_data)) image.show() gp.check_result(gp.gp_camera_exit(camera)) return image
def getPreview(self): #increase the shutterspeed for preview in case of using manual flash #TODO read this setting from config if (self.BrightPreview): config = self._cap.get_config() shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) #store the original value (allows to change the shutterspeed on the camera) if (self.FirstPreview): self._shutter = shutterspeed.get_value() self.FirstPreview = False #TODO read the shutterspeed for preview from config file gp.check_result(gp.gp_widget_set_value(shutterspeed, "1")) gp.check_result(gp.gp_camera_set_config(self._cap, config)) camera_file = self._cap.capture_preview() file_data = camera_file.get_data_and_size() return Image.open(io.BytesIO(file_data))
def __apply_settings(self, settings): """ takes dict of keys as option names and the corresponding values """ print '__apply_settings' for key, value in settings.items(): if key not in self.__config_dict: print 'camera: can not set %s '%(key,value) continue widget = self.__config_dict[key].get('_widget') if not widget: print 'camera: can not set %s '%(key,value) continue print key, value gp.check_result(gp.gp_widget_set_value(widget, value)) self.__config_dict[key]['_value']=value gp.check_result(gp.gp_camera_set_config( self.__camera, self.__config, self.__context))
def take_picture(imagedir): camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) config = gp.check_result(gp.gp_camera_get_config(camera)) capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) value = gp.check_result(gp.gp_widget_get_choice(capture_target, 1)) gp.check_result(gp.gp_widget_set_value(capture_target, value)) gp.check_result(gp.gp_camera_set_config(camera, config)) file_path = gp.check_result( gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE)) file_name = datetime.now().strftime('%y%m%d-%H%M%S-%f') + file_path.name target = join(imagedir, file_name) camera_file = gp.check_result( gp.gp_camera_file_get(camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)) gp.check_result(gp.gp_file_save(camera_file, target)) gp.check_result(gp.gp_camera_exit(camera)) return file_name
def getCamera(cameraNumber=0): logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) # make a list of all available cameras camera_list = [] for name, addr in gp.check_result(gp.gp_camera_autodetect()): camera_list.append((name, addr)) camera_list.sort(key=lambda x: x[0]) if len(camera_list) == 0: print("No cameras found") return None if cameraNumber < 0 or cameraNumber >= len(camera_list): print('Camera out of range') return None # initialise chosen camera name, addr = camera_list[cameraNumber] camera = gp.Camera() # search ports for camera port name port_info_list = gp.PortInfoList() port_info_list.load() idx = port_info_list.lookup_path(addr) camera.set_port_info(port_info_list[idx]) camera.init() config = gp.check_result(gp.gp_camera_get_config(camera)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config)) return camera
def main(): # use Python logging logging.basicConfig(format="%(levelname)s: %(name)s: %(message)s", level=logging.WARNING) gp.check_result(gp.use_python_logging()) # open camera connection camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the date/time setting config item and set it if set_datetime(config): # apply the changed config gp.check_result(gp.gp_camera_set_config(camera, config, context)) else: print("Could not set date & time") # clean up gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def set_config_value(self, field_name, field_value): """ Set configValue for given configField :param field_name: :param field_value: :return: """ try: # get configuration tree config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context)) # find the capture target config item config_target = gp.check_result(gp.gp_widget_get_child_by_name(config, str(field_name))) # value = gp.check_result(gp.gp_widget_get_choice(config_target, 2)) gp.check_result(gp.gp_widget_set_value(config_target, str(field_value))) # set config gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context)) logger.debug("set field_name:{}, field_value:{}".format(field_name, field_value)) except Exception as e: logger.debug(e.message)
def main(): logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) context = gp.gp_context_new() camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera, context)) # required configuration will depend on camera type! print('Checking camera config') # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) # make sure it's not raw if 'raw' in value.lower(): print('Cannot preview raw images') return 1 # find the capture size class config item # need to set this on my Canon 350d to get preview to work at all OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) # capture preview image (not saved to camera memory card) print('Capturing preview image') camera_file = gp.check_result(gp.gp_camera_capture_preview(camera, context)) file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) # display image data = memoryview(file_data) print(type(data), len(data)) print(data[:10].tolist()) image = Image.open(io.BytesIO(file_data)) image.show() gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def set_config_value_checked(self, name, value): value = str(value) ret = False for t in range(0, 20): try: config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context)) OK, widget = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: num = None choice_count = gp.check_result(gp.gp_widget_count_choices(widget)) print "count", choice_count for i in range(choice_count): vi = gp.check_result(gp.gp_widget_get_choice(widget, i)) if vi.lower() == value.lower(): num = i value = vi break try: if abs(float(vi) - float(value)) < 0.000001: value = vi num = i break except ValueError: pass if num is not None: print "set %s => %s (choice %d)" % (name, value, num) # set value gp.check_result(gp.gp_widget_set_value(widget, value)) ret = True else: print "cant't set %s => %s" % (name, value) # set config gp.check_result(gp.gp_camera_set_config(self.camera, config, self.context)) break except gp.GPhoto2Error as ex: print ex.code time.sleep(0.1) ret = False continue return ret
def main(): # use Python logging logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) callback_obj = gp.check_result(gp.use_python_logging()) # open camera connection camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) # get camera details abilities = gp.check_result(gp.gp_camera_get_abilities(camera)) # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera)) # find the date/time setting config item and set it if set_datetime(config, abilities.model): # apply the changed config gp.check_result(gp.gp_camera_set_config(camera, config)) else: print('Could not set date & time') # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def waitForCamera(context): showText(AREA_PREVIEW,"Warte auf Kamera ") pygame.display.flip() camera = gp.check_result(gp.gp_camera_new()) err=gp.gp_camera_init(camera, context) if (err < gp.GP_OK): if err != gp.GP_ERROR_MODEL_NOT_FOUND: # some other error we can't handle here raise gp.GPhoto2Error(err) return # required configuration will depend on camera type! print('Checking camera config') # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name(config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = gp.check_result(gp.gp_widget_get_value(image_format)) # make sure it's not raw if 'raw' in value.lower(): raise gp.GPhoto2Error('Cannot preview raw images') # find the capture size class config item # need to set this on my Canon 350d to get preview to work at all OK, capture_size_class = gp.gp_widget_get_child_by_name( config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = gp.check_result(gp.gp_widget_get_choice(capture_size_class, 2)) gp.check_result(gp.gp_widget_set_value(capture_size_class, value)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) OK,txt=gp.gp_camera_get_summary(camera,context) infod=txToDict(txt.text) showText(AREA_PREVIEW,infod.get('Model')) info.camera=infod.get('Model') pygame.display.flip() return camera
def __update_config(self): gp.check_result(gp.gp_camera_set_config( self.__camera, self.__config, self.__context))
def set_config(self): res = gp.gp_camera_set_config(self.camera, self.root.widget, self.context) gp.check_result(res)
def apply_changes(self): gp.check_result(gp.gp_camera_set_config( self.camera, self.camera_config)) QtWidgets.qApp.closeAllWindows()
def apply_changes(self): gp.check_result(gp.gp_camera_set_config( self.camera, self.camera_config, self.context)) QtGui.qApp.closeAllWindows()
def set_config_value(key, value, camera, context): config_widget = gp.check_result(gp.gp_camera_get_config(camera, context)) camera_widget_child = gp.check_result(gp.gp_widget_get_child_by_name(config_widget, key)) gp.check_result(gp.gp_widget_set_value(camera_widget_child, value)) gp.check_result(gp.gp_camera_set_config(camera, config_widget, context))