Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OpenCV blur image

  • blur

  • Average the intensity of all the pixels in the kernel (window)

  • Median - helps reduce the nois in the image

  • Gaussian blur - less blurring than the average blurring, but more natural

  • Increasing the ksize (kernel size) and the image will be more blurred.

import cv2 as cv
import sys

if len(sys.argv) != 3:
    exit(f"Usage: {sys.argv[0]} FILENAME KERNEL")

filename = sys.argv[1]
kernel = int(sys.argv[2])

original = cv.imread(filename)
cv.imshow('Original', original)

blurred = cv.blur(original, ksize=(kernel, kernel))

cv.imshow('Blurred', blurred)
cv.waitKey(0)