Exemple #1
0
    def decode_lytro_file(self):

        # Lytro type decoding
        with open(self._lfp_path, mode='rb') as file:

            # LFC and raw type decoding
            obj = LfpDecoder(file, self.cfg, self.sta, lfp_path=self._lfp_path)
            obj.main()
            self._lfp_img = obj.bay_img
            self._json_dict = obj.json_dict
            del obj

            # save bayer image as file (if not already present)
            if not os.path.exists(self.fp) and not self.sta.interrupt:
                self.sta.status_msg(msg='Save raw image',
                                    opt=self.cfg.params[self.cfg.opt_prnt])
                self.sta.progress(None, self.cfg.params[self.cfg.opt_prnt])
                misc.save_img_file(misc.Normalizer(
                    self._lfp_img).uint16_norm(),
                                   self.fp,
                                   file_type='tiff')
                self.sta.progress(100, self.cfg.params[self.cfg.opt_prnt])

        return True
Exemple #2
0
    def _search_cal_dirs(self):
        """ look for geo data in calibration folders """

        # skip if file already found or if provided path is not a directory
        if not self._file_found:
            onlydirs = [d for d in listdir(self._path)]
            items = [self._serial] if onlydirs.count(
                self._serial) else onlydirs

            # iterate through directories
            for item in items:
                cali_manifest = join(join(self._path, item),
                                     'cal_file_manifest.json')
                if exists(cali_manifest):
                    with open(cali_manifest, 'r') as file:
                        # find matching sha-1 value
                        json_dict = json.load(file)
                        self._match_georef(json_dict)
                        if self._file_found:
                            # update config and load raw data
                            self.cfg.params[self.cfg.cal_meta] = join(
                                join(self._path.split('.')[0], self._serial),
                                self._cal_fn)
                            with open(self.cfg.params[self.cfg.cal_meta],
                                      mode='rb') as meta_file:
                                self._raw_data = meta_file.read()
                            break

                # extract Lytro's 1st generation files
                elif item.lower().endswith(SUPP_FILE_EXT[-4:]):
                    fn = join(join(self._path, item))
                    if not exists(splitext(fn)[0]):
                        # status update
                        self.sta.status_msg('Extract ' + basename(fn),
                                            self.cfg.params[self.cfg.opt_prnt])
                        # bundle type decoding
                        with open(fn, mode='rb') as file:
                            obj = LfpDecoder(file,
                                             self.cfg,
                                             self.sta,
                                             lfp_path=fn)
                            obj.main()
                            del obj

                    # find matching file
                    mod_txts = [
                        d for d in listdir(splitext(fn)[0])
                        if d.lower().startswith('mod')
                        and d.lower().endswith('.txt')
                    ]
                    for mod_txt in mod_txts:
                        with open(join(splitext(fn)[0], mod_txt), 'r') as f:
                            json_dict = {}
                            json_dict.update(
                                json.loads(f.read().rpartition('}')[0] + '}'))
                            #self._match_georef(json_dict['master']['picture']['frameArray'][0])
                            #if json_dict['master']['picture']['frameArray'][0]['frame']['imageRef'] == self._georef:
                            if json_dict['master']['picture'][
                                    'derivationArray'] == self._georef:
                                self._file_found = True

        return True