def _set_config(self): # find the capture target item OK, capture_target = gp.gp_widget_get_child_by_name( self.config, 'capturetarget') if OK >= gp.GP_OK: if self.old_capturetarget is None: self.old_capturetarget = capture_target.get_value() choice_count = capture_target.count_choices() for n in range(choice_count): choice = capture_target.get_choice(n) if 'internal' in choice.lower(): # set config capture_target.set_value(choice) self.camera.set_config(self.config, self.context) break # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name( self.config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = image_format.get_value() # make sure it's not raw if 'raw' in value.lower(): print('Cannot preview raw images') return False return True
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 __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 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_config(self): # find the capture target item OK, capture_target = gp.gp_widget_get_child_by_name( self.config, 'capturetarget') if OK >= gp.GP_OK: if self.old_capturetarget is None: self.old_capturetarget = capture_target.get_value() choice_count = capture_target.count_choices() for n in range(choice_count): choice = capture_target.get_choice(n) if 'internal' in choice.lower(): # set config capture_target.set_value(choice) self.camera.set_config(self.config) break # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name( self.config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = image_format.get_value() # make sure it's not raw if 'raw' in value.lower(): print('Cannot preview raw images') return False return True
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 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 getCameraModel(self): camera_config = self.config OK, camera_model = gp.gp_widget_get_child_by_name( camera_config, 'cameramodel') if OK < gp.GP_OK: OK, camera_model = gp.gp_widget_get_child_by_name( camera_config, 'model') if OK >= gp.GP_OK: camera_model = camera_model.get_value() else: camera_model = '' return camera_model
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 get_camera_model(camera_config): # get the camera model OK, camera_model = gp.gp_widget_get_child_by_name(camera_config, 'cameramodel') if OK < gp.GP_OK: OK, camera_model = gp.gp_widget_get_child_by_name( camera_config, 'model') if OK >= gp.GP_OK: camera_model = camera_model.get_value() else: camera_model = '' return camera_model
def get_camera_model(self): camera_config = self.camera.get_config() # get the camera model OK, camera_model = gp.gp_widget_get_child_by_name( camera_config, 'cameramodel') if OK < gp.GP_OK: OK, camera_model = gp.gp_widget_get_child_by_name( camera_config, 'model') if OK >= gp.GP_OK: camera_model = camera_model.get_value() else: camera_model = 'unknown model' return camera_model
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_datetime(config): OK, sync_config = gp.gp_widget_get_child_by_name(config, 'syncdatetime') if OK >= gp.GP_OK: gp.check_result(gp.gp_widget_set_value(sync_config, 1)) return True 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
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 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 camera_find_by_serialnumber(self, serialnumber): logging.info( 'camera_find_by_serialnumber: ++ sn = {}'.format(serialnumber)) found = False ret = None try: cnt, cameras = gp.gp_camera_autodetect() for i in range(cnt): if len(cameras[i]) == 2: addr = cameras[i][1] port_info_list = gp.PortInfoList() port_info_list.load() idx = port_info_list.lookup_path(addr) c = gp.Camera() c.set_port_info(port_info_list[idx]) c.init() config = c.get_config() OK, sn = gp.gp_widget_get_child_by_name( config, 'serialnumber') if OK >= gp.GP_OK: sn_text = sn.get_value() if serialnumber == sn_text[-len(serialnumber):]: found = True ret = c if not found: c.exit() if found: break except: pass logging.info('camera_find_by_serialnumber: -- ret={}'.format(ret)) return ret
def test_focus_sweep(): camera = gp.Camera() camera.init() config = camera.get_config() OK, bulb_child = gp.gp_widget_get_child_by_name(config, 'bulb')
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 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 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 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 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 set_datetime(config): OK, sync_config = gp.gp_widget_get_child_by_name(config, "syncdatetime") if OK >= gp.GP_OK: gp.check_result(gp.gp_widget_set_value(sync_config, 1)) return True 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
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 get_config_value(self, name): 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_value(widget)) print "get %s => %s" % (name, value) return value
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 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 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 _get_config_value(self, config, name): error, conf_result = gp.gp_widget_get_child_by_name(config, name) gp.check_result(error) error, result = gp.gp_widget_get_value(conf_result) gp.check_result(error) return result
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(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 _reset_config(self): if self.old_capturetarget is not None: # find the capture target item OK, capture_target = gp.gp_widget_get_child_by_name( self.config, 'capturetarget') if OK >= gp.GP_OK: # set config capture_target.set_value(self.old_capturetarget) self.camera.set_config(self.config, self.context) self.old_capturetarget = None
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 _reset_config(self): if self.old_capturetarget is not None: # find the capture target item OK, capture_target = gp.gp_widget_get_child_by_name( self.config, 'capturetarget') if OK >= gp.GP_OK: # set config capture_target.set_value(self.old_capturetarget) self.camera.set_config(self.config) self.old_capturetarget = None
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(): 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 _check_config(self): # find the image format config item OK, image_format = gp.gp_widget_get_child_by_name( self.config, 'imageformat') if OK >= gp.GP_OK: # get current setting value = image_format.get_value() # make sure it's not raw if 'raw' in value.lower(): print('Cannot preview raw images') return False return True
def get_config_value(self, field_name): """ Get configValue for given configField :param field_name: :return: """ # 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))) # check value in range value = gp.check_result(gp.gp_widget_get_value(config_target)) return value
def set_datetime(config, model): if model == 'Canon EOS 100D': OK, date_config = gp.gp_widget_get_child_by_name(config, 'datetimeutc') if OK >= gp.GP_OK: now = int(time.time()) gp.check_result(gp.gp_widget_set_value(date_config, now)) return True OK, sync_config = gp.gp_widget_get_child_by_name(config, 'syncdatetime') if OK >= gp.GP_OK: gp.check_result(gp.gp_widget_set_value(sync_config, 1)) return True 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
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 __init__(self): self.do_next = QtCore.QEvent.registerEventType() super(CameraHandler, self).__init__() self.running = False # initialise camera self.context = gp.Context() self.camera = gp.Camera() self.camera.init(self.context) # get camera config tree self.config = self.camera.get_config(self.context) self.old_capturetarget = None # get the camera model OK, camera_model = gp.gp_widget_get_child_by_name( self.config, 'cameramodel') if OK < gp.GP_OK: OK, camera_model = gp.gp_widget_get_child_by_name( self.config, 'model') if OK >= gp.GP_OK: self.camera_model = camera_model.get_value() print('Camera model:', self.camera_model) else: print('No camera model info') self.camera_model = '' if self.camera_model == 'unknown': # 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( self.config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = capture_size_class.get_choice(2) capture_size_class.set_value(value) # set config self.camera.set_config(self.config, self.context) else: # put camera into preview mode to raise mirror gp.gp_camera_capture_preview(self.camera, self.context)
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 get it # name varies with camera driver # Canon EOS350d - 'datetime' # PTP - 'd034' for name, fmt in (('datetime', '%Y-%m-%d %H:%M:%S'), ('d034', None)): now = datetime.now() OK, datetime_config = gp.gp_widget_get_child_by_name(config, name) if OK >= gp.GP_OK: widget_type = gp.check_result(gp.gp_widget_get_type(datetime_config)) if widget_type == gp.GP_WIDGET_DATE: raw_value = gp.check_result( gp.gp_widget_get_value(datetime_config)) camera_time = datetime.fromtimestamp(raw_value) else: raw_value = gp.check_result( gp.gp_widget_get_value(datetime_config)) if fmt: camera_time = datetime.strptime(raw_value, fmt) else: camera_time = datetime.utcfromtimestamp(float(raw_value)) print('Camera clock: ', camera_time.isoformat(' ')) print('Computer clock:', now.isoformat(' ')) err = now - camera_time if err.days < 0: err = -err lead_lag = 'ahead' print('Camera clock is ahead by',) else: lead_lag = 'behind' print('Camera clock is %s by %d days and %d seconds' % ( lead_lag, err.days, err.seconds)) break else: print('Unknown date/time config item') # clean up gp.check_result(gp.gp_camera_exit(camera, context)) 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 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 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): self.do_next = QtCore.QEvent.registerEventType() super(CameraHandler, self).__init__() self.running = False # initialise camera self.context = gp.Context() self.camera = gp.Camera() self.camera.init(self.context) # get camera config tree self.config = self.camera.get_config(self.context) # 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( self.config, 'capturesizeclass') if OK >= gp.GP_OK: # set value value = capture_size_class.get_choice(2) capture_size_class.set_value(value) # set config self.camera.set_config(self.config, self.context)
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 get_parameter(self, parameter_name): error, parameter = gphoto2.gp_widget_get_child_by_name(self.config, parameter_name) if error < 0: print "Parameter does not exist" return return gphoto2.gp_widget_get_value(parameter)
def _get_widget(self, config_name): config = gp.check_result( gp.gp_camera_get_config(self.camera, self.context)) widget = gp.check_result( gp.gp_widget_get_child_by_name(config, config_name)) return config, widget
def get_config_value(key, 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)) config_value = gp.check_result(gp.gp_widget_get_value(camera_widget_child)) return config_value
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()
def get_config_value (config, config_name): OK, config_child = gp.gp_widget_get_child_by_name(config,config_name) if OK >= gp.GP_OK: value = gp.check_result(gp.gp_widget_get_value(config_child)) return value
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))