Пример #1
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
Пример #2
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
Пример #3
0
def get_camera_file_info(camera, context, path):
    folder, name = os.path.split(path)
    info = gp.CameraFileInfo()
    gp.check_result(
        gp.gp_camera_file_get_info(camera, folder, name, info, context))
    return info
Пример #4
0
def get_file_info(camera, path):
    folder, name = os.path.split(path)
    return gp.check_result(
        gp.gp_camera_file_get_info(camera, folder, name))
Пример #5
0
def get_file_info(camera, path):
    folder, name = os.path.split(path)
    return gp.check_result(gp.gp_camera_file_get_info(camera, folder, name))