@@ -552,16 +552,19 @@ def compute_using(algorithm):
552552 log .ODM_WARNING ("Compute homography: %s" % str (e ))
553553 return None , (None , None ), None
554554
555- def find_ecc_homography (image_gray , align_image_gray , number_of_iterations = 1000 , termination_eps = 1e-8 , start_eps = 1e-4 , warp_matrix_init = None ):
555+ def find_ecc_homography (image_gray , align_image_gray , number_of_iterations = 2000 , termination_eps = 1e-8 , start_eps = 1e-4 , warp_matrix_init = None ):
556556 # Major props to Alexander Reynolds for his insight into the pyramided matching process found at
557557 # https://stackoverflow.com/questions/45997891/cv2-motion-euclidean-for-the-warp-mode-in-ecc-image-alignment-method
558558 pyramid_levels = 0
559559 h ,w = image_gray .shape
560560 min_dim = min (h , w )
561561
562- number_of_iterations = 1000 if min_dim > 300 else 5000
563- termination_eps = 1e-8 if min_dim > 300 else 1e-6
564- gaussian_filter_size = 9 # if min_dim > 300 else 5
562+ if (min_dim <= 300 ):
563+ number_of_iterations = 5000
564+ termination_eps = 1e-6
565+ gaussian_filter_size = 9 # a constant since there is only one pyramid level
566+ else :
567+ gaussian_filter_size = 5 # will be increased in each pyramid level iteration
565568
566569 while min_dim > 300 :
567570 min_dim /= 2.0
@@ -609,8 +612,9 @@ def find_ecc_homography(image_gray, align_image_gray, number_of_iterations=1000,
609612 number_of_iterations , eps )
610613
611614 try :
615+ gaussian_filter_size = gaussian_filter_size + level * 2
612616 log .ODM_INFO ("Computing ECC pyramid level %s using Gaussian filter size %s" % (level , gaussian_filter_size ))
613- _ , warp_matrix = cv2 .findTransformECC (ig , aig , warp_matrix , cv2 .MOTION_HOMOGRAPHY , criteria , inputMask = None , gaussFiltSize = gaussian_filter_size )
617+ _ , warp_matrix = cv2 .findTransformECC (ig , aig , warp_matrix , cv2 .MOTION_HOMOGRAPHY , criteria , inputMask = None , gaussFiltSize = gaussian_filter_size )
614618 except Exception as e :
615619 if level != pyramid_levels :
616620 log .ODM_INFO ("Could not compute ECC warp_matrix at pyramid level %s, resetting matrix" % level )
@@ -625,7 +629,7 @@ def find_ecc_homography(image_gray, align_image_gray, number_of_iterations=1000,
625629
626630 return warp_matrix
627631
628- def find_features_homography (image_gray , align_image_gray , feature_retention = 0.7 , min_match_count = 10 ):
632+ def find_features_homography (image_gray , align_image_gray , feature_retention = 0.8 , min_match_count = 4 ):
629633
630634 # Detect SIFT features and compute descriptors.
631635 detector = cv2 .SIFT_create () # edgeThreshold=10, contrastThreshold=0.1 (default 0.04)
0 commit comments