Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_illum(self):
# use pre-loaded calibration dataset
wht_list = [file for file in listdir(self.fp) if file.startswith('caldata')]
lfp_list = [file for file in listdir(self.fp) if file.endswith(('lfr', 'lfp'))]
self.cfg.params[self.cfg.cal_path] = join(self.fp, wht_list[0])
for lfp_file in lfp_list:
self.cfg.params[self.cfg.lfp_path] = join(self.fp, lfp_file)
print('\nCompute image %s' % basename(self.cfg.params[self.cfg.lfp_path]))
# decode light field image
obj = LfpReader(self.cfg, self.sta)
ret = obj.main()
# use third of original image size (to prevent Travis from stopping due to memory error)
crop_h, crop_w = obj.lfp_img.shape[0] // 3, obj.lfp_img.shape[1] // 3
crop_h, crop_w = crop_h + crop_h % 2, crop_w + crop_w % 2 # use even number for correct Bayer arrangement
lfp_img = obj.lfp_img[crop_h:-crop_h, crop_w:-crop_w]
del obj
self.assertEqual(True, ret)
# create output data folder
mkdir_p(self.cfg.exp_path, self.cfg.params[self.cfg.opt_prnt])
if not self.cfg.cond_meta_file():
# automatic calibration data selection
obj = CaliFinder(self.cfg, self.sta)
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)
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
aligner = lfp_reader.LfpReader(cfg, sta)
aligner.main()
lfp_img = aligner.lfp_img
except Exception as e:
misc.PlenopticamError(e, cfg=cfg, sta=sta)
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
extractor = lfp_calibrator.CaliFinder(cfg, sta)
extractor.main()
wht_img = extractor.wht_bay
else:
# load white image calibration file
wht_img = misc.load_img_file(cfg.params[cfg.cal_path])
def load_lfp(self, lfp_path=None, wht_opt=False):
# decode light field image
lfp_obj = lfp_reader.LfpReader(cfg=self.cfg, sta=self.sta, lfp_path=lfp_path)
lfp_obj.main()
if wht_opt:
self.wht_img = lfp_obj.lfp_img
else:
self.lfp_img = lfp_obj.lfp_img
del lfp_obj
cfg.params[cfg.cal_path] = r"/Users/Admin/Pictures/Plenoptic/CalibFolder/caldata-B5144000580.tar"
cfg.params[cfg.lfp_path] = r"/Users/Admin/Pictures/Plenoptic/INRIA_SIROCCO/Building.LFR"
#cfg.params[cfg.cal_path] = r"../../../../test/data/caldata-B5144402350.tar"
#cfg.params[cfg.lfp_path] = r"../../../../test/data/gradient_rose_far.lfr"
cfg.lfpimg['bay'] = "GRBG"
cfg.params[cfg.opt_cali] = True
cfg.params[cfg.opt_rota] = True
cfg.params[cfg.opt_dbug] = False
cfg.params[cfg.cal_meth] = 'grid-fit'
cal_opt = False
if cal_opt:
# decode light field image
lfp_obj = lfp_reader.LfpReader(cfg)
lfp_obj.main()
lfp_img = lfp_obj.lfp_img[:, :-16]
del lfp_obj
# automatic calibration data selection
obj = lfp_calibrator.CaliFinder(cfg)
obj.main()
wht_img = obj.wht_bay[:, :-16]
del obj
if cal_opt:
# perform centroid calibration
cal_obj = lfp_calibrator.LfpCalibrator(wht_img, cfg)
cal_obj.main()
cfg = cal_obj.cfg
del cal_obj