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 camera_capture_light_field(camera, ser, n_views, n_exposures, stops=2.0, path='/tmp'): # initialize camera location ser.write(b'm0') # check and create output dirctory for capture output_dir = os.path.join(path, "capture") if not os.path.exists(output_dir): os.mkdir(output_dir) else: n_folder = 0 while os.path.exists(output_dir): n_folder += 1 output_dir = os.path.join(path, "capture-{}".format(n_folder)) os.mkdir(output_dir) # capture process for capture_location in range(n_views): # initialize camera gp.check_result(gp.gp_camera_init(camera)) # wait for camera to stop moving and trigger camera capture process = ser.readline() gp.check_result(gp.gp_camera_trigger_capture(camera)) # move to the next location if capture_location is not n_views-1: ser.write(b'm' + str((capture_location+1)*(1000//(n_views-1))).encode('UTF-8')) # save the captured files to path file_number = 0 while file_number < n_exposures: gp.check_result(gp.gp_camera_wait_for_event( camera, gp.GP_EVENT_FILE_ADDED)) # wait for new available file file_list = list_files(camera) # save the new file if len(file_list) is not file_number: # file format: capt-<sequence>-<distance(mm)>[<exposure(EV)>].arw # e.g. capt-001-0100[-2.0].arw target = os.path.join(output_dir, "capt-{:0>3d}-{:0>4d}[{:+.1f}]".format( capture_location*n_exposures + file_number, int(capture_location*(1000/(n_views-1))), stops*(file_number-n_exposures//2)) + file_list[file_number][-4:]) camera_file = gp.check_result(gp.gp_camera_file_get( camera, '/', file_list[file_number][1:], gp.GP_FILE_TYPE_NORMAL)) gp.check_result(gp.gp_file_save(camera_file, target)) file_number += 1 # exit camera gp.check_result(gp.gp_camera_exit(camera)) # return to initial location ser.write(b'm0')
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 trigger(self): self.log("Triggering") gp.check_result(gp.gp_camera_trigger_capture(self.camera, self.context)) self.log("Triggered") self.in_preview = False