Exemple #1
0
    def process(self):

        # reset
        self.var_init()

        # status update
        self.sta.status_msg('Loading data', self.cfg.params[self.cfg.opt_prnt])
        self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])

        # disable button activity
        self.toggle_btn_list(self.all_btn_list)
        self.cmd_wid.btn_list[3].config(text='Stop')

        # read light field photo and calibration source paths
        self.fetch_paths()

        # remove output folder if option is set
        misc.rmdir_p(
            self.cfg.exp_path) if self.cfg.params[self.cfg.dir_remo] else None

        # remove calibrated light-field if calibration or devignetting option is set
        if self.cfg.params[self.cfg.opt_cali] or self.cfg.params[
                self.cfg.opt_vign]:
            misc.rm_file(join(self.cfg.exp_path, 'lfp_img_align.pkl'))
            if self.cfg.params[self.cfg.opt_cali]:
                misc.rm_file(self.cfg.params[self.cfg.cal_meta])

        # create output data folder (prevent override)
        misc.mkdir_p(self.cfg.exp_path, self.cfg.params[self.cfg.opt_prnt])

        # put tasks in the job queue to be run
        for task_info in ((self.load_lfp, self.cfg.cond_load_limg,
                           self.cfg.params[self.cfg.lfp_path]),
                          (self.auto_find, self.cfg.cond_auto_find),
                          (self.load_lfp, self.cfg.cond_load_wimg,
                           self.cfg.params[self.cfg.cal_path],
                           True), (self.cal, self.cfg.cond_perf_cali),
                          (self.cfg.load_cal_data, self.cfg.cond_lfp_align),
                          (self.lfp_align,
                           self.cfg.cond_lfp_align), (self.load_pickle_file,
                                                      True), (self.lfp_extract,
                                                              True),
                          (self.lfp_refo,
                           self.cfg.params[self.cfg.opt_refo]), (self.finish,
                                                                 True)):
            self.job_queue.put(task_info)

        # start polling
        self.after(POLLING_RATE, self.poll)

        # cancel if file paths not provided
        self.sta.validate(checklist=[
            self.cfg.params[self.cfg.lfp_path],
            self.cfg.params[self.cfg.cal_path]
        ],
                          msg='Canceled due to missing image file path')
Exemple #2
0
    def process(self):

        # status update
        self.sta.status_msg('Starting ...', self.cfg.params[self.cfg.opt_dbug])
        self.sta.progress(None, self.cfg.params[self.cfg.opt_dbug])

        # reset
        self.var_init()
        self.sta.interrupt = False

        # disable button activity
        self.toggle_btn_list(self.cmd_wid.btn_list + self.fil_wid.btn_list)

        # read light field photo and calibration source paths
        self.fetch_paths()

        # safely remove output folder if option is set
        misc.rmdir_p(self.cfg.params[self.cfg.lfp_path].split('.')
                     [0]) if self.cfg.params[self.cfg.dir_remo] else None

        # safely create output data folder
        misc.mkdir_p(self.cfg.params[self.cfg.lfp_path].split('.')[0],
                     self.cfg.params[self.cfg.opt_prnt])

        # put tasks in the job queue to be run
        for task_info in ((self.load_lfp, self.cond0,
                           self.cfg.params[self.cfg.lfp_path]),
                          (self.auto_find,
                           self.cond1), (self.load_lfp, self.cond2,
                                         self.cfg.params[self.cfg.cal_path],
                                         True), (self.cal, self.cond3),
                          (self.cfg.load_cal_data, True), (self.lfp_align,
                                                           self.cond4),
                          (self.load_pickle_file, True), (self.lfp_extract,
                                                          True)):
            self.job_queue.put(task_info)

        # start polling
        self.after(POLLING_RATE, self.poll)
    def test_read_error(self):

        # folder and path handling
        fp = os.path.join(
            os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
            'examples', 'data')
        os.makedirs(fp) if not os.path.exists(fp) else None

        # create dummy file with wrong file format
        self.cfg.params[self.cfg.lfp_path] = os.path.join(fp, 'test_dummy.lfp')
        with open(self.cfg.params[self.cfg.lfp_path], 'a'):
            os.utime(self.cfg.params[self.cfg.lfp_path], None)

        with self.assertRaises(PlenopticamError) as exc:
            reader = LfpReader(cfg=self.cfg, sta=self.sta)
            reader.main()

        self.assertEqual("'dict' object has no attribute 'startswith'",
                         str(exc.exception))

        # remove dummy data after test
        rm_file(self.cfg.params[self.cfg.lfp_path])
        rmdir_p(self.cfg.exp_path)
    def process(self):

        # status update
        self.sta.status_msg('Starting ...', self.cfg.params[self.cfg.opt_dbug])
        self.sta.progress(None, self.cfg.params[self.cfg.opt_dbug])

        # reset
        self.var_init()
        self.sta.interrupt = False

        # disable button activity
        self.toggle_btn_list(self.cmd_wid.btn_list + self.fil_wid.btn_list)

        # read light field photo and calibration source paths
        self.fetch_paths()

        # remove output folder if option is set
        misc.rmdir_p(self.cfg.params[self.cfg.lfp_path].split('.')
                     [0]) if self.cfg.params[self.cfg.dir_remo] else None

        # remove calibrated light-field if calibration option is set
        if self.cfg.params[self.cfg.opt_cali]:
            misc.rmdir_p(
                join(self.cfg.params[self.cfg.lfp_path].split('.')[0],
                     'lfp_img_align.pkl'))
            misc.rmdir_p(self.cfg.params[self.cfg.cal_meta])

        # create output data folder
        misc.mkdir_p(self.cfg.params[self.cfg.lfp_path].split('.')[0],
                     self.cfg.params[self.cfg.opt_prnt])

        # put tasks in the job queue to be run
        for task_info in ((self.load_lfp, self.cfg.load_limg_cond0,
                           self.cfg.params[self.cfg.lfp_path]),
                          (self.auto_find, self.cfg.auto_find_cond1),
                          (self.load_lfp, self.cfg.load_wimg_cond2,
                           self.cfg.params[self.cfg.cal_path],
                           True), (self.cal, self.cfg.cali_meta_cond3),
                          (self.cfg.load_cal_data, self.cfg.auto_find_cond1),
                          (self.lfp_align, self.cfg.lfp_align_cond4),
                          (self.load_pickle_file, True), (self.lfp_extract,
                                                          True)):
            self.job_queue.put(task_info)

        # start polling
        self.after(POLLING_RATE, self.poll)

        # cancel if file paths not provided
        self.sta.validate(checklist=[
            self.cfg.params[self.cfg.lfp_path],
            self.cfg.params[self.cfg.cal_path]
        ],
                          msg='Canceled due to missing image file path')
Exemple #5
0
    def remove_dummy_file(self):
        """ remove dummy data after test """

        rm_file(self.cfg.params[self.cfg.lfp_path])
        rmdir_p(self.cfg.exp_path)
Exemple #6
0
def main():

    # program info
    print("\nPlenoptiCam v%s \n" % __version__)

    # create config object
    cfg = PlenopticamConfig()
    cfg.default_values()

    # parse options
    cfg = parse_options(sys.argv[1:], cfg)

    # instantiate status object
    sta = misc.PlenopticamStatus()
    sta.bind_to_interrupt(sys.exit)  # set interrupt

    # force relative paths to be absolute
    cfg.params[cfg.lfp_path] = os.path.abspath(cfg.params[cfg.lfp_path])
    cfg.params[cfg.cal_path] = os.path.abspath(cfg.params[cfg.cal_path])

    # collect light field image file name(s) based on provided path
    if os.path.isdir(cfg.params[cfg.lfp_path]):
        lfp_filenames = [
            f for f in os.listdir(cfg.params[cfg.lfp_path])
            if f.lower().endswith(SUPP_FILE_EXT)
        ]
        cfg.params[cfg.lfp_path] = os.path.join(cfg.params[cfg.lfp_path],
                                                'dummy.ext')
    elif not os.path.isfile(cfg.params[cfg.lfp_path]):
        lfp_filenames = [
            misc.select_file(cfg.params[cfg.lfp_path],
                             'Select plenoptic image')
        ]
    else:
        lfp_filenames = [cfg.params[cfg.lfp_path]]

    if not cfg.params[cfg.cal_path]:
        # manual calibration data selection
        sta.status_msg(
            '\r Please select white image calibration source manually',
            cfg.params[cfg.opt_prnt])
        # open selection window (at current lfp file directory) to set calibration folder path
        cfg.params[cfg.cal_path] = misc.select_file(
            cfg.params[cfg.lfp_path], 'Select calibration image')

    # provide number of found images to user
    print("\n %s Image(s) found" % len(lfp_filenames))

    # cancel if file paths not provided
    sta.validate(checklist=lfp_filenames + [cfg.params[cfg.lfp_path]],
                 msg='Canceled due to missing image file path')

    # iterate through light field image(s)
    for lfp_filename in sorted(lfp_filenames):

        # change path to next filename
        cfg.params[cfg.lfp_path] = os.path.join(
            os.path.dirname(cfg.params[cfg.lfp_path]), lfp_filename)
        print(cfg.params[cfg.lfp_path])
        sta.status_msg(msg='Process file ' + lfp_filename,
                       opt=cfg.params[cfg.opt_prnt])

        # remove output folder if option is set
        misc.rmdir_p(cfg.exp_path) if cfg.params[cfg.dir_remo] else None

        try:
            # decode light field image
            lfp_obj = lfp_reader.LfpReader(cfg, sta)
            lfp_obj.main()
            lfp_img = lfp_obj.lfp_img
            del lfp_obj
        except Exception as e:
            misc.PlenopticamError(e)
            continue
        # create output data folder
        misc.mkdir_p(cfg.exp_path, cfg.params[cfg.opt_prnt])

        if cfg.cond_auto_find():
            # automatic calibration data selection
            obj = lfp_calibrator.CaliFinder(cfg, sta)
            obj.main()
            wht_img = obj.wht_bay
            del obj

        else:
            # load white image calibration file
            wht_img = misc.load_img_file(cfg.params[cfg.cal_path])
            # save settings configuration
            cfg.save_params()

        # perform calibration if previously computed calibration data does not exist
        meta_cond = not (os.path.exists(cfg.params[cfg.cal_meta])
                         and cfg.params[cfg.cal_meta].lower().endswith('json'))
        if meta_cond or cfg.params[cfg.opt_cali]:
            # perform centroid calibration
            cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg, sta)
            cal_obj.main()
            cfg = cal_obj.cfg
            del cal_obj

        # load calibration data
        cfg.load_cal_data()

        #  check if light field alignment has been done before
        if cfg.cond_lfp_align():
            # align light field
            lfp_obj = lfp_aligner.LfpAligner(lfp_img, cfg, sta, wht_img)
            lfp_obj.main()
            lfp_obj = lfp_obj.lfp_img
            del lfp_obj

        # load previously computed light field alignment
        with open(os.path.join(cfg.exp_path, 'lfp_img_align.pkl'), 'rb') as f:
            lfp_img_align = pickle.load(f)

        # extract viewpoint data
        lfp_calibrator.CaliFinder(cfg).main()
        obj = lfp_extractor.LfpExtractor(lfp_img_align, cfg=cfg, sta=sta)
        obj.main()
        vp_img_arr = obj.vp_img_arr
        del obj

        # do refocusing
        if cfg.params[cfg.opt_refo]:
            obj = lfp_refocuser.LfpRefocuser(vp_img_arr, cfg=cfg, sta=sta)
            obj.main()
            del obj

    return True