对于各种色彩空间的变化,opencv 都给我我们相应的接口,直接调用即可,下面我们来看一下:
def color_space_demo(image):
# trans to gray
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.namedWindow('gray_space', cv2.WINDOW_AUTOSIZE)
cv2.imshow('gray_space', gray)
# trans to hsv
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
cv2.namedWindow('HSV_space', cv2.WINDOW_AUTOSIZE)
cv2.imshow('HSV_space', hsv)
# trans to yuv
yuv = cv2.cvtColor(image, cv2.COLOR_BGR2YUV)
cv2.namedWindow('YUV_space', cv2.WINDOW_AUTOSIZE)
cv2.imshow('YUV_space', yuv)
# trans to Ycrcb
ycrcb = cv2.cvtColor(image, cv2.COLOR_BGR2YCrCb)
cv2.namedWindow('Ycrcb_space', cv2.WINDOW_AUTOSIZE)
cv2.imshow('Ycrcb_sp