還沒看過前一篇的記得先看吶!!

想了解HSV&HSL差異可以看看這篇呦!

1
2
3
4
5
6
7
8
9
10
11
12
import cv2 as cv
import matplotlib.pyplot as plt

img = cv.imread('../Resources/Photos/park.jpg')
cv.imshow('Park', img)

#-------block--------

#------endblock------

cv.waitKey(0)

將block替換成以下內容可以得到同效果:

灰階

1
2
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
cv.imshow('Gray', gray)

HSV

1
2
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV)
cv.imshow('HSV', hsv)

LAB

1
2
lab = cv.cvtColor(img, cv.COLOR_BGR2LAB)
cv.imshow('LAB', lab)

BGR to RGB

1
2
rgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
cv.imshow('RGB', rgb)

HSV to BGR

1
2
lab_bgr = cv.cvtColor(lab, cv.COLOR_LAB2BGR)
cv.imshow('LAB --> BGR', lab_bgr)

參考

  1. Python-OpenCV — 讀取顯示及儲存影像、影片

  2. Python-OpenCV — 影像運算及轉換

  3. OpenCV Course - Full Tutorial with Python