1from __future__ import print_function
2from __future__ import division
3import cv2 as cv
4import argparse
5
6alpha_slider_max = 100
7title_window = 'Linear Blend'
8
9## [on_trackbar]
10def on_trackbar(val):
11    alpha = val / alpha_slider_max
12    beta = ( 1.0 - alpha )
13    dst = cv.addWeighted(src1, alpha, src2, beta, 0.0)
14    cv.imshow(title_window, dst)
15## [on_trackbar]
16
17parser = argparse.ArgumentParser(description='Code for Adding a Trackbar to our applications tutorial.')
18parser.add_argument('--input1', help='Path to the first input image.', default='LinuxLogo.jpg')
19parser.add_argument('--input2', help='Path to the second input image.', default='WindowsLogo.jpg')
20args = parser.parse_args()
21
22## [load]
23# Read images ( both have to be of the same size and type )
24src1 = cv.imread(cv.samples.findFile(args.input1))
25src2 = cv.imread(cv.samples.findFile(args.input2))
26## [load]
27if src1 is None:
28    print('Could not open or find the image: ', args.input1)
29    exit(0)
30
31if src2 is None:
32    print('Could not open or find the image: ', args.input2)
33    exit(0)
34
35## [window]
36cv.namedWindow(title_window)
37## [window]
38
39## [create_trackbar]
40trackbar_name = 'Alpha x %d' % alpha_slider_max
41cv.createTrackbar(trackbar_name, title_window , 0, alpha_slider_max, on_trackbar)
42## [create_trackbar]
43
44# Show some stuff
45on_trackbar(0)
46
47# Wait until user press some key
48cv.waitKey()
49