原文链接: opencv rgb 颜色空间 彩虹色
上一篇: opencv hsv 颜色空间 彩虹色
下一篇: opencv 漫水填充 泛洪填充
参考
https://blog.csdn.net/bjbz_cxy/article/details/79701006
rgb颜色空间
使用opencv 生成彩虹图
颜色rgb 值
# 赤 (255,0,0)
# 橙 (255,165,0)
# 黄 (255,255,0)
# 绿 (0,255,0)
# 青 (0,127,255)
# 蓝 (0,0,255)
# 紫 (139,0.255)
注意 : opencv 中默认顺序为bgr !!!
import cv2 as cv
import numpy as np
# rgb,bgr
# 赤 (255,0,0)
# 橙 (255,165,0)
# 黄 (255,255,0)
# 绿 (0,255,0)
# 青 (0,127,255)
# 蓝 (0,0,255)
# 紫 (139,0.255)
img = np.zeros([600, 6 * 100, 3])
# 每个颜色间隔100步
steps = 100
# 赤-橙
img[:, :100, 2] = 255
img[:, :100, 1] = np.linspace(0, 165, 100)
img[:, :100, 0] = 0
# 橙-黄
img[:, 100:200, 2] = 255
img[:, 100:200, 1] = np.linspace(165, 255, 100)
img[:, 100:200, 0] = 0
# 黄-绿
img[:, 200:300, 2] = np.linspace(0, 255, 100)[::-1]
img[:, 200:300, 1] = 255
img[:, 200:300, 0] = 0
# 绿-青
img[:, 300:400, 2] = 0
img[:, 300:400, 1] = np.linspace(127, 255, 100)[::-1]
img[:, 300:400, 0] = np.linspace(0, 255, 100)
# 青-蓝
img[:, 400:500, 2] = 0
img[:, 400:500, 1] = np.linspace(0, 127, 100)[::-1]
img[:, 400:500, 0] = 255
# 蓝-紫
img[:, 500:600, 2] = np.linspace(0, 139, 100)
img[:, 500:600, 1] = 0
img[:, 500:600, 0] = 255
# img[:, :, 1] = np.arange(0, 255, dtype=np.uint8)
# img[:, :, 2] = 255 - img[:, :, 0]
# img[:, :, 0] = np.arange(0, 255, dtype=np.uint8).reshape([255, 1])
img = img.astype(np.uint8)
# print(img[:, :, 0])
# print(img[:, :, 1])
# print(img[:, :, 2])
print(img[:, :200, 0])
print(img[:, :200, 1])
print(img[:, :200, 2])
cv.imshow('img', img)
# cv.imshow('hsv', cv.cvtColor(img, cv.COLOR_HSV2RGB))
cv.waitKey(0)
对每个颜色进行处理,每个颜色间隔100像素,每个颜色线性递增
注意最后需要修改np数组类型,否则报错