samples: fix python samples compatibility with demo.py

pull/14124/head
Alexander Alekhin 6 years ago committed by Alexander Alekhin
parent a509ec0d91
commit fbed33cc1f
  1. 10
      samples/python/dis_opt_flow.py
  2. 21
      samples/python/stitching.py
  3. 89
      samples/python/stitching_detailed.py

@ -18,6 +18,7 @@ from __future__ import print_function
import numpy as np
import cv2 as cv
import video
@ -56,7 +57,7 @@ def warp_flow(img, flow):
return res
if __name__ == '__main__':
def main():
import sys
print(__doc__)
try:
@ -111,4 +112,11 @@ if __name__ == '__main__':
if ch == ord('4'):
use_temporal_propagation = not use_temporal_propagation
print('temporal propagation is', ['off', 'on'][use_temporal_propagation])
print('Done')
if __name__ == '__main__':
print(__doc__)
main()
cv.destroyAllWindows()

@ -8,15 +8,18 @@ Show how to use Stitcher API from python in a simple way to stitch panoramas
or scans.
'''
# Python 2/3 compatibility
from __future__ import print_function
import cv2 as cv
import numpy as np
import cv2 as cv
import argparse
import sys
modes = (cv.Stitcher_PANORAMA, cv.Stitcher_SCANS)
parser = argparse.ArgumentParser(description='Stitching sample.')
parser = argparse.ArgumentParser(prog='stitching.py', description='Stitching sample.')
parser.add_argument('--mode',
type = int, choices = modes, default = cv.Stitcher_PANORAMA,
help = 'Determines configuration of stitcher. The default is `PANORAMA` (%d), '
@ -25,12 +28,16 @@ parser.add_argument('--mode',
parser.add_argument('--output', default = 'result.jpg',
help = 'Resulting image. The default is `result.jpg`.')
parser.add_argument('img', nargs='+', help = 'input images')
__doc__ += '\n' + parser.format_help()
def main():
args = parser.parse_args()
# read input images
imgs = []
for img_name in args.img:
img = cv.imread(img_name)
img = cv.imread(cv.samples.findFile(img_name))
if img is None:
print("can't read image " + img_name)
sys.exit(-1)
@ -45,3 +52,11 @@ if status != cv.Stitcher_OK:
cv.imwrite(args.output, pano);
print("stitching completed successfully. %s saved!" % args.output)
print('Done')
if __name__ == '__main__':
print(__doc__)
main()
cv.destroyAllWindows()

@ -1,71 +1,20 @@
"""Rotation model images stitcher.
stitching_detailed img1 img2 [...imgN] [flags]
Flags:
--preview
Run stitching in the preview mode. Works faster than usual mode,
but output image will have lower resolution.
--try_cuda (yes|no)
Try to use CUDA. The default value is 'no'. All default values
are for CPU mode.
\nMotion Estimation Flags:
--work_megapix <float>
Resolution for image registration step. The default is 0.6 Mpx.
--features (surf|orb|sift)
Type of features used for images matching. The default is surf.
--matcher (homography|affine)
Matcher used for pairwise image matching.
--estimator (homography|affine)
Type of estimator used for transformation estimation.
--match_conf <float>
Confidence for feature matching step. The default is 0.65 for surf and 0.3 for orb.
--conf_thresh <float>
Threshold for two images are from the same panorama confidence.
The default is 1.0.
--ba (no|reproj|ray|affine)
Bundle adjustment cost function. The default is ray.
--ba_refine_mask (mask)
Set refinement mask for bundle adjustment. It looks like 'x_xxx',
where 'x' means refine respective parameter and '_' means don't
refine one, and has the following format:
<fx><skew><ppx><aspect><ppy>. The default mask is 'xxxxx'. If bundle
adjustment doesn't support estimation of selected parameter then
the respective flag is ignored.
--wave_correct (no|horiz|vert)
Perform wave effect correction. The default is 'horiz'.
--save_graph <file_name>
Save matches graph represented in DOT language to <file_name> file.
Labels description: Nm is number of matches, Ni is number of inliers,
C is confidence.
\nCompositing Flags:
--warp (affine|plane|cylindrical|spherical|fisheye|stereographic|compressedPlaneA2B1|compressedPlaneA1.5B1|compressedPlanePortraitA2B1|compressedPlanePortraitA1.5B1|paniniA2B1|paniniA1.5B1|paniniPortraitA2B1|paniniPortraitA1.5B1|mercator|transverseMercator)
Warp surface type. The default is 'spherical'.
--seam_megapix <float>
Resolution for seam estimation step. The default is 0.1 Mpx.
--seam (no|voronoi|gc_color|gc_colorgrad)
Seam estimation method. The default is 'gc_color'.
--compose_megapix <float>
Resolution for compositing step. Use -1 for original resolution.
The default is -1.
--expos_comp (no|gain|gain_blocks)
Exposure compensation method. The default is 'gain_blocks'.
--blend (no|feather|multiband)
Blending method. The default is 'multiband'.
--blend_strength <float>
Blending strength from [0,100] range. The default is 5.
--output <result_img>
The default is 'result.jpg'.
--timelapse (as_is|crop)
Output warped images separately as frames of a time lapse movie, with 'fixed_' prepended to input file names.
--rangewidth <int>
uses range_width to limit number of images to match with.\n
"""
Stitching sample (advanced)
===========================
Show how to use Stitcher API from python.
"""
# Python 2/3 compatibility
from __future__ import print_function
import numpy as np
import cv2 as cv
import sys
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='stitching_detailed')
parser = argparse.ArgumentParser(prog='stitching_detailed.py', description='Rotation model images stitcher')
parser.add_argument('img_names', nargs='+',help='files to stitch',type=str)
parser.add_argument('--preview',help='Run stitching in the preview mode. Works faster than usual mode but output image will have lower resolution.',type=bool,dest = 'preview' )
parser.add_argument('--try_cuda',action = 'store', default = False,help='Try to use CUDA. The default value is no. All default values are for CPU mode.',type=bool,dest = 'try_cuda' )
@ -92,6 +41,10 @@ if __name__ == '__main__':
parser.add_argument('--output',action = 'store', default = 'result.jpg',help='The default is "result.jpg"',type=str,dest = 'output' )
parser.add_argument('--timelapse',action = 'store', default = None,help='Output warped images separately as frames of a time lapse movie, with "fixed_" prepended to input file names.',type=str,dest = 'timelapse' )
parser.add_argument('--rangewidth',action = 'store', default = -1,help='uses range_width to limit number of images to match with.',type=int,dest = 'rangewidth' )
__doc__ += '\n' + parser.format_help()
def main():
args = parser.parse_args()
img_names=args.img_names
print(img_names)
@ -167,7 +120,7 @@ if __name__ == '__main__':
is_seam_scale_set = False
is_compose_scale_set = False;
for name in img_names:
full_img = cv.imread(name)
full_img = cv.imread(cv.samples.findFile(name))
if full_img is None:
print("Cannot read image ", name)
exit()
@ -401,8 +354,16 @@ if __name__ == '__main__':
result_mask=None
result,result_mask = blender.blend(result,result_mask)
cv.imwrite(result_name,result)
zoomx =600/result.shape[1]
zoomx = 600.0 / result.shape[1]
dst=cv.normalize(src=result,dst=None,alpha=255.,norm_type=cv.NORM_MINMAX,dtype=cv.CV_8U)
dst=cv.resize(dst,dsize=None,fx=zoomx,fy=zoomx)
cv.imshow(result_name,dst)
cv.waitKey()
print('Done')
if __name__ == '__main__':
print(__doc__)
main()
cv.destroyAllWindows()

Loading…
Cancel
Save