Skip to content
Jasper Zanjani edited this page Sep 14, 2020 · 1 revision

👉 3 hour course

cv2.cvtColor

Convert colorspace 18:14

img = cv2.imread('image.png')
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow("Grayscale image", imgGray)
cv2.waitKey(0)

cv2.GaussianBlur

ksize must be tuple of odd values

imgBlur = cv2.GaussianBlur(img, ksize=(7,7), sigmaX=0)
cv2.imshow('Blurred image', imgBlur)
cv2.waitKey(0)

cv2.imread

img = cv2.imread('lena.png')

cv2.imshow

Takes two arguments:

  • Name of the window in which to display the image
  • The image itself
cv2.imshow("Output",img)
cv2.waitKey(0)

cv2.read

cap = cv2.VideoCapture("video.mp4")

while True:
  success, img = cap.read()
  cv2.imshow("Video",img)

cv2.VideoCapture

cap = cv2.VideoCapture("video.mp4")

while True:
  success, img = cap.read()
  cv2.imshow("Video",img)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cv2.waitKey

Used to prevent window from automatically closing

cv2.waitKey(0)

Breaking out of a loop

if cv2.waitKey(1) & 0xFF == ord('q')
  break
Clone this wiki locally