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