Skip to content

Commit

Permalink
Merge pull request #9 from 20treeAI/solve_window_error
Browse files Browse the repository at this point in the history
Return an empty array if the window for sift has a size of zero or negative
  • Loading branch information
daviddemeij authored Nov 2, 2022
2 parents 17d94a4 + 4082ea3 commit f1cfc04
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
23 changes: 21 additions & 2 deletions s2p/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ def stereo_matching(tile, i):
rect2 = os.path.join(out_dir, 'rectified_sec.tif')
disp = os.path.join(out_dir, 'rectified_disp.tif')
mask = os.path.join(out_dir, 'rectified_mask.png')

disp_min, disp_max = np.loadtxt(os.path.join(out_dir, 'disp_min_max.txt'))

block_matching.compute_disparity_map(rect1, rect2, disp, mask,
Expand All @@ -210,7 +211,6 @@ def stereo_matching(tile, i):
common.remove(rect2)
common.remove(os.path.join(out_dir, 'disp_min_max.txt'))


def disparity_to_height(tile, i):
"""
Compute a height map from the disparity map of a pair of image tiles.
Expand Down Expand Up @@ -606,9 +606,27 @@ def main(user_cfg, start_from=0):
parallel.launch_calls(rectification_pair, tiles_pairs, nb_workers,
timeout=timeout)


# matching step:
if start_from <= 4:
# Check which tiles were rectified correctly, and skip tiles that have missing files
tiles_new = []
for tile in tiles:
paths = []
for i in range(1, n):
out_dir = os.path.join(tile['dir'], 'pair_{}'.format(i))
paths += [
os.path.join(out_dir, 'rectified_ref.tif'),
os.path.join(out_dir, 'rectified_sec.tif')
]
missing = sum(not os.path.exists(p) for p in paths)
if missing > 0:
print(f"WARNING: tile {tile['dir']} is missing {missing}/{len(paths)} "
"input files for stereo matching, skipping...")
continue
tiles_new.append(tile)
tiles = tiles_new
tiles_pairs = [(t, i) for i in range(1, n) for t in tiles]

if cfg['max_processes_stereo_matching'] is not None:
nb_workers_stereo = cfg['max_processes_stereo_matching']
else:
Expand All @@ -623,6 +641,7 @@ def main(user_cfg, start_from=0):
# For non mgm_multi don't use less than 2/3 of the workers (much less RAM intensive)
nb_workers_stereo = int(min(nb_workers, max(((2 / 3) * nb_workers), nb_workers / divider)))
try:

print(f'4) running stereo matching using {nb_workers_stereo} workers...')
parallel.launch_calls(stereo_matching, tiles_pairs, nb_workers_stereo,
timeout=timeout)
Expand Down
2 changes: 2 additions & 0 deletions s2p/sift.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ def image_keypoints(im, x, y, w, h, max_nb=None, thresh_dog=0.0133, nb_octaves=8
# if extract not completely inside the full image then resize (w, h)
w = min(w, ds.width - x)
h = min(h, ds.height - y)
if w <= 0 or h <= 0:
return np.array([])
in_buffer = ds.read(window=rio.windows.Window(x, y, w, h))

# Detect keypoints on first band
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def finalize_options(self):
}

setup(name="s2p",
version="1.3.3",
version="1.3.5",
description="Satellite Stereo Pipeline.",
long_description=readme(),
long_description_content_type='text/markdown',
Expand Down

0 comments on commit f1cfc04

Please sign in to comment.