diff --git a/opendm/multispectral.py b/opendm/multispectral.py index e1d530a3..dddcb3db 100644 --- a/opendm/multispectral.py +++ b/opendm/multispectral.py @@ -563,6 +563,8 @@ def local_normalize(im): def align_image(image, warp_matrix, dimension): + image = resize_match(image, dimension) + if warp_matrix.shape == (3, 3): return cv2.warpPerspective(image, warp_matrix, dimension) else: @@ -594,3 +596,16 @@ def to_8bit(image, force_normalize=False): return image +def resize_match(image, dimension): + h, w = image.shape[0], image.shape[1] + mw, mh = dimension + + if w != mw or h != mh: + fx = mw/w + fy = mh/h + image = cv2.resize(image, None, + fx=fx, + fy=fx, + interpolation=(cv2.INTER_AREA if (fx < 1.0 and fy < 1.0) else cv2.INTER_LANCZOS4)) + + return image \ No newline at end of file diff --git a/stages/run_opensfm.py b/stages/run_opensfm.py index 5ef220c2..e1af1529 100644 --- a/stages/run_opensfm.py +++ b/stages/run_opensfm.py @@ -104,9 +104,9 @@ class ODMOpenSfMStage(types.ODM_Stage): image = func(shot_id, image) return image - def resize_secondary_images(shot_id, image): + def resize_thermal_images(shot_id, image): photo = reconstruction.get_photo(shot_id) - if photo.band_name != primary_band_name: + if photo.is_thermal(): return thermal.resize_to_match(image, largest_photo) else: return image @@ -138,8 +138,8 @@ class ODMOpenSfMStage(types.ODM_Stage): return image if reconstruction.multi_camera: - largest_photo = find_largest_photo([p for p in photos if p.band_name == primary_band_name]) - undistort_pipeline.append(resize_secondary_images) + largest_photo = find_largest_photo([p for p in photos]) + undistort_pipeline.append(resize_thermal_images) if args.radiometric_calibration != "none": undistort_pipeline.append(radiometric_calibrate) @@ -149,7 +149,8 @@ class ODMOpenSfMStage(types.ODM_Stage): if reconstruction.multi_camera: # Undistort only secondary bands - image_list_override = [os.path.join(tree.dataset_raw, p.filename) for p in photos] # if p.band_name.lower() != primary_band_name.lower() + primary_band_name = multispectral.get_primary_band_name(reconstruction.multi_camera, args.primary_band) + image_list_override = [os.path.join(tree.dataset_raw, p.filename) for p in photos if p.band_name.lower() != primary_band_name.lower()] # We backup the original reconstruction.json, tracks.csv # then we augment them by duplicating the primary band @@ -161,7 +162,6 @@ class ODMOpenSfMStage(types.ODM_Stage): s2p, p2s = None, None if not io.file_exists(added_shots_file) or self.rerun(): - primary_band_name = multispectral.get_primary_band_name(reconstruction.multi_camera, args.primary_band) s2p, p2s = multispectral.compute_band_maps(reconstruction.multi_camera, primary_band_name) if not args.skip_band_alignment: