def test_raw_panel_manual(panel_image_name): img = image.Image(panel_image_name) pan = panel.Panel(img, panelCorners=[[809, 613], [648, 615], [646, 454], [808, 452]]) mean, std, num, sat = pan.raw() assert mean == pytest.approx(45406, rel=0.01) assert std == pytest.approx(738.0, rel=0.05) assert num == pytest.approx(26005, rel=0.001) assert sat == pytest.approx(0, abs=2)
def test_raw_panel_bad_corners(panel_image_name): img = image.Image(panel_image_name) pan = panel.Panel(img, panelCorners=[[460, 599], [583, 599], [584, 478], [462, 477]]) mean, std, num, sat = pan.raw() assert mean == pytest.approx(26965, rel=0.01) assert std == pytest.approx(15396.0, rel=0.05) assert num == pytest.approx(14824, rel=0.01) assert sat == pytest.approx(0, abs=2)
def from_filelist(cls, file_list): if len(file_list) == 0: raise IOError("No files provided. Check your file paths") for fle in file_list: if not os.path.isfile(fle): raise IOError( "All files in file list must be a file. The following file is not:\nfle" ) images = [image.Image(fle) for fle in file_list] return cls(images)
def test_qr_corners(panel_image_name): img = image.Image(panel_image_name) pan = panel.Panel(img) qr_corners = pan.qr_corners() good_qr_corners = [[460, 599], [583, 599], [584, 478], [462, 477]] assert qr_corners is not None assert len(qr_corners) == len(good_qr_corners) assert pan.serial == 'RP02-1603036-SC' for i, pt in enumerate(qr_corners): # different opencv/zbar versions round differently it seems assert pt[0] == pytest.approx(good_qr_corners[i][0], abs=3) assert pt[1] == pytest.approx(good_qr_corners[i][1], abs=3)
def test_panel_corners(panel_image_name): img = image.Image(panel_image_name) pan = panel.Panel(img) panel_pts = pan.panel_corners() good_pts = [[809, 613], [648, 615], [646, 454], [808, 452]] assert panel_pts is not None assert len(panel_pts) == len(good_pts) assert pan.serial == 'RP02-1603036-SC' for i, pt in enumerate(panel_pts): # different opencv/zbar versions round differently it seems assert pt[0] == pytest.approx(good_pts[i][0], abs=3) assert pt[1] == pytest.approx(good_pts[i][1], abs=3)
def from_filelist(cls, file_list): """ Create Capture instance from List of file paths. :param file_list: List of str system file paths. :return: Capture object. """ if len(file_list) == 0: raise IOError("No files provided. Check your file paths.") for file in file_list: if not os.path.isfile(file): raise IOError(f"All files in file list must be a file. The following file is not:\n{file}") images = [image.Image(file) for file in file_list] return cls(images)
def test_altum_panel(altum_panel_image_name): img = image.Image(altum_panel_image_name) assert img.auto_calibration_image == True pan = panel.Panel(img) panel_pts = pan.panel_corners() good_pts = [[1278, 483], [1176, 491], [1184, 591], [1286, 583]] assert panel_pts is not None assert len(panel_pts) == len(good_pts) assert pan.serial == 'RP04-1901231-SC' print(panel_pts) for i, pt in enumerate(panel_pts): # different opencv/zbar versions round differently it seems assert pt[0] == pytest.approx(good_pts[i][0], abs=3) assert pt[1] == pytest.approx(good_pts[i][1], abs=3) assert pan.qr_corners() == None
def test_panel_corners(panel_image_name): img = image.Image(panel_image_name) pan = panel.Panel(img) panel_pts = pan.panel_corners() good_pts = [[809, 613], [648, 615], [646, 454], [808, 452]] assert panel_pts is not None assert len(panel_pts) == len(good_pts) assert pan.serial == 'RP02-1603036-SC' # the particular order of the points is not relevant # so sort by coordinates panel_pts = sorted(panel_pts, key=operator.itemgetter(0, 1)) good_pts = sorted(good_pts, key=operator.itemgetter(0, 1)) for i, pt in enumerate(panel_pts): # different opencv/zbar versions round differently it seems assert pt[0] == pytest.approx(good_pts[i][0], abs=3) assert pt[1] == pytest.approx(good_pts[i][1], abs=3)
def test_raw_panel_saturatedl(panel_image_name): img = image.Image(panel_image_name) pan = panel.Panel(img, panelCorners=[[809, 613], [648, 615], [646, 454], [808, 452]]) #saturate 2500 pixels in the raw image - note that on the undistorted image this #will result in 2329 saturated pixels i0 = img.undistorted(img.raw()) i0[500:550, 700:750] = 4095 * 16 + 1 img.set_undistorted(i0) mean, std, num, sat = pan.raw() assert mean == pytest.approx(47245, rel=0.01) assert std == pytest.approx(5846.1, rel=0.05) assert num == pytest.approx(26005, rel=0.001) assert sat == pytest.approx(2500, abs=0)
def from_directory(cls, directory, progress_callback=None, exiftool_path=None): """ Create and ImageSet recursively from the files in a directory """ cls.basedir = directory matches = [] for root, dirnames, filenames in os.walk(directory): for filename in fnmatch.filter(filenames, '*.tif'): matches.append(os.path.join(root, filename)) images = [] if exiftool_path is None and os.environ.get( 'exiftoolpath') is not None: exiftool_path = os.path.normpath(os.environ.get('exiftoolpath')) with exiftool.ExifTool(exiftool_path) as exift: for i, path in enumerate(matches): images.append(image.Image(path, exiftool_obj=exift)) if progress_callback is not None: progress_callback(float(i) / float(len(matches))) # create a dictionary to index the images so we can sort them # into captures # { # "capture_id": [img1, img2, ...] # } captures_index = {} for img in images: c = captures_index.get(img.capture_id) if c is not None: c.append(img) else: captures_index[img.capture_id] = [img] captures = [] for cap_imgs in captures_index: imgs = captures_index[cap_imgs] newcap = capture.Capture(imgs) captures.append(newcap) if progress_callback is not None: progress_callback(1.0) return cls(captures)
def test_RP06_panel_raw(panel_images_RP06): test_mean = [33082, 34347, 33971, 34186, 33371] test_std = [474.7, 582.6, 476.3, 464, 658.9] test_num = [3616, 3552, 3669, 3612, 3729] test_sat = [0, 0, 0, 0, 0] for i, m, s, n, sa in zip(panel_images_RP06, test_mean, test_std, test_num, test_sat): img = image.Image(i) pan = panel.Panel(img) mean, std, num, sat = pan.raw() assert pan.panel_detected() print('mean {:f} std {:f} num {:f} sat {:f}'.format( mean, std, num, sat)) print('m {:f} s {:f} n {:f} sa {:f}'.format(m, s, n, sa)) assert mean == pytest.approx(m, rel=0.1) assert std == pytest.approx(s, rel=0.1) assert num == pytest.approx(n, rel=0.1) assert sat == pytest.approx(sa, rel=0.1)
def test_altum_panel(altum_panel_image_name): img = image.Image(altum_panel_image_name) assert img.auto_calibration_image == True pan = panel.Panel(img) panel_pts = pan.panel_corners() good_pts = [[1278, 483], [1176, 491], [1184, 591], [1286, 583]] assert panel_pts is not None assert len(panel_pts) == len(good_pts) assert pan.serial == 'RP04-1901231-SC' # the particular order of the points is not relevant # so sort by coordinates panel_pts = sorted(panel_pts, key=operator.itemgetter(0, 1)) good_pts = sorted(good_pts, key=operator.itemgetter(0, 1)) for i, pt in enumerate(panel_pts): # different opencv/zbar versions round differently it seems assert pt[0] == pytest.approx(good_pts[i][0], abs=3) assert pt[1] == pytest.approx(good_pts[i][1], abs=3) assert pan.qr_corners() == None
def bad_dls2_horiz_irr_image(): image_path = os.path.join('data', 'ALTUM0SET', '000') return image.Image(os.path.join(image_path, 'IMG_0000_1.tif'))
def altum_lwir_image(altum_files_dir): return image.Image(os.path.join(altum_files_dir, 'IMG_0000_6.tif'))
def altum_flight_image(altum_flight_image_name): return image.Image(altum_flight_image_name)
def panel_altum_image(panel_altum_file_name): return image.Image(panel_altum_file_name)
def img2(files_dir): return image.Image(os.path.join(files_dir, 'IMG_0000_2.tif'))
def test_append_list(): imgs = [image.Image(fle) for fle in file_list()] cap = capture.Capture(imgs[0]) assert len(cap.images) == 1 cap.append_images(imgs[1:]) assert len(cap.images) == 5
def test_from_images(): imgs = [image.Image(fle) for fle in file_list()] cap = capture.Capture(imgs) assert cap is not None assert len(cap.images) == len(file_list())
def test_panel_not_detected(flight_image_name): img = image.Image(flight_image_name) pan = panel.Panel(img) assert pan.panel_detected() == False
def image_from_file(filename): return image.Image(filename)
def test_append_list(panel_rededge_file_list): imgs = [image.Image(fle) for fle in panel_rededge_file_list] cap = capture.Capture(imgs[0]) assert len(cap.images) == 1 cap.append_images(imgs[1:]) assert len(cap.images) == 5
def from_file(cls, file_name): return cls(image.Image(file_name))
def panel_altum_capture(panel_altum_file_list): imgs = [image.Image(fle) for fle in panel_altum_file_list] return capture.Capture(imgs)
def test_altum_lwir(altum_lwir_image_name): img = image.Image(altum_lwir_image_name) assert img.auto_calibration_image == False pan = panel.Panel(img) assert pan.panel_detected() == False
def test_unordered_coordinates(panel_image_name): img = image.Image(panel_image_name) ordered_corners = [(809, 613), (648, 615), (646, 454), (808, 452)] unordered_corners = [(648, 615), (809, 613), (808, 452), (646, 454)] pan = panel.Panel(img, panelCorners=unordered_corners) assert pan.ordered_panel_coordinates() == ordered_corners
def append_file(self, file_name): self.append_image(image.Image(file_name))
def test_altum_images(non_panel_altum_file_list): imgs = [image.Image(fle) for fle in non_panel_altum_file_list] cap = capture.Capture(imgs) assert cap is not None assert len(cap.images) == len(non_panel_altum_file_list)
def from_filelist(cls, file_list): images = [image.Image(fle) for fle in file_list] return cls(images)
def test_from_images(panel_rededge_file_list): imgs = [image.Image(fle) for fle in panel_rededge_file_list] cap = capture.Capture(imgs) assert cap is not None assert len(cap.images) == len(panel_rededge_file_list)