-
Notifications
You must be signed in to change notification settings - Fork 0
/
zoom_in_with_trackbar.py
54 lines (39 loc) · 1.23 KB
/
zoom_in_with_trackbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import cv2
maxScaleUp = 100
scaleFactor = 1
scaleType = 0
maxType = 1
windowName = "Resize Image"
trackbarValue = "Scale"
# load an image
im = cv2.imread("/home/jean/Pictures/download.jpeg")
# Create a window to display results
cv2.namedWindow(windowName, cv2.WINDOW_AUTOSIZE)
# Callback functions
def scaleImage(*args):
global scaleFactor
global scaleType
# Get the scale factor from the trackbar
scaleFactor = 1+ args[0]/100.0
# Perform check if scaleFactor is zero
if scaleFactor == 0:
scaleFactor = 1
# Resize the image
scaledImage = cv2.resize(im, None, fx=scaleFactor,\
fy = scaleFactor, interpolation = cv2.INTER_LINEAR)
cv2.imshow(windowName, scaledImage)
# Callback functions
def scaleTypeImage(*args):
global scaleType
global scaleFactor
scaleType = args[0]
scaleFactor = 1 + scaleFactor/100.0
if scaleFactor ==0:
scaleFactor = 1
scaledImage = cv2.resize(im, None, fx=scaleFactor,\
fy = scaleFactor, interpolation = cv2.INTER_LINEAR)
cv2.imshow(windowName, scaledImage)
cv2.createTrackbar(trackbarValue, windowName, scaleFactor, maxScaleUp, scaleImage)
cv2.imshow(windowName, im)
c = cv2.waitKey(0)
cv2.destroyAllWindows()