How to use the gphoto2.gp_context_new 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 / intvlm8r.py View on Github external
if arduinoStats != "Unknown":
            lastShot= arduinoStats.split(":")[0]
            if lastShot != "19999":
                templateData['arduinoLastShot'] = arduinoDoW[int(lastShot[0:1])] + " " + lastShot[1:3]+ ":" + lastShot[3:5]
            nextShot = arduinoStats.split(":")[1]
            if nextShot != "19999":
                templateData['arduinoNextShot'] = arduinoDoW[int(nextShot[0:1])] + " " + nextShot[1:3]+ ":" + nextShot[3:5]
    except:
        pass
    #except Exception as e:
    #    app.logger.debug('Time template error: ' + str(e))

    # Camera comms:
    try:
        camera = gp.Camera()
        context = gp.gp_context_new()
        camera.init(context)

        storage_info = gp.check_result(gp.gp_camera_get_storageinfo(camera))
        if len(storage_info) == 0:
            flash('No storage info available') # The memory card is missing or faulty
            
        abilities = gp.check_result(gp.gp_camera_get_abilities(camera))
        config = camera.get_config(context)
        files = list_camera_files(camera)
        if not files:
            fileCount = 0
            lastImage = ''
        else:
            fileCount = len(files)
            info = get_camera_file_info(camera, files[-1]) #Get the last file
            lastImage = datetime.utcfromtimestamp(info.file.mtime).isoformat(' ')
github greiginsydney / Intervalometerator / Raspberry Pi / intvlm8r.py View on Github external
def transfer():
    """ This page is where you manage how the images make it from the camera to the real world."""
    args = request.args.to_dict()
    if args.get('copyNow'):
        app.logger.debug('Detected COPY NOW')
        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))
            return redirect(url_for('main')) #If we transfer OK, return to main
        except gp.GPhoto2Error as e:
            flash(e.string)
            app.logger.debug("Transfer wasn't able to connect to the camera: " + e.string)

    if not os.path.exists(iniFile):
        createConfigFile(iniFile)

    # Initialise the dictionary:
    templateData = {
        'tfrMethod'     : 'Off',    # Hides all options if the file isn't found or is bad
        'sftpServer'    : '',
        'sftpUser'      : '',
github greiginsydney / Intervalometerator / Raspberry Pi / www / intvlm8r.py View on Github external
if arduinoStats != "Unknown":
            lastShot= arduinoStats.split(":")[0]
            if lastShot != "19999":
                templateData['arduinoLastShot'] = arduinoDoW[int(lastShot[0:1])] + " " + lastShot[1:3]+ ":" + lastShot[3:5]
            nextShot = arduinoStats.split(":")[1]
            if nextShot != "19999":
                templateData['arduinoNextShot'] = arduinoDoW[int(nextShot[0:1])] + " " + nextShot[1:3]+ ":" + nextShot[3:5]
    except:
        pass
    #except Exception as e:
    #    app.logger.debug('Time template error: ' + str(e))

    # Camera comms:
    try:
        camera = gp.Camera()
        context = gp.gp_context_new()
        camera.init(context)

        storage_info = gp.check_result(gp.gp_camera_get_storageinfo(camera))
        if len(storage_info) == 0:
            flash('No storage info available') # The memory card is missing or faulty
            
        abilities = gp.check_result(gp.gp_camera_get_abilities(camera))
        config = camera.get_config(context)
        files = list_camera_files(camera)
        if not files:
            fileCount = 0
            lastImage = ''
        else:
            fileCount = len(files)
            info = get_camera_file_info(camera, files[-1]) #Get the last file
            lastImage = datetime.utcfromtimestamp(info.file.mtime).isoformat(' ')
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 bitcraft / tailor / tailor / plugins / gphoto2_camera.py View on Github external
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
github greiginsydney / Intervalometerator / Raspberry Pi / intvlm8r.py View on Github external
def cameraPOST():
    """ This page is where you manage all the camera settings."""
    try:
        camera = gp.Camera()
        context = gp.gp_context_new()
        camera.init(context)
        config = camera.get_config(context)

        if request.form['CamSubmit'] == 'apply':
            app.logger.debug('-- Camera Apply selected')
            #This *does* write a new setting to the camera:
            node = config.get_child_by_name('imageformat') #
            node.set_value(str(request.form.get('img')))
            # Don't bother sending any of the "read only" settings:
            if (request.form.get('wb') != None):
                node = config.get_child_by_name('whitebalance')
                node.set_value(str(request.form.get('wb')))
            if (request.form.get('iso') != None):
                node = config.get_child_by_name('iso')
                node.set_value(str(request.form.get('iso')))
            if (request.form.get('aperture') != 'implicit auto'):
github florisvb / multi_tracker / nodes / trigger_gphoto2_camera.py View on Github external
if experiment_basename == 'none':
            experiment_basename = time.strftime("%Y%m%d_%H%M%S_N" + nodenum, time.localtime())
        directory_name = experiment_basename + '_gphoto2'
        self.destination = os.path.join(home_directory, directory_name)
        if os.path.exists(self.destination):
            pass
        else:
            os.mkdir(self.destination)

        # initialize the node
        rospy.init_node('gphoto2_' + nodenum)
        self.nodename = rospy.get_name().rstrip('/')
        self.nodenum = nodenum

        #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))
        self.synchronize_camera_timestamp()
        
        self.subTrackedObjects = rospy.Subscriber('/multi_tracker/' + nodenum + '/' + topic, Float32MultiArray, self.gphoto_callback)
github greiginsydney / Intervalometerator / Raspberry Pi / www / intvlm8r.py View on Github external
def cameraPOST():
    """ This page is where you manage all the camera settings."""
    try:
        camera = gp.Camera()
        context = gp.gp_context_new()
        camera.init(context)
        config = camera.get_config(context)

        if request.form['CamSubmit'] == 'apply':
            app.logger.debug('-- Camera Apply selected')
            #This *does* write a new setting to the camera:
            node = config.get_child_by_name('imageformat') #
            node.set_value(str(request.form.get('img')))
            # Don't bother sending any of the "read only" settings:
            if (request.form.get('wb') != None):
                node = config.get_child_by_name('whitebalance')
                node.set_value(str(request.form.get('wb')))
            if (request.form.get('iso') != None):
                node = config.get_child_by_name('iso')
                node.set_value(str(request.form.get('iso')))
            if (request.form.get('aperture') != 'implicit auto'):