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 one_photo(camera, context, value, filename): # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the capture target config item shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(shutterspeed)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value)) gp.check_result(gp.gp_widget_set_value(shutterspeed, speedvalue)) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) print('Capturing image (shutterspeed=%d)' % value) file_path = gp.check_result(gp.gp_camera_capture( camera, gp.GP_CAPTURE_IMAGE, context)) target = filename+".jpg" camera_file = gp.check_result(gp.gp_camera_file_get( camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)) gp.check_result(gp.gp_file_save(camera_file, target))
def one_photo(camera, context, value, filename): # get configuration tree config = gp.check_result(gp.gp_camera_get_config(camera, context)) # find the capture target config item shutterspeed = gp.check_result( gp.gp_widget_get_child_by_name(config, 'shutterspeed')) # check value in range count = gp.check_result(gp.gp_widget_count_choices(shutterspeed)) if value < 0 or value >= count: print('Parameter out of range') return 1 # set value speedvalue = gp.check_result(gp.gp_widget_get_choice(shutterspeed, value)) gp.check_result( gp.gp_widget_set_value(shutterspeed, speedvalue) ) # set config gp.check_result(gp.gp_camera_set_config(camera, config, context)) print('Capturing image (shutterspeed=%d)' % value) file_path = gp.check_result( gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context)) target = filename + ".jpg" camera_file = gp.check_result( gp.gp_camera_file_get(camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL, context)) gp.check_result(gp.gp_file_save(camera_file, target))
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 get_exposure_bias(self): error, bias = gp.gp_widget_get_child_by_name(self.config,'exposurecompensation') if error !=0: print(error) print('get_exposure_bias: cannot read widget!') return else: self.bias = bias error, value = gp.gp_widget_get_value(bias) if error !=0: print(error) print('get_exposure_bias: cannot read value!') return count = gp.check_result(gp.gp_widget_count_choices(self.bias)) for choice in range(count): error, test = gp.gp_widget_get_choice(self.bias, choice) if test == value: break if error !=0: print(error) print('get_exposure_bias: cannot find choice!') return return choice, value
def get_iso(self): error, isovalue = gp.gp_widget_get_child_by_name(self.config,'iso') if error !=0: print(error) print('get_iso: cannot read widget!') return else: self.iso = isovalue error, value = gp.gp_widget_get_value(isovalue) if error !=0: print(error) print('get_iso: cannot read value!') return count = gp.check_result(gp.gp_widget_count_choices(self.iso)) for choice in range(count): error, test = gp.gp_widget_get_choice(self.iso, choice) if test == value: break if error !=0: print(error) print('get_iso: cannot find choice!') return return choice, value
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 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 get_exposure_time(self): error, exptime = gp.gp_widget_get_child_by_name(self.config,'shutterspeed2') if error !=0: print(error) print('get_exposure_time: cannot read widget!') return else: self.exptime = exptime error, value = gp.gp_widget_get_value(exptime) if error !=0: print(error) print('get_exposure_time: cannot read value!') return count = gp.check_result(gp.gp_widget_count_choices(self.exptime)) for choice in range(count): error, test = gp.gp_widget_get_choice(self.exptime, choice) if test == value: break if error !=0: print(error) print('get_exposure_time: cannot find choice!') return return choice, value
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 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 __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 __walk_config(self, widget, cfg, pname=''): child_count = gp.check_result(gp.gp_widget_count_children(widget)) for n in range(child_count): child = gp.check_result(gp.gp_widget_get_child(widget, n)) label = gp.check_result(gp.gp_widget_get_label(child)) name = gp.check_result(gp.gp_widget_get_name(child)) child_type = gp.check_result(gp.gp_widget_get_type(child)) _name = pname + '/' +name _cfg = {'_type':child_type,'_widget':child,'_label':label} if child_type != gp.GP_WIDGET_SECTION: value = gp.check_result(gp.gp_widget_get_value(child)) print label, name, value _cfg['_value'] = value if child_type == gp.GP_WIDGET_RADIO: _cfg['_choice'] = [] choice_count = gp.check_result(gp.gp_widget_count_choices(child)) for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(child, n)) if choice: _cfg['_choice'].append(choice) if child_type == gp.GP_WIDGET_RANGE: lo, hi, inc = gp.check_result(gp.gp_widget_get_range(child)) _cfg['_lo'] = lo _cfg['_hi'] = hi _cfg['_inc'] = inc cfg[_name]=_cfg self.__walk_config(child,cfg,pname=_name)
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 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 capture target config item capture_target = gp.check_result( gp.gp_widget_get_child_by_name(config, 'capturetarget')) # print current setting value = gp.check_result(gp.gp_widget_get_value(capture_target)) print('Current setting:', value) # print possible settings for n in range(gp.check_result( gp.gp_widget_count_choices(capture_target))): choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) print('Choice:', n, choice) # clean up gp.check_result(gp.gp_camera_exit(camera, context)) return 0
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 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 _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 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 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 get(self, config): assert count_children(config) == 0 # not sure layout = dict() options = list() value = get_value(config) layout['options'] = options layout['value'] = value choice_count = gp.check_result(gp.gp_widget_count_choices(config)) for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(config, n)) if choice: options.append(choice) return layout
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 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 __init__(self, config_changed, config, parent=None): QtGui.QComboBox.__init__(self, parent) self.config_changed = config_changed self.config = config if gp.check_result(gp.gp_widget_get_readonly(config)): self.setDisabled(True) assert gp.check_result(gp.gp_widget_count_children(config)) == 0 value = gp.check_result(gp.gp_widget_get_value(config)) choice_count = gp.check_result(gp.gp_widget_count_choices(config)) for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(config, n)) if choice: self.addItem(choice) if choice == value: self.setCurrentIndex(n) self.currentIndexChanged.connect(self.new_value)
def getAllChoiceFromParameter(camera, parameter): config = getConfigurationOf(camera) capture_target = getPropertyIn(config, parameter) for n in range(gp.check_result( gp.gp_widget_count_choices(capture_target))): choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) if not (cameraConfiguration.has_key(parameter)): cameraConfiguration[parameter] = {} if not (cameraTechnicalConfiguration.has_key(parameter)): cameraTechnicalConfiguration[parameter] = {} cameraConfiguration[parameter][choice] = n cameraTechnicalConfiguration[parameter][n] = choice return
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 set_config_choice(self, name, num): 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: # set value value = gp.check_result(gp.gp_widget_get_choice(widget, num)) print "set %s => %s" % (name, 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 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 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 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 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 __init__(self, config_changed, config, parent=None): QtGui.QWidget.__init__(self, parent) self.config_changed = config_changed self.config = config if gp.check_result(gp.gp_widget_get_readonly(config)): self.setDisabled(True) assert gp.check_result(gp.gp_widget_count_children(config)) == 0 self.setLayout(QtGui.QHBoxLayout()) value = gp.check_result(gp.gp_widget_get_value(config)) choice_count = gp.check_result(gp.gp_widget_count_choices(config)) self.buttons = [] for n in range(choice_count): choice = gp.check_result(gp.gp_widget_get_choice(config, n)) if choice: button = QtGui.QRadioButton(choice) self.layout().addWidget(button) if choice == value: button.setChecked(True) self.buttons.append((button, choice)) button.clicked.connect(self.new_value)
def preview(): 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() return 0
def preview_image(): callback_obj = 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 # camera dependent - 'imageformat' is 'imagequality' on some 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) image = cv2.imdecode(np.asarray(bytearray(data), dtype=np.uint8), 3) cv2.imshow("preview",image) cv2.waitKey() # image.show() gp.check_result(gp.gp_camera_exit(camera))
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 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 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')) # print current setting value = gp.check_result(gp.gp_widget_get_value(capture_target)) print('Current setting:', value) # print possible settings for n in range(gp.check_result(gp.gp_widget_count_choices(capture_target))): choice = gp.check_result(gp.gp_widget_get_choice(capture_target, n)) print('Choice:', n, choice) # clean up gp.check_result(gp.gp_camera_exit(camera)) return 0
def initUI(self): self.go_button = QtGui.QPushButton('GO!', self) self.stop_button = QtGui.QPushButton('Stop', self) iso_select = QtGui.QComboBox(self) shutter_select = QtGui.QComboBox(self) self.bulb_time = QtGui.QLineEdit(self) self.bulb_time.setText('1') self.bulb_pics = QtGui.QLineEdit(self) self.bulb_pics.setText('1') self.video_flag = QtGui.QCheckBox('Video', self) self.record_flag = QtGui.QCheckBox('Record', self) self.record_file = QtGui.QLineEdit(self) self.record_file.setText('') self.zoom_select = QtGui.QComboBox(self) self.reticle_flag = QtGui.QCheckBox('Reticle', self) self.solve_button = QtGui.QPushButton('Solve', self) self.solve_scale = QtGui.QComboBox(self) self.mount_button = QtGui.QPushButton('Update Mount', self) self.contours_flag = QtGui.QCheckBox('Contours', self) self.contours_slider = QtGui.QSlider(QtCore.Qt.Horizontal, self) self.contours_slider.setRange(0, 255) focuser_slider = QtGui.QSlider(QtCore.Qt.Vertical, self) focuser_slider.setRange(-255,255) self.image_label = QtGui.QLabel(self) self.text_line = QtGui.QLabel("Camera is ready", self) try: self.arduino = serial.Serial( port='/dev/ttyACM0', baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS) self.arduino.write('0') except: print "Focuser not found!" focuser_slider.setEnabled(False) self.myImage = QtGui.QImage((numpy.ones((768,512,3))*155).astype(numpy.uint8), 768, 512, QtGui.QImage.Format_RGB888) self.image_event = 1 grid = QtGui.QGridLayout() grid.setSpacing(5) grid.addWidget(QtGui.QLabel('ISO'), 0,0) grid.addWidget(QtGui.QLabel('Shutter'), 0,1) grid.addWidget(QtGui.QLabel('Bulb Time'), 0,2) grid.addWidget(QtGui.QLabel('Bulb Pics'), 0,3) grid.addWidget(QtGui.QLabel('Video File'), 0,6) grid.addWidget(QtGui.QLabel('Zoom'), 0,7) grid.addWidget(iso_select, 1,0) grid.addWidget(shutter_select, 1,1) grid.addWidget(self.bulb_time, 1,2) grid.addWidget(self.bulb_pics, 1,3) grid.addWidget(self.video_flag, 1,4) grid.addWidget(self.record_flag, 1,5) grid.addWidget(self.record_file, 1,6) grid.addWidget(self.zoom_select, 1, 7) grid.addWidget(self.reticle_flag, 1, 8) grid.addWidget(self.go_button, 2,0) grid.addWidget(self.stop_button, 2,1) grid.addWidget(self.solve_button, 2,3) grid.addWidget(self.solve_scale, 2,4) grid.addWidget(self.mount_button, 2,5) grid.addWidget(self.image_label, 3, 0, 1, 9) grid.addWidget(self.contours_flag, 2, 7) grid.addWidget(self.contours_slider, 2, 8) grid.addWidget(focuser_slider, 3,9) grid.addWidget(self.text_line, 4, 0, 1, 10) self.setLayout(grid) self.stop = threading.Event() iso_select.activated[str].connect(self.set_iso) shutter_select.activated[str].connect(self.set_shutter) self.video_flag.stateChanged.connect(self.set_video) self.go_button.clicked[bool].connect(self.go) self.stop_button.clicked[bool].connect(self.stop_actions) self.stop_button.setEnabled(False) self.record_flag.setEnabled(False) self.record_file.setEnabled(False) self.reticle_flag.setEnabled(False) self.contours_flag.setEnabled(False) self.contours_slider.setEnabled(False) self.zoom_select.setEnabled(False) self.solve_button.clicked[bool].connect(self.solve) self.mount_button.clicked[bool].connect(self.update_mount) self.solve_button.setEnabled(False) self.mount_button.setEnabled(False) self.solve_scale.setEnabled(False) focuser_slider.valueChanged[int].connect(self.focuser) iso_choiche = [] shutter_choiche = [] solve_scale_choiche = ['0.985', '0.255'] self.current_picture='IMG_0000.CR2' error = 0 set_value = 0 while (error == 0): error, value = gphoto2.gp_widget_get_choice(gphoto2.gp_widget_get_child_by_name(self.config, 'iso')[1], set_value) iso_choiche.append(value) set_value = set_value + 1 for i in iso_choiche[0:set_value-1]: iso_select.addItem(i) error=0 set_value = 0 while (error == 0): error, value = gphoto2.gp_widget_get_choice(gphoto2.gp_widget_get_child_by_name(self.config, 'shutterspeed')[1], set_value) shutter_choiche.append(value) set_value = set_value + 1 for i in shutter_choiche[0:set_value-1]: shutter_select.addItem(i) for i in solve_scale_choiche: self.solve_scale.addItem(i) self.zoom_select.addItem(str(1)) for i in range (2, 12, 2): self.zoom_select.addItem(str(i)) self.setGeometry(50, 50, -1 ,-1) self.setWindowTitle(self.camera_name) self.show()