def start_photobooth(): ##for the first PIC preview(3,'r',1) if play_shutter_sound == 1: shutter_sound.play() #take the photos file_name=time.strftime("%d%m%Y_%H%M%S") for i, filename in enumerate(camera.capture_continuous(file_path + file_name + '-' + '{counter:02d}.jpg',use_video_port=False)): print(filename) if use_external_camera == 1: context = gp.gp_context_new() camera_ext = gp.check_result(gp.gp_camera_new()) error = gp.gp_camera_init(camera_ext, context) if error != gp.GP_ERROR_MODEL_NOT_FOUND: gp.gp_camera_capture(camera_ext, gp.GP_CAPTURE_IMAGE) gp.gp_camera_exit(camera_ext) if i == total_pics-1: #GPIO.output(led1_pin,False); break preview(3,'r',i+2) if play_shutter_sound == 1: shutter_sound.play() #show photos for pNum in range (1,total_pics+1): displayImage(file_path + file_name + '-0' + str(pNum) + '.jpg') text = 'photo ' + str(pNum) + ' of ' + str(total_pics) drawText(small_font, text, clear_screen=False, color=(255,255,255), y=15) time.sleep(5)
def connect(self): if self._camera is not None and self._context is not None: logging.warn('asked to connect over an opened connection, ignoring') return self.close_other_gphoto_processes() success = False tries = 1 while not success: try: logging.debug('trying to open a connection') self._camera = gp.check_result(gp.gp_camera_new()) self._context = gp.gp_context_new() success = True except Exception as ex: logging.debug('failed to open a connection', exc_info=True) if tries > 5: raise ex tries += 1 time.sleep(0.5) logging.debug('opened a new connection') return self
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print('Getting list of files') files = list_files(camera, context) if not files: print('No files found') return 1 path = files[0] print('Copying %s to memory' % path) folder, name = os.path.split(path) camera_file = gp.check_result(gp.gp_camera_file_get( camera, folder, name, gp.GP_FILE_TYPE_NORMAL, context)) file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) data = memoryview(file_data) print(type(data), len(data)) print(data[:10].tolist()) image = Image.open(io.BytesIO(file_data)) image.show() print('After deleting camera_file and file_data') del camera_file, file_data print(type(data), len(data)) print(data[:10].tolist()) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def takePhoto(self): context = gp.gp_context_new() camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera, context)) print("Capturing image") file_path = gp.check_result(gp.gp_camera_capture(camera, gp.GP_CAPTURE_IMAGE, context)) print("Camera file path: {0}/{1}".format(file_path.folder, file_path.name)) target = os.path.join("/tmp", file_path.name) print("Copying image to", target) 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)) gp.check_result(gp.gp_camera_exit(camera, context)) return target
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 initialize(self): """ Sets up the context needed by gphoto :return: None """ self.context = gp.gp_context_new()
def capture(save_path, filename): #log to be used by gphoto 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)) config = camera.get_config(context) target = config.get_child_by_name('viewfinder') target.set_value(1) camera.set_config(config, context) target.set_value(0) camera.set_config(config, context) time.sleep(2) #capture the image (to camera's internal SD card) file_path = gp.check_result(gp.gp_camera_capture( camera, gp.GP_CAPTURE_IMAGE)) #Copy the image over usb to the local filesystem target = os.path.join(save_path, filename) camera_file = gp.check_result(gp.gp_camera_file_get( camera, file_path.folder, file_path.name, gp.GP_FILE_TYPE_NORMAL)) gp.gp_file_save(camera_file, target) #exit the camera to complete the process gp.gp_camera_exit(camera) return 0
def main(): logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) computer_files = list_computer_files() camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print('Getting list of files from camera...') camera_files = list_camera_files(camera, context) if not camera_files: print('No files found') return 1 print('Copying files...') for path in camera_files: info = get_camera_file_info(camera, context, path) timestamp = datetime.fromtimestamp(info.file.mtime) folder, name = os.path.split(path) dest_dir = get_target_dir(timestamp) dest = os.path.join(dest_dir, name) if dest in computer_files: continue print('%s -> %s' % (path, dest_dir)) if not os.path.isdir(dest_dir): os.makedirs(dest_dir) camera_file = gp.check_result(gp.gp_file_new()) gp.check_result( gp.gp_camera_file_get(camera, folder, name, gp.GP_FILE_TYPE_NORMAL, camera_file, context)) gp.check_result(gp.gp_file_save(camera_file, dest)) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
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)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print('Summary') print('=======') print(text.text) print('Abilities') print('=========') abilities = gp.check_result(gp.gp_camera_get_abilities(camera)) print('model:', abilities.model) print('status:', abilities.status) print('port:', abilities.port) print('speed:', abilities.speed) print('operations:', abilities.operations) print('file_operations:', abilities.file_operations) print('folder_operations:', abilities.folder_operations) print('usb_vendor:', abilities.usb_vendor) print('usb_product:', abilities.usb_product) print('usb_class:', abilities.usb_class) print('usb_subclass:', abilities.usb_subclass) print('usb_protocol:', abilities.usb_protocol) print('library:', abilities.library) print('id:', abilities.id) print('device_type:', abilities.device_type) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print("Getting list of files") files = list_files(camera, context) if not files: print("No files found") return 1 path = files[0] print("Copying %s to memory" % path) folder, name = os.path.split(path) camera_file = gp.check_result(gp.gp_camera_file_get(camera, folder, name, gp.GP_FILE_TYPE_NORMAL, context)) # read file data using 'slurp' and a buffer allocated in Python info = gp.check_result(gp.gp_camera_file_get_info(camera, folder, name, context)) file_data = bytearray(info.file.size) count = gp.check_result(gp.gp_file_slurp(camera_file, file_data)) print(count, "bytes read") # or read data using 'get_data_and_size' which allocates its own buffer ## file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) data = memoryview(file_data) print(type(data), len(data)) print(data[:10].tolist()) image = Image.open(io.BytesIO(file_data)) image.show() print("After deleting camera_file and file_data") del camera_file, file_data print(type(data), len(data)) print(data[:10].tolist()) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print('Getting list of files') files = list_files(camera, context) if not files: print('No files found') return 1 path = files[0] print('Copying %s to memory in 100 kilobyte chunks' % path) folder, name = os.path.split(path) file_info = gp.check_result(gp.gp_camera_file_get_info( camera, folder, name, context)) data = bytearray(file_info.file.size) view = memoryview(data) chunk_size = 100 * 1024 offset = 0 while offset < len(data): bytes_read = gp.check_result(gp.gp_camera_file_read( camera, folder, name, gp.GP_FILE_TYPE_NORMAL, offset, view[offset:offset + chunk_size], context)) offset += bytes_read print(bytes_read) print(' '.join(map(str, data[0:10]))) image = Image.open(io.BytesIO(data)) image.show() gp.check_result(gp.gp_camera_exit(camera, context)) return 0
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 main(argv=None): if argv is None: argv = sys.argv 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) storage_info = gp.check_result( gp.gp_camera_get_storageinfo(camera, context)) if len(storage_info) > 1: print('Unable to handle camera with multiple storage media') return 1 if len(storage_info) == 0: print('No storage info available') return 2 si = storage_info[0] if not (si.fields & gp.GP_STORAGEINFO_MAXCAPACITY and si.fields & gp.GP_STORAGEINFO_FREESPACEKBYTES): print('Cannot read storage capacity') return 3 print('Camera has %.1f%% free space' % (100.0 * float(si.freekbytes) / float(si.capacitykbytes))) if len(argv) < 2: return 4 if len(argv) > 2: print('usage: %s [percent_to_clear]' % argv[0]) return 5 target = float(argv[1]) / 100.0 target = int(target * float(si.capacitykbytes)) free_space = si.freekbytes if free_space >= target: print('Sufficient free space') return 0 print('Getting file list...') files = list_files(camera, context) mtime = {} size = {} for path in files: info = get_file_info(camera, context, path) mtime[path] = info.file.mtime size[path] = info.file.size files.sort(key=lambda x: mtime[x], reverse=True) while True: while files and free_space < target: path = files.pop() print('Delete', path) delete_file(camera, context, path) free_space += size[path] // 1000 storage_info = gp.check_result( gp.gp_camera_get_storageinfo(camera, context)) si = storage_info[0] print('Camera has %.1f%% free space' % (100.0 * float(si.freekbytes) / float(si.capacitykbytes))) free_space = si.freekbytes if free_space >= target: break gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def __init__(self): print "init AstroCamCanon" gp.check_result(gp.use_python_logging()) self.context = gp.gp_context_new() self.camera = gp.check_result(gp.gp_camera_new()) print "config" camera_config = gp.check_result(gp.gp_camera_get_config(self.camera, self.context)) child_count = gp.check_result(gp.gp_widget_count_children(camera_config)) print child_count for n in range(child_count): try: print "============" child = gp.check_result(gp.gp_widget_get_child(camera_config, n)) name = gp.check_result(gp.gp_widget_get_name(child)) print name chtype = gp.check_result(gp.gp_widget_get_type(child)) print chtype ro = gp.check_result(gp.gp_widget_get_readonly(child)) print ro cdildcen = gp.check_result(gp.gp_widget_count_children(child)) print cdildcen except Exception, e: print e
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) files = list_files(camera, context) if not files: print('No files found') return 1 print('File list') print('=========') for path in files[:10]: print(path) print('...') for path in files[-10:]: print(path) info = get_file_info(camera, context, files[-1]) print print('File info') print('=========') print('image dimensions:', info.file.width, info.file.height) print('image type:', info.file.type) print('file mtime:', datetime.fromtimestamp(info.file.mtime).isoformat(' ')) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def info(): context = gp_context_new() error, camera = gp_camera_new() error = gp_camera_init(camera, context) error, text = gp_camera_get_summary(camera, context) error = gp_camera_exit(camera, context) return text.text
def open_camera(): """ context manager to control access to the camera resource """ camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) yield camera, context gp.check_result(gp.gp_camera_exit(camera, context))
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 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() if hasattr(gp, 'gp_camera_autodetect'): # gphoto2 version 2.5+ cameras = gp.check_result(gp.gp_camera_autodetect(context)) else: port_info_list = gp.check_result(gp.gp_port_info_list_new()) gp.check_result(gp.gp_port_info_list_load(port_info_list)) abilities_list = gp.check_result(gp.gp_abilities_list_new()) gp.check_result(gp.gp_abilities_list_load(abilities_list, context)) cameras = gp.check_result( gp.gp_abilities_list_detect(abilities_list, port_info_list, context)) n = 0 for name, value in cameras: print('camera number', n) print('===============') print(name) print(value) print() n += 1 return 0
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) files = list_files(camera, context) if not files: print('No files found') return 1 print('File list') print('=========') for path in files[:10]: print(path) print('...') for path in files[-10:]: print(path) info = get_file_info(camera, context, files[-1]) print print('File info') print('=========') print('image dimensions:', info.file.width, info.file.height) print('image type:', info.file.type) print('file mtime:', datetime.fromtimestamp(info.file.mtime).isoformat(' ')) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print('Getting list of files') files = list_files(camera, context) if not files: print('No files found') return 1 path = files[0] print('Copying %s to memory in 100 kilobyte chunks' % path) folder, name = os.path.split(path) file_info = gp.check_result( gp.gp_camera_file_get_info(camera, folder, name, context)) data = bytearray(file_info.file.size) view = memoryview(data) chunk_size = 100 * 1024 offset = 0 while offset < len(data): bytes_read = gp.check_result( gp.gp_camera_file_read(camera, folder, name, gp.GP_FILE_TYPE_NORMAL, offset, view[offset:offset + chunk_size], context)) offset += bytes_read print(bytes_read) print(' '.join(map(str, data[0:10]))) image = Image.open(io.BytesIO(data)) image.show() gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def main(): logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) computer_files = list_computer_files() camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print('Getting list of files from camera...') camera_files = list_camera_files(camera, context) if not camera_files: print('No files found') return 1 print('Copying files...') for path in camera_files: info = get_camera_file_info(camera, context, path) timestamp = datetime.fromtimestamp(info.file.mtime) folder, name = os.path.split(path) dest_dir = get_target_dir(timestamp) dest = os.path.join(dest_dir, name) if dest in computer_files: continue print('%s -> %s' % (path, dest_dir)) if not os.path.isdir(dest_dir): os.makedirs(dest_dir) camera_file = gp.check_result(gp.gp_file_new()) gp.check_result(gp.gp_camera_file_get( camera, folder, name, gp.GP_FILE_TYPE_NORMAL, camera_file, context)) gp.check_result(gp.gp_file_save(camera_file, dest)) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def open(self): self.context = gp.gp_context_new() error, camera = gp.gp_camera_new() gp.check_result(error) if self.port is not None: error = gp.gp_camera_set_port_info(camera, self.port) gp.check_result(error) error = gp.gp_camera_init(camera, self.context) gp.check_result(error) self.camera = camera # create image (sub-)directory self.image_directory = os.path.join(self.image_base_directory, "cam_" + self.get_serialnumber()) try: os.makedirs(self.image_directory) except FileExistsError as e: pass status = self.get_exposure_status() if status["expprogram"] == "A": self.exposure_mode = self.MODE_APERTURE_PRIORITY elif status["expprogram"] == "M": self.exposure_mode = self.MODE_MANUAL else: self.exposure_mode = self.MODE_UNKNOWN self.state = self.STATE_CONNECTED
def main(): 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) print('Getting list of files') files = list_files(camera, context) if not files: print('No files found') return 1 path = files[0] print('Copying %s to memory' % path) folder, name = os.path.split(path) camera_file = gp.check_result(gp.gp_camera_file_get( camera, folder, name, gp.GP_FILE_TYPE_NORMAL, context)) data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) print(type(data), len(data)) if six.PY2: print(map(ord, data[0:10])) image = Image.open(StringIO.StringIO(data)) else: print(data[0:10]) image = Image.open(io.BytesIO(data)) image.show() print('After deleting camera_file') del camera_file print(type(data), len(data)) if six.PY2: print(map(ord, data[0:10])) else: print(data[0:10]) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def main(argv=None): if argv is None: argv = sys.argv 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()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) storage_info = gp.check_result(gp.gp_camera_get_storageinfo(camera, context)) if len(storage_info) > 1: print('Unable to handle camera with multiple storage media') return 1 if len(storage_info) == 0: print('No storage info available') return 2 si = storage_info[0] if not (si.fields & gp.GP_STORAGEINFO_MAXCAPACITY and si.fields & gp.GP_STORAGEINFO_FREESPACEKBYTES): print('Cannot read storage capacity') return 3 print('Camera has %.1f%% free space' % ( 100.0 * float(si.freekbytes) / float(si.capacitykbytes))) if len(argv) < 2: return 4 if len(argv) > 2: print('usage: %s [percent_to_clear]' % argv[0]) return 5 target = float(argv[1]) / 100.0 target = int(target * float(si.capacitykbytes)) free_space = si.freekbytes if free_space >= target: print('Sufficient free space') return 0 print('Getting file list...') files = list_files(camera, context) mtime = {} size = {} for path in files: info = get_file_info(camera, context, path) mtime[path] = info.file.mtime size[path] = info.file.size files.sort(key=lambda x: mtime[x], reverse=True) while True: while files and free_space < target: path = files.pop() print('Delete', path) delete_file(camera, context, path) free_space += size[path] // 1000 storage_info = gp.check_result( gp.gp_camera_get_storageinfo(camera, context)) si = storage_info[0] print('Camera has %.1f%% free space' % ( 100.0 * float(si.freekbytes) / float(si.capacitykbytes))) free_space = si.freekbytes if free_space >= target: break gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def initCam(): global context, camera 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))
def __init__(self, model=None): self.model = model if self.model == "canonEOS": gp.check_result(gp.use_python_logging()) self.context = gp.gp_context_new() self.camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(self.camera, self.context))
def initCam(): global context, camera 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))
def test_camera(): global camera, context, config, camera_config_name, camera_config print("Testing Camera") 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_list = [] for name, addr in context.camera_autodetect(): camera_list.append((name, addr)) if not camera_list: print('No camera detected') return 1 camera_list.sort(key=lambda x: x[0]) name, addr = camera_list[0] camera = gp.Camera() #camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera, context)) config = gp.check_result(gp.gp_camera_get_config(camera, context)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print('Summary') print('=======') print(text.text) print('Abilities') print('=========') abilities = gp.check_result(gp.gp_camera_get_abilities(camera)) print('model:', abilities.model) print('status:', abilities.status) print('port:', abilities.port) print('speed:', abilities.speed) print('operations:', abilities.operations) print('file_operations:', abilities.file_operations) print('folder_operations:', abilities.folder_operations) print('usb_vendor:', abilities.usb_vendor) print('usb_product:', abilities.usb_product) print('usb_class:', abilities.usb_class) print('usb_subclass:', abilities.usb_subclass) print('usb_protocol:', abilities.usb_protocol) print('library:', abilities.library) print('id:', abilities.id) print('device_type:', abilities.device_type) child_count = gp.check_result(gp.gp_widget_count_children(config)) if child_count < 1: return tabs = None for n in range(child_count): child = gp.check_result(gp.gp_widget_get_child(config, n)) camera_config.append(getConfig(child)) label = gp.check_result(gp.gp_widget_get_label(child)) camera_config_name.append(label) print('!!!!!!! CONFIG ', child, label) name = gp.check_result(gp.gp_widget_get_name(child)) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def main(): logging.basicConfig( format='%(levelname)s: %(name)s: %(message)s', level=logging.CRITICAL) gp.check_result(gp.use_python_logging()) camera = gp.check_result(gp.gp_camera_new()) context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(camera, context)) trigger_capture(camera, context, 'image.jpg') gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def initialise(self): # get camera config tree self.camera = gp.check_result(gp.gp_camera_new()) self.context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(self.camera, self.context)) self.camera_config = gp.check_result( gp.gp_camera_get_config(self.camera, self.context)) # create corresponding tree of tab widgets self.setWindowTitle( gp.check_result(gp.gp_widget_get_label(self.camera_config))) self.centralWidget().layout().addWidget( SectionWidget(self.config_changed, self.camera_config), 0, 0, 1, 3)
def initialise(self): # get camera config tree self.camera = gp.check_result(gp.gp_camera_new()) self.context = gp.gp_context_new() gp.check_result(gp.gp_camera_init(self.camera, self.context)) self.camera_config = gp.check_result( gp.gp_camera_get_config(self.camera, self.context)) # create corresponding tree of tab widgets self.setWindowTitle( gp.check_result(gp.gp_widget_get_label(self.camera_config))) self.centralWidget().layout().addWidget(SectionWidget( self.config_changed, self.camera_config), 0, 0, 1, 3)
def setup(): """ Attempt to attach to a gphoto device and grab the camera and context. Return the results. """ 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)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print text.text return camera, context
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)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print('Summary') print('=======') print(text.text) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def init_camera(**kwd_args): context = gp.gp_context_new() error, camera = gp.gp_camera_new() error = gp.gp_camera_init(camera, context) if DEBUG: error, summary = gp.gp_camera_get_summary(camera, context) print('Summary', file=sys.stderr) print('=======', file=sys.stderr) print(summary.text, file=sys.stderr) return camera
def setup(): """ Attempt to attach to a gphoto device and grab the camera and context. Return the results. """ 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)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print text.text return camera, context
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)) text = gp.check_result(gp.gp_camera_get_summary(camera, context)) print('Summary') print('=======') print(text.text) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
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_list = gp.check_result(gp.gp_camera_autodetect(context)) # loop through camera list for index, (name, addr) in enumerate(camera_list): print('{:s} {:s}'.format(addr, name)) return 0
def __init__(self): logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING) gp.check_result(gp.use_python_logging()) self.context = gp.gp_context_new() self.camera = gp.check_result(gp.gp_camera_new()) try: gp.check_result(gp.gp_camera_init(self.camera, self.context)) self.isCameraPresent = True except: print("WARN : fail to init gphoto camera !") self.isCameraPresent = False
def open_camera(self): # the following needs to be changed into some # kind of context manager aware delay to allow # the camera to get ready in a context manager release_from_tight_grip_of_operating_system() ctx = gp.gp_context_new() error, camera = gp.gp_camera_new() gp.check_result(gp.gp_camera_init(camera, ctx)) # TODO: check if camera cannot be used for some reason self._camera = camera self._context = ctx
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 find_camera(self): context = gp.gp_context_new() port_info_list = gp.check_result(gp.gp_port_info_list_new()) gp.check_result(gp.gp_port_info_list_load(port_info_list)) abilities_list = gp.check_result(gp.gp_abilities_list_new()) gp.check_result(gp.gp_abilities_list_load(abilities_list, context)) self._cameras = gp.check_result( gp.gp_abilities_list_detect(abilities_list, port_info_list, context)) found_device = False for name, value in self._cameras: logger.debug("%s, %s" % (name, value)) found_device = True return found_device
def init(): context = gp.gp_context_new() error, file = gp.gp_file_new() error, camera = gp.gp_camera_new() error = gp.gp_camera_init(camera, context) error, text = gp.gp_camera_get_summary(camera, context) gp.gp_camera_capture(camera, 0, context) print('Summary') print('=======') print(text.text) print(gp.gp_result_as_string(error)) print("start") return camera, context
def __init__(self): """ Initialise the camera :return: """ try: self.camera = gp.check_result(gp.gp_camera_new()) self.context = gp.gp_context_new() self.path_root = '/camera/imgCap/' self.path_single = '/camera/imgCap/single/' self.path_hdr3 = '/camera/imgCap/hdr3/' self.path_hdr5 = '/camera/imgCap/hdr5/' except Exception as e: logger.error(e.message)
def __init_camera(self): error, self.__camera = gp.gp_camera_new() self.__context = gp.gp_context_new() error = gp.gp_camera_init(self.__camera, self.__context) error, text = gp.gp_camera_get_summary(self.__camera, self.__context) #print('Summary') #('=======') #print(text.text) self.__config = gp.check_result(gp.gp_camera_get_config(self.__camera, self.__context)) self.__config_dict = OrderedDict() self.__walk_config(self.__config,self.__config_dict) self.print_settings() self.__watcher = QtCore.QFileSystemWatcher([self.__cfg_file_path], self) self.__watcher.fileChanged.connect(self.load_settings) self.load_settings(self.__cfg_file_path)
def __init__(self, name = "My Camera", camera = None, context = None, controlfocus = False): self.name = name if context is None: self.context = gp.gp_context_new() else: self.context = context if camera is None: self.camera = gp.check_result(gp.gp_camera_new()); else: self.camera = camera self.logger = logging.getLogger(self.name) self.controlfocus = controlfocus self.in_preview = False gp.check_result(gp.gp_camera_init(self.camera, self.context))
def __init__(self, mpstate): """Initialise module""" super(llcamera, self).__init__(mpstate, "example", "") self.status_callcount = 0 self.boredom_interval = 10 # seconds self.last_bored = time.time() self.packets_mytarget = 0 self.packets_othertarget = 0 self.verbose = False self.example_settings = mp_settings.MPSettings( [ ('verbose', bool, False), ]) self.add_command('llcamera', self.cmd_example, "llcamera module", ['status','set (LOGSETTING)']) self.context = gp.gp_context_new() self.camera = gp.check_result(gp.gp_camera_new()) self.path = datetime.datetime.now().strftime("%Y_%m_%d_%H_%M") self.targetPath = os.path.join('/home/ubuntu/Pictures', self.path) self.vehicleLat = 0.0 # Current Vehicle Latitude self.vehicleLon = 0.0 # Current Vehicle Longitude self.vehicleHdg = 0.0 # Current Vehicle Heading self.vehicleAMSL = 0.0 # Current Vehicle Altitude above mean sea level self.vehicleRoll = 0.0 # Current Vehicle Roll self.vehiclePitch = 0.0 # Current Vehicle Pitch self.vehicleYaw = 0.0 self.imageLogFilePath = os.path.join(self.targetPath, 'log_' + self.path + '.txt') print(self.imageLogFilePath) if not os.path.exists(self.targetPath): os.makedirs(self.targetPath) file = open(self.imageLogFilePath, 'w') file.write('Filename\tLatitude\tLongitude\tAlt (AMSL)\tRoll\tPitch\tYaw\n') file.close() while True: try: self.camera.init(self.context) except gp.GPhoto2Error as ex: if ex.code == gp.GP_ERROR_MODEL_NOT_FOUND: # no camera, try again in 2 seconds time.sleep(2) continue # some other error we can't handle here raise # operation completed successfully so exit loop break # continue with rest of program print('Camera connected.')
def connect(self): self.context = gp.gp_context_new() print self.context self.camera = gp.check_result(gp.gp_camera_new()) print self.camera gp.check_result(gp.gp_camera_init(self.camera, self.context)) text = gp.check_result(gp.gp_camera_get_summary(self.camera, self.context)) print('Summary') print('=======') print(text.text) print('Abilities') print('=========') abilities = gp.check_result(gp.gp_camera_get_abilities(self.camera)) print('model:', abilities.model) print('status:', abilities.status) print('port:', abilities.port) print('speed:', abilities.speed) print('operations:', abilities.operations) print('file_operations:', abilities.file_operations) print('folder_operations:', abilities.folder_operations) print('usb_vendor:', abilities.usb_vendor) print('usb_product:', abilities.usb_product) print('usb_class:', abilities.usb_class) print('usb_subclass:', abilities.usb_subclass) print('usb_protocol:', abilities.usb_protocol) print('library:', abilities.library) print('id:', abilities.id) print('device_type:', abilities.device_type) print "--------------" print abilities rospy.set_param('AROM_camera/%s/model' %(self.name), abilities.model) rospy.set_param('AROM_camera/%s/config' %(self.name), {'name': self.arg['name'], 'civil_name': self.arg['civil_name'], 'driver': self.arg['driver'], 'model': abilities.model, '#main':{ '@capture': {'type': 'button', 'msg_name': 'capture'}, '@Shutter_speed': {'type': 'select', 'msg_name': 'shutter_speed', 'value': {'0': "1/4000", '1': "1/1000", '2': "1/800"}}, '@ISO': {'type': 'select', 'msg_name': 'gain', 'value': {'0': "AUTO", '1': "100", '2': "200"}}, '@ISO': {'type': 'select', 'msg_name': 'gain', 'value': {'0': "AUTO", '1': "100", '2': "200"}} } } )
def takePicture(): context = gp.gp_context_new() error, camera = gp.gp_camera_new() error = gp.gp_camera_init(camera, context) capturetype = gp.GP_CAPTURE_IMAGE error, path = gp.gp_camera_capture(camera, capturetype, context) filetype = gp.GP_FILE_TYPE_NORMAL #http://www.gphoto.org/doc/api/gphoto2-file_8h.html#ab9f339bdf374343272c62d2352753d69 error, file = gp.gp_camera_file_get(camera, path.folder, path.name, filetype, context) error = gp.gp_file_save(file, '/albums/default/' + path.name) error = gp.gp_camera_exit(camera, context) raw = rawpy.imread(path.name) rgb = raw.postprocess() convertedName = path.name[0:(path.name.index('.'))] + '.jpg' imageio.imwrite(convertedName, rgb) #want to redirect to displaying the downloaded image return redirect(url_for('displayPicture', id=convertedName))
def capture(downloadPath, resultFile, showImage): context = gp.gp_context_new() camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera, context)) print('Capturing image') file_path = gp.check_result(gp.gp_camera_capture( camera, gp.GP_CAPTURE_IMAGE, context)) print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name)) target = downloadPath+"/"+resultFile print('Copying image to', target) 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)) if (showImage): subprocess.call(['xdg-open', target]) gp.check_result(gp.gp_camera_exit(camera, context)) return True
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 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 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)) print('Capturing image') file_path = gp.check_result(gp.gp_camera_capture( camera, gp.GP_CAPTURE_IMAGE, context)) print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name)) target = os.path.join('/tmp', file_path.name) print('Copying image to', target) 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)) subprocess.call(['xdg-open', target]) gp.check_result(gp.gp_camera_exit(camera, context)) return 0
def initCamera(self): self.context = gphoto2.gp_context_new() error, self.camera = gphoto2.gp_camera_new() error = gphoto2.gp_camera_init(self.camera, self.context) if error != 0: print "Init error!" quit() self.camera_name = self.context.camera_autodetect()[0][0] error, self.config = gphoto2.gp_camera_get_config(self.camera, self.context) self.set_parameter('imageformat', 7) # 0 to 7 self.set_parameter('iso', 0) # 0 to 5 self.set_parameter('whitebalance', 7) # 0 to 7 self.set_parameter('whitebalanceadjusta', 0) # 0 to 18 self.set_parameter('whitebalanceadjustb', 0) # 0 to 18 self.set_parameter('shutterspeed', 0) # 0 to 52 self.set_parameter('picturestyle', 0) # 0 to 8 self.set_parameter('drivemode', 0) # 0 to 4 self.set_parameter('autoexposuremode', 3) # 0 to 15 self.set_parameter('colorspace', 0) # 0 to 1 self.set_parameter('meteringmode', 2) # 0 to 2
def get_all_cameras(): # Ugh, C libraries >.< # Get all available ports portinfolist = gp.check_result(gp.gp_port_info_list_new()) gp.check_result(gp.gp_port_info_list_load(portinfolist)) # Get all available cameras and a string of their port context = gp.gp_context_new() camlist = gp.check_result(gp.gp_camera_autodetect(context)) cameralist = [] for i in range(camlist.count()): camname = camlist.get_name(i) camport = camlist.get_value(i) # Find port info for this camera portindex = portinfolist.lookup_path(camport) portinfo = portinfolist.get_info(portindex) # Create camera object and associate with given port cam = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_set_port_info(cam, portinfo)) myCamera = Camera("{} ({})".format(camname, camport), cam, context) cameralist.append(myCamera) return cameralist