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__':
static Ptr< Stitcher > create(Mode mode=Stitcher::PANORAMA)
Creates a Stitcher configured in one of the stitching modes.
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
Try to find requested data file.
void destroyAllWindows()
Destroys all of the HighGUI windows.
CV_EXPORTS_W bool imwrite(const String &filename, InputArray img, const std::vector< int > ¶ms=std::vector< int >())
Saves an image to a specified file.
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR)
Loads an image from a file.
static void print(const MatShape &shape, const String &name="")
Definition: shape_utils.hpp:198