Skip to content

Commit

Permalink
Merge pull request #1771 from pierotofy/homographyfix
Browse files Browse the repository at this point in the history
Mavic 3M Support
  • Loading branch information
pierotofy authored Jun 29, 2024
2 parents 75c3639 + 8b51c69 commit 9acbaf5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion SuperBuild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ externalproject_add(dem2points
externalproject_add(odm_orthophoto
DEPENDS opencv
GIT_REPOSITORY https://github.com/OpenDroneMap/odm_orthophoto.git
GIT_TAG 317
GIT_TAG 353
PREFIX ${SB_BINARY_DIR}/odm_orthophoto
SOURCE_DIR ${SB_SOURCE_DIR}/odm_orthophoto
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${SB_INSTALL_DIR}
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.5.2
3.5.3
42 changes: 25 additions & 17 deletions opendm/multispectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,14 @@ def find_ecc_homography(image_gray, align_image_gray, number_of_iterations=1000,
pyramid_levels = 0
h,w = image_gray.shape
max_dim = max(h, w)
downscale = 0

max_size = 1280
max_size = 2048
while max_dim / (2**downscale) > max_size:
downscale += 1

if max_dim > max_size:
if max_dim == w:
f = max_size / w
else:
f = max_size / h
if downscale > 0:
f = 1 / (2**downscale)
image_gray = cv2.resize(image_gray, None, fx=f, fy=f, interpolation=cv2.INTER_AREA)
h,w = image_gray.shape

Expand Down Expand Up @@ -473,7 +473,6 @@ def find_ecc_homography(image_gray, align_image_gray, number_of_iterations=1000,

# Define the motion model, scale the initial warp matrix to smallest level
warp_matrix = np.eye(3, 3, dtype=np.float32)
warp_matrix = warp_matrix * np.array([[1,1,2],[1,1,2],[0.5,0.5,1]], dtype=np.float32)**(1-(pyramid_levels+1))

for level in range(pyramid_levels+1):
ig = gradient(gaussian(image_gray_pyr[level]))
Expand All @@ -495,14 +494,16 @@ def find_ecc_homography(image_gray, align_image_gray, number_of_iterations=1000,
if level != pyramid_levels:
log.ODM_INFO("Could not compute ECC warp_matrix at pyramid level %s, resetting matrix" % level)
warp_matrix = np.eye(3, 3, dtype=np.float32)
warp_matrix = warp_matrix * np.array([[1,1,2],[1,1,2],[0.5,0.5,1]], dtype=np.float32)**(1-(pyramid_levels+1))
else:
raise e

if level != pyramid_levels:
warp_matrix = warp_matrix * np.array([[1,1,2],[1,1,2],[0.5,0.5,1]], dtype=np.float32)

return warp_matrix
if downscale > 0:
return warp_matrix * (np.array([[1,1,2],[1,1,2],[0.5,0.5,1]], dtype=np.float32) ** downscale)
else:
return warp_matrix


def find_features_homography(image_gray, align_image_gray, feature_retention=0.7, min_match_count=10):
Expand All @@ -512,13 +513,14 @@ def find_features_homography(image_gray, align_image_gray, feature_retention=0.7

h,w = image_gray.shape
max_dim = max(h, w)
downscale = 0

max_size = 2048
if max_dim > max_size:
if max_dim == w:
f = max_size / w
else:
f = max_size / h
max_size = 4096
while max_dim / (2**downscale) > max_size:
downscale += 1

if downscale > 0:
f = 1 / (2**downscale)
image_gray = cv2.resize(image_gray, None, fx=f, fy=f, interpolation=cv2.INTER_AREA)
h,w = image_gray.shape

Expand Down Expand Up @@ -570,7 +572,13 @@ def find_features_homography(image_gray, align_image_gray, feature_retention=0.7

# Find homography
h, _ = cv2.findHomography(points_image, points_align_image, cv2.RANSAC)
return h
if h is None:
return None

if downscale > 0:
return h * (np.array([[1,1,2],[1,1,2],[0.5,0.5,1]], dtype=np.float32) ** downscale)
else:
return h

def gradient(im, ksize=5):
im = local_normalize(im)
Expand Down Expand Up @@ -635,4 +643,4 @@ def resize_match(image, dimension):
fy=fx,
interpolation=(cv2.INTER_AREA if (fx < 1.0 and fy < 1.0) else cv2.INTER_LANCZOS4))

return image
return image
2 changes: 1 addition & 1 deletion opendm/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def parse_exif_values(self, _path_file):
self.set_attr_from_xmp_tag('speed_z', xtags, [
'@drone-dji:FlightZSpeed',
], float)

# Account for over-estimation
if self.gps_xy_stddev is not None:
self.gps_xy_stddev *= 2.0
Expand Down
1 change: 0 additions & 1 deletion opendm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ def get_photo(self, filename):
if p.filename == filename:
return p


class ODM_GeoRef(object):
@staticmethod
def FromCoordsFile(coords_file):
Expand Down
2 changes: 1 addition & 1 deletion stages/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def find_mask(photo_path, masks):
(p, ext) = os.path.splitext(r)
if p[-5:] == "_mask" and ext.lower() in context.supported_extensions:
masks[p] = r

photos = []
with open(tree.dataset_list, 'w') as dataset_list:
log.ODM_INFO("Loading %s images" % len(path_files))
Expand Down

0 comments on commit 9acbaf5

Please sign in to comment.