From 54693cf7b1a32d15504308b7499b8b9160f016b5 Mon Sep 17 00:00:00 2001 From: Jeremy Ephron Date: Wed, 2 Mar 2022 11:01:53 -0800 Subject: [PATCH] Update stitching_detailed.py ### Critical bugs fixed: - `seam_finder.find()` returns None and overwrites `masks_warped` - `indices` is only 1-dimensional ### Nice-to-have bugs fixed: - avoid invalid value in sqrt and subsequent runtime warning - avoid printing help string on each run (use argparse builtin behavior) ### New features: - added graphcut seam finder support ### Test Summary: Tested on Ubuntu 20.04 with python 3.8.10 and opencv-python-contrib 4.5.5.62 --- samples/python/stitching_detailed.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/samples/python/stitching_detailed.py b/samples/python/stitching_detailed.py index 333ea15648..56d6965733 100644 --- a/samples/python/stitching_detailed.py +++ b/samples/python/stitching_detailed.py @@ -324,7 +324,10 @@ def main(): is_work_scale_set = True img = cv.resize(src=full_img, dsize=None, fx=work_scale, fy=work_scale, interpolation=cv.INTER_LINEAR_EXACT) if is_seam_scale_set is False: - seam_scale = min(1.0, np.sqrt(seam_megapix * 1e6 / (full_img.shape[0] * full_img.shape[1]))) + if seam_megapix > 0: + seam_scale = min(1.0, np.sqrt(seam_megapix * 1e6 / (full_img.shape[0] * full_img.shape[1]))) + else: + seam_scale = 1.0 seam_work_aspect = seam_scale / work_scale is_seam_scale_set = True img_feat = cv.detail.computeImageFeatures2(finder, img) @@ -345,9 +348,9 @@ def main(): img_names_subset = [] full_img_sizes_subset = [] for i in range(len(indices)): - img_names_subset.append(img_names[indices[i, 0]]) - img_subset.append(images[indices[i, 0]]) - full_img_sizes_subset.append(full_img_sizes[indices[i, 0]]) + img_names_subset.append(img_names[indices[i]]) + img_subset.append(images[indices[i]]) + full_img_sizes_subset.append(full_img_sizes[indices[i]]) images = img_subset img_names = img_names_subset full_img_sizes = full_img_sizes_subset @@ -479,7 +482,7 @@ def main(): blender = cv.detail.Blender_createDefault(cv.detail.Blender_NO) elif blend_type == "multiband": blender = cv.detail_MultiBandBlender() - blender.setNumBands((np.log(blend_width) / np.log(2.) - 1.).astype(np.int)) + blender.setNumBands((np.log(blend_width) / np.log(2.) - 1.).astype(np.int32)) elif blend_type == "feather": blender = cv.detail_FeatherBlender() blender.setSharpness(1. / blend_width) @@ -513,6 +516,5 @@ def main(): if __name__ == '__main__': - print(__doc__) main() cv.destroyAllWindows()