import cv2 as cv
read = cv.imread(image_path)
applying_color_spaces = cv.cvtColor(read, g)
在g
位置,我要一个接一个地应用所有色彩空间并将图像写入桌面。
答案 0 :(得分:1)
只需一个简单的代码片段即可开始。我使用了两个列表:
代码:
import os
import cv2
read = cv2.imread(r'C:\Users\Jackson\Desktop\leaf.JPG', cv2.IMREAD_COLOR)
color_name = ['gray', 'HSV', 'LAB', 'YCrCb']
color_spaces = [cv2.COLOR_BGR2GRAY, cv2.COLOR_BGR2HSV, cv2.COLOR_BGR2LAB, cv2.COLOR_BGR2YCrCb]
for name, i in zip(color_name, color_spaces):
res = cv2.cvtColor(read, i)
cv2.imwrite(os.path.join(r'C:\Users\Jackson\Desktop', name + '.jpg'), res)