def trigger_capture(camera, context, dstpath='image.jpg'): """ Trigger capture must be used instead of capture if you want to shoot while the mirror is locked up and you do not want to re-focus - set capture format on camera""" timeout = 20 starttime = time.time() gp.check_result(gp.gp_camera_trigger_capture(camera, context)) filefound = [False, False] while filefound[1] != gp.GP_EVENT_FILE_ADDED: filefound = gp.gp_camera_wait_for_event(camera, 10000, context) if time.time() - starttime > timeout: print ('operation timed out') return False campath = '/' filelist = list_files(camera, context, campath) for f in filelist: filename = f.strip(campath) camfile = gp.check_result(gp.gp_file_new()) gp.gp_camera_file_get(camera, campath, filename, gp.GP_FILE_TYPE_NORMAL, camfile, context) gp.gp_file_save(camfile, dstpath) gp.gp_file_unref(camfile) gp.gp_camera_file_delete(camera, campath, filename, context) endtime = round(time.time() - starttime, 2) print ('capture complete in {}s'.format(endtime))
def main(): # Init camera camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) timeout = 3000 # miliseconds while True: event_type, event_data = gp.check_result( gp.gp_camera_wait_for_event(camera, timeout)) if event_type == gp.GP_EVENT_FILE_ADDED: # Get the image from the camera camera_file = gp.check_result(gp.gp_camera_file_get( camera, event_data.folder, event_data.name, gp.GP_FILE_TYPE_NORMAL)) # Path where the image is to be saved target_path= os.path.join(os.getcwd(), event_data.name) print("Picture is saved to {}".format(target_path)) gp.check_result(gp.gp_file_save(camera_file, target_path)) return 0
def get_bulb_picture(self, secs, stop): self.set_parameter('bulb', 1) i = 0 while i < secs and not stop.isSet(): time.sleep(1) self.text_line.setText('Elapsed '+str(i+1)+' of '+str(secs)+' secs') i = i + 1 self.set_parameter('bulb', 0) self.text_line.setText('Saving image...') time.sleep(2) status = 0 i = 0 while status != 2: error, status, self.file_path = gphoto2.gp_camera_wait_for_event(self.camera, i, self.context) i = i + 1 camera_file = gphoto2.check_result(gphoto2.gp_camera_file_get(self.camera, self.file_path.folder, self.file_path.name, gphoto2.GP_FILE_TYPE_NORMAL, self.context)) error = gphoto2.gp_file_save(camera_file, self.file_path.name) self.text_line.setText('Done') return self.file_path
def main(): # Init camera camera = gp.check_result(gp.gp_camera_new()) gp.check_result(gp.gp_camera_init(camera)) while(True): result,image_file = gp.check_result(gp.gp_camera_wait_for_event(camera,gp.GP_EVENT_FILE_ADDED)) if (result == gp.GP_EVENT_FILE_ADDED): # Get the image from the camera camera_file = gp.check_result(gp.gp_camera_file_get( camera, image_file.folder, image_file.name, gp.GP_FILE_TYPE_NORMAL)) # Path where the image is to be saved target_path= os.path.join(os.getcwd(),image_file.name) print("Picture is saved to {}".format(target_path)) gp.gp_file_save(camera_file, target_path) return 0
def capture_bulb(self, test = False, callback = None): if test: sec = self.status['test-exp-sec'] self.set_config_value_checked('iso', self.status['test-iso']) try: self.status['test-iso'] = int(self.get_config_value('iso')) except: pass self.set_config_choice('capturetarget', 0) #mem self.set_config_choice('imageformat', 1) #Large Normal JPEG else: sec = self.status['exp-sec'] self.set_config_value_checked('iso', self.status['iso']) try: self.status['iso'] = int(self.get_config_value('iso')) except: pass self.set_config_choice('capturetarget', 1) #card #self.set_config_choice('imageformat', 24) #RAW self.set_config_choice('imageformat', 7) #RAW + Large Normal JPEG self.set_config_value('aperture', self.status['f-number']) self.status['f-number'] = self.get_config_value('aperture') if sec <= 30: bulbmode = None self.set_config_value_checked('autoexposuremode', 'Manual') self.set_config_value_checked('shutterspeed', sec) gp.check_result(gp.gp_camera_trigger_capture(self.camera, self.context)) else: self.set_config_value_checked('autoexposuremode', 'Manual') if not self.set_config_value_checked('shutterspeed', 'Bulb'): self.set_config_value_checked('autoexposuremode', 'Bulb') bulbmode = 'eosremoterelease' if not self.set_config_value_checked('eosremoterelease', 'Immediate'): self.set_config_value('bulb', 1) bulbmode = 'bulb' self.t_start = time.time() t = 0 self.status['exp_in_progress'] = True self.status['interrupt'] = False while True: if t < sec - 4 and not self.status['interrupt']: time.sleep(3) e, file_path = gp.check_result(gp.gp_camera_wait_for_event(self.camera, 1000,self.context)) t = time.time() - self.t_start print "camera event ", t, e, file_path if self.status['exp_in_progress']: self.status['cur_time'] = int(t) if self.status['exp_in_progress'] and (t > sec or self.status['interrupt']): if bulbmode == 'bulb': self.set_config_value('bulb', 0) elif bulbmode == 'eosremoterelease': self.set_config_value_checked('eosremoterelease', 'Release Full') self.status['exp_in_progress'] = False if e == gp.GP_EVENT_FILE_ADDED: print >> sys.stderr, "filepath:", file_path.folder, file_path.name filename, file_extension = os.path.splitext(file_path.name) if file_extension == ".jpg" or file_extension == ".JPG": break self.status['exp_in_progress'] = False self.status['cur_time'] = 0 self.status['interrupt'] = False target = os.path.join('/tmp', file_path.name) n = 20 while True: n -= 1 try: 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)) file_data = gp.check_result(gp.gp_file_get_data_and_size(camera_file)) if callback is not None: callback(file_data) break except gp.GPhoto2Error as ex: if ex.code == gp.GP_ERROR_CAMERA_BUSY: time.sleep(1) if (n > 0): continue raise #stop review on display self.set_config_value_checked('eosremoterelease', 'Press Half') self.set_config_value_checked('eosremoterelease', 'Release Half') self.do_fps_hack()
def get_event(self, timeout = 0): return gp.check_result( gp.gp_camera_wait_for_event(self.camera, timeout, self.context))