How to use the gphoto2.Camera 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 greiginsydney / Intervalometerator / Raspberry Pi / www / intvlm8r.py View on Github external
'expoptions'    : '',
        'piPreviewFile' : ''
        }

    args = request.args.to_dict()
    if args.get('preview'):
        cameraData['piPreviewFile'] = PI_PREVIEW_FILE + '?' + str(calendar.timegm(time.gmtime())) #Adds a unique suffix so the browser always downloads the file

    if args.get('wakeCamera'):
        writeString("WC") # Sends the WAKE command to the Arduino
        time.sleep(1);    # (Adds another second on top of the 0.5s baked into WriteString)
        app.logger.debug('Returned after detecting camera wake command')
        return redirect(url_for('camera'))

    try:
        camera = gp.Camera()
        context = gp.gp_context_new()
        camera.init(context)
        config = camera.get_config(context)
        cameraTimeAndDate = "Unknown"
        try:
            # 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'),
                              ('datetimeutc', None),
                              ('d034',     None)):
                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:
github jim-easterbrook / python-gphoto2 / examples / wait-for-event-oo.py View on Github external
def main():
    # Init camera
    camera = gp.Camera()
    camera.init()
    timeout = 3000 # miliseconds
    while True:
        event_type, event_data = camera.wait_for_event(timeout)
        if event_type == gp.GP_EVENT_FILE_ADDED:
            cam_file = camera.file_get(
                event_data.folder, event_data.name, gp.GP_FILE_TYPE_NORMAL)
            target_path = os.path.join(os.getcwd(), event_data.name)
            print("Image is being saved to {}".format(target_path))
            cam_file.save(target_path)
    return 0
github jim-easterbrook / python-gphoto2 / examples / cam-conf-view-gui.py View on Github external
def loadSetCamConfJson(args):
    if (not(args.load_cam_conf_json)):
        print("loadSetCamConfJson: Sorry, unusable/empty output .json filename; aborting")
        sys.exit(1)
    injsonfile = os.path.realpath(args.load_cam_conf_json)
    print("loadSetCamConfJson: loading from {}".format(injsonfile))
    camera = gp.Camera()
    ctx = gp.Context()
    hasCamInited = False
    try:
        camera.init(ctx)
        hasCamInited = True
    except Exception as ex:
        lastException = ex
        print("No camera: {} {}; ".format( type(lastException).__name__, lastException.args))
    if hasCamInited:
        do_LoadSetCamConfJson(camera, injsonfile)
        print("Exiting.")
        sys.exit(0)
    else:
        print("Sorry, no camera present, cannot execute command; exiting.")
        sys.exit(1)
github jim-easterbrook / python-gphoto2 / examples / list-files-oo.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.Camera()
    camera.init()
    files = list_files(camera)
    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, files[-1])
    print
    print('File info')
    print('=========')
github jim-easterbrook / python-gphoto2 / examples / list-files.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.Camera()
    camera.init()
    files = list_files(camera)
    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, files[-1])
    print
    print('File info')
    print('=========')
github jim-easterbrook / python-gphoto2 / examples / cam-conf-view-gui.py View on Github external
def stop_capture_view():
    camera = gp.Camera()
    hasCamInited = False
    try:
        camera.init()
        hasCamInited = True
    except Exception as ex:
        lastException = ex
        print("No camera: {} {}; ".format( type(lastException).__name__, lastException.args))
    if hasCamInited:
        camera_config = camera.get_config()
        camera_model = get_camera_model(camera_config)
        # https://github.com/gphoto/gphoto2/issues/195
        OK, capture = gp.gp_widget_get_child_by_name( camera_config, 'capture' )
        if OK >= gp.GP_OK:
            capture.set_value(0)
            camera.set_config(camera_config)
        print("Stopped capture view (retracted lens/released mirror) on camera: {} ({} {})".format(camera_model, OK, capture))
github greiginsydney / Intervalometerator / Raspberry Pi / www / intvlm8r.py View on Github external
def copyNow():
    writeString("WC") # Sends the WAKE command to the Arduino (just in case)
    time.sleep(1);    # (Adds another second on top of the 0.5s baked into WriteString)
    try:
        camera = gp.Camera()
        context = gp.gp_context_new()
        camera.init(context)
        copy_files(camera)
        gp.check_result(gp.gp_camera_exit(camera))
    except gp.GPhoto2Error as e:
        flash(e.string)
        app.logger.debug("Transfer wasn't able to connect to the camera: " + e.string)
    except Exception as e:
        app.logger.debug('Unknown error in copyNow: ' + str(e))
    return
github jim-easterbrook / python-gphoto2 / examples / read-exif-gexiv2.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.Camera()
    camera.init()
    files = list_files(camera)
    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)
    print()
    print('Exif data via GP_FILE_TYPE_NORMAL')
    print('=================================')
    for path in files:
github jim-easterbrook / python-gphoto2 / examples / wait-for-event.py View on Github external
def main():
    # Init camera
    camera = gp.Camera()
    camera.init()
    timeout = 3000 # miliseconds
    while True:
        event_type, event_data = camera.wait_for_event(timeout)
        if event_type == gp.GP_EVENT_FILE_ADDED:
            cam_file = camera.file_get(
                event_data.folder, event_data.name, gp.GP_FILE_TYPE_NORMAL)
            target_path = os.path.join(os.getcwd(), event_data.name)
            print("Image is being saved to {}".format(target_path))
            cam_file.save(target_path)
    return 0