-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsmooth_image.py
59 lines (36 loc) · 1.72 KB
/
smooth_image.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
55
56
57
58
59
#####################################################################
# Example : displaying an image from file (and smoothing it)
# Author : Toby Breckon, toby.breckon@durham.ac.uk
# Copyright (c) 2015 School of Engineering & Computing Science,
# Durham University, UK
# License : LGPL - http://www.gnu.org/licenses/lgpl.html
#####################################################################
import cv2
#####################################################################
# define display window name
window_name = "Smoothed Image" # window name
# read an image from the specified file (in colour)
img = cv2.imread('example.jpg', cv2.IMREAD_COLOR)
# check it has loaded
if img is not None:
# performing smoothing on the image using a 5x5 smoothing mark (see manual
# entry for GaussianBlur())
blur = cv2.GaussianBlur(img, (5, 5), 0)
# display this blurred image in a named window
cv2.imshow(window_name, blur)
# start the event loop - essential
# cv2.waitKey() is a keyboard binding function (argument is the time in
# ms). It waits for specified milliseconds for any keyboard event.
# If you press any key in that time, the program continues.
# If 0 is passed, it waits indefinitely for a key stroke.
# (bitwise and with 0xFF to extract least significant byte of
# multi-byte response)
key = cv2.waitKey(0) & 0xFF # wait
# It can also be set to detect specific key strokes by recording which key
# is pressed
# e.g. if user presses "x" then exit and close all windows
if (key == ord('x')):
cv2.destroyAllWindows()
else:
print("No image file successfully loaded.")
#####################################################################