How to use the gphoto2.gp_camera_file_get function in gphoto2

To help you get started, we’ve selected a few gphoto2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jim-easterbrook / python-gphoto2 / examples / copy-data.py View on Github external
def main():
    logging.basicConfig(
        format='%(levelname)s: %(name)s: %(message)s', level=logging.WARNING)
    callback_obj = gp.check_result(gp.use_python_logging())
    camera = gp.check_result(gp.gp_camera_new())
    gp.check_result(gp.gp_camera_init(camera))
    print('Getting list of files')
    files = list_files(camera)
    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))
##    # read file data using 'slurp' and a buffer allocated in Python
##    info = gp.check_result(
##        gp.gp_camera_file_get_info(camera, folder, name))
##    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
github jim-easterbrook / python-gphoto2 / examples / copy-files.py View on Github external
if not camera_files:
        print('No files found')
        return 1
    print('Copying files...')
    for path in camera_files:
        info = get_camera_file_info(camera, 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_camera_file_get(
            camera, folder, name, gp.GP_FILE_TYPE_NORMAL))
        gp.check_result(gp.gp_file_save(camera_file, dest))
    gp.check_result(gp.gp_camera_exit(camera))
    return 0
github greiginsydney / Intervalometerator / Raspberry Pi / www / intvlm8r.py View on Github external
with open(iniFile, 'w') as config_file:
                config.write(config_file)
            app.logger.debug('Added deleteAfterCopy flag to the INI file, after error : ' + str(e))
        except Exception as e:
            app.logger.debug('Exception thrown trying to add deleteAfterCopy to the INI file : ' + str(e))
        deleteAfterCopy = False
    
    for path in camera_files:
        sourceFolderTree, imageFileName = os.path.split(path)
        dest = CreateDestPath(sourceFolderTree, PI_PHOTO_DIR)
        dest = os.path.join(dest, imageFileName)
        if dest in computer_files:
            continue
        app.logger.debug('Copying {0} --> {1}'.format(path, dest))
        try:
            camera_file = gp.check_result(gp.gp_camera_file_get(
                camera, sourceFolderTree, imageFileName, gp.GP_FILE_TYPE_NORMAL))
            copyOK = gp.check_result(gp.gp_file_save(camera_file, dest))
            if ((copyOK >= gp.GP_OK) and (deleteAfterCopy == True)):
                gp.check_result(gp.gp_camera_file_delete(camera, sourceFolderTree, imageFileName))
                app.logger.debug('Deleted {0}/{1}'.format(sourceFolderTree, imageFileName))
        except Exception as e:
            app.logger.debug('Exception in copy_files: ' + str(e))
    return 0
github greiginsydney / Intervalometerator / Raspberry Pi / intvlm8r.py View on Github external
if not camera_files:
        app.logger.debug('No files found')
        return 1
    app.logger.debug('Copying files...')

    if not os.path.isdir(PI_PHOTO_DIR):
        os.makedirs(PI_PHOTO_DIR)

    for path in camera_files:
        sourceFolderTree, imageFileName = os.path.split(path)
        dest = CreateDestPath(sourceFolderTree, PI_PHOTO_DIR)
        dest = os.path.join(dest, imageFileName)
        if dest in computer_files:
            continue
        app.logger.debug('Copying %s --> %s' % (path, dest))
        camera_file = gp.check_result(gp.gp_camera_file_get(
            camera, sourceFolderTree, imageFileName, gp.GP_FILE_TYPE_NORMAL))
        gp.check_result(gp.gp_file_save(camera_file, dest))
    return 0
github florisvb / multi_tracker / nodes / trigger_gphoto2_camera.py View on Github external
def gphoto_callback(self, msg):

        file_path = gp.check_result(gp.gp_camera_capture(
            self.camera, gp.GP_CAPTURE_IMAGE, self.context))
        print('Camera file path: {0}/{1}'.format(file_path.folder, file_path.name))

        print('Captured image')
        t = rospy.Time.now()
        time_base = time.strftime("%Y%m%d_%H%M%S_N" + self.nodenum, time.localtime())
        print time_base
        name = time_base + '_' + str(t.secs) + '_' + str(t.nsecs) + '.jpg'
        target = os.path.join(self.destination, name)

        print('Copying image to', target)
        camera_file = gp.check_result(gp.gp_camera_file_get(
                self.camera, file_path.folder, file_path.name,
                gp.GP_FILE_TYPE_NORMAL, self.context))
        gp.check_result(gp.gp_file_save(camera_file, target))
        #subprocess.call(['xdg-open', target])
github bitcraft / tailor / tailor / plugins / gphoto2_camera.py View on Github external
def capture():
            path = gp.check_result(gp.gp_camera_capture(self._camera, gp.GP_CAPTURE_IMAGE, self._context))

            file = gp.check_result(gp.gp_camera_file_get(
                self._camera, path.folder, path.name,
                gp.GP_FILE_TYPE_NORMAL, self._context))

            data = gp.check_result(gp.gp_file_get_data_and_size(file))
            return bytes(data)