Skip to content

Instantly share code, notes, and snippets.

@pierrelux
Created May 25, 2015 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pierrelux/0220f4809b4f7d383ce0 to your computer and use it in GitHub Desktop.
Save pierrelux/0220f4809b4f7d383ce0 to your computer and use it in GitHub Desktop.
DSLR image capture and download from Python
import os
import gphoto2 as gp
class Camera:
def __init__(self):
pass
def open(self):
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 close(self):
gp.check_result(gp.gp_camera_exit(self.camera, self.context))
def capture(self, path='./'):
file_path = gp.check_result(gp.gp_camera_capture(
self.camera, gp.GP_CAPTURE_IMAGE, self.context))
target = os.path.join(path, file_path.name)
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))
return target
if __name__ == "__main__":
cam = Camera()
cam.open()
cam.capture()
cam.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment