A basic example on image stitching in Python.
7 Show how to use Stitcher API from python in a simple way to stitch panoramas 12 from __future__
import print_function
20 modes = (cv.Stitcher_PANORAMA, cv.Stitcher_SCANS)
22 parser = argparse.ArgumentParser(prog=
'stitching.py', description=
'Stitching sample.')
23 parser.add_argument(
'--mode',
24 type = int, choices = modes, default = cv.Stitcher_PANORAMA,
25 help =
'Determines configuration of stitcher. The default is `PANORAMA` (%d), ' 26 'mode suitable for creating photo panoramas. Option `SCANS` (%d) is suitable ' 27 'for stitching materials under affine transformation, such as scans.' % modes)
28 parser.add_argument(
'--output', default =
'result.jpg',
29 help =
'Resulting image. The default is `result.jpg`.')
30 parser.add_argument(
'img', nargs=
'+', help =
'input images')
32 __doc__ +=
'\n' + parser.format_help()
35 args = parser.parse_args()
39 for img_name
in args.img:
42 print(
"can't read image " + img_name)
47 status, pano = stitcher.stitch(imgs)
49 if status != cv.Stitcher_OK:
50 print(
"Can't stitch images, error code = %d" % status)
54 print(
"stitching completed successfully. %s saved!" % args.output)
59 if __name__ ==
'__main__':