Merge pull request #19931 from lukasalexanderweber:patch-1
authorLukas-Alexander Weber <32765578+lukasalexanderweber@users.noreply.github.com>
Mon, 26 Apr 2021 14:47:50 +0000 (16:47 +0200)
committerGitHub <noreply@github.com>
Mon, 26 Apr 2021 14:47:50 +0000 (14:47 +0000)
Stitching Detailed Tutorial Improvements

* Add Vertical Wave Correction

The user has the possibility to pass "vert" as wave_correct parameter. However, in the code "cv.detail.WAVE_CORRECT_HORIZ" ist fixed. This change proposes changes so that the wave correction is done vertically if the user passes "vert" as wave_correct parameter. The variable "do_wave_correct" is replaced by None which is passed to the variable "wave_correct" if the user chooses "no" for wave correction.

* Correct fixed conf_thresh

According to the documentation, [cv.detail.leaveBiggestComponent](https://docs.opencv.org/4.5.1/d7/d74/group__stitching__rotation.html#ga855d2fccbcfc3b3477b34d415be5e786) takes features, the pairwise_matches and the conf_threshold as input.
In the tutorial, however, conf_threshold is fixed at 0.3 even though the user can pass conf_thresh as parameter which is 1 by default. Fixing this parameter at 0.3 causes the script to include images into the panorama which are not part of it.

samples/python/stitching_detailed.py

index 7bf5a9a..7253932 100644 (file)
@@ -79,7 +79,10 @@ WARP_CHOICES = (
     'transverseMercator',
 )
 
-WAVE_CORRECT_CHOICES = ('horiz', 'no', 'vert',)
+WAVE_CORRECT_CHOICES = OrderedDict()
+WAVE_CORRECT_CHOICES['horiz'] = cv.detail.WAVE_CORRECT_HORIZ
+WAVE_CORRECT_CHOICES['no'] = None
+WAVE_CORRECT_CHOICES['vert'] = cv.detail.WAVE_CORRECT_VERT
 
 BLEND_CHOICES = ('multiband', 'feather', 'no',)
 
@@ -147,9 +150,9 @@ parser.add_argument(
     type=str, dest='ba_refine_mask'
 )
 parser.add_argument(
-    '--wave_correct', action='store', default=WAVE_CORRECT_CHOICES[0],
-    help="Perform wave effect correction. The default is '%s'" % WAVE_CORRECT_CHOICES[0],
-    choices=WAVE_CORRECT_CHOICES,
+    '--wave_correct', action='store', default=list(WAVE_CORRECT_CHOICES.keys())[0],
+    help="Perform wave effect correction. The default is '%s'" % list(WAVE_CORRECT_CHOICES.keys())[0],
+    choices=WAVE_CORRECT_CHOICES.keys(),
     type=str, dest='wave_correct'
 )
 parser.add_argument(
@@ -279,11 +282,7 @@ def main():
     compose_megapix = args.compose_megapix
     conf_thresh = args.conf_thresh
     ba_refine_mask = args.ba_refine_mask
-    wave_correct = args.wave_correct
-    if wave_correct == 'no':
-        do_wave_correct = False
-    else:
-        do_wave_correct = True
+    wave_correct = WAVE_CORRECT_CHOICES[args.wave_correct]
     if args.save_graph is None:
         save_graph = False
     else:
@@ -343,7 +342,7 @@ def main():
         with open(args.save_graph, 'w') as fh:
             fh.write(cv.detail.matchesGraphAsString(img_names, p, conf_thresh))
 
-    indices = cv.detail.leaveBiggestComponent(features, p, 0.3)
+    indices = cv.detail.leaveBiggestComponent(features, p, conf_thresh)
     img_subset = []
     img_names_subset = []
     full_img_sizes_subset = []
@@ -393,11 +392,11 @@ def main():
         warped_image_scale = focals[len(focals) // 2]
     else:
         warped_image_scale = (focals[len(focals) // 2] + focals[len(focals) // 2 - 1]) / 2
-    if do_wave_correct:
+    if wave_correct is not None:
         rmats = []
         for cam in cameras:
             rmats.append(np.copy(cam.R))
-        rmats = cv.detail.waveCorrect(rmats, cv.detail.WAVE_CORRECT_HORIZ)
+        rmats = cv.detail.waveCorrect(rmats, wave_correct)
         for idx, cam in enumerate(cameras):
             cam.R = rmats[idx]
     corners = []