Skip to content

Instantly share code, notes, and snippets.

@jhh
Last active September 1, 2016 01:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhh/dce53b919a60dc98a84b68dc4657a3ab to your computer and use it in GitHub Desktop.
Save jhh/dce53b919a60dc98a84b68dc4657a3ab to your computer and use it in GitHub Desktop.
Solution to exercise 1.
import cv2
import sys
import os
# usage: python ex_001.py path/to/image.jpg
imgPath = sys.argv[1]
if not os.path.isfile(imgPath):
print("Image file not found.")
sys.exit()
# read in the image
img = cv2.imread(imgPath)
# display the image and wait for key press
cv2.imshow('original', img)
cv2.waitKey(0)
# convert to grayscale and display
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('grayscale', gray)
cv2.waitKey(0)
# apply a blue and display
blurred = cv2.blur(gray, (9, 9))
cv2.imshow('blurred', blurred)
cv2.waitKey(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment