opencv_python学习(九)----cv自带colormap操作
一、函数cv2.applyColorMap
功能:
在图像处理中,伪色彩用途广泛。在OpenCV库中,常见的伪色彩模式都可通过 cv2.applyColorMap(src, userColor[, dst]) 直接调用,很是方便快捷。 将对象按照cv内置colormap进行转换
API详解:
def applyColorMap(src: Any,colormap: Any,dst: Any = None) -> None
- src :待转换对象
- colormap:内置map选择
二、一个demo
import cv2 as cv
def color_map_demo():
image = cv.imread('图片路径')
cv.imshow('input',image)
colormap = [
cv.COLORMAP_HOT,
cv.COLORMAP_HSV,
cv.COLORMAP_JET,
cv.COLORMAP_MAGMA,
cv.COLORMAP_COOL,
cv.COLORMAP_SPRING,
cv.COLORMAP_SUMMER,
cv.COLORMAP_AUTUMN,
cv.COLORMAP_WINTER,
cv.COLORMAP_BONE,
cv.COLORMAP_CIVIDIS,
cv.COLORMAP_HOT,
cv.COLORMAP_DEEPGREEN,
cv.COLORMAP_INFERNO,
cv.COLORMAP_OCEAN,
cv.COLORMAP_PARULA,
cv.COLORMAP_PINK,
cv.COLORMAP_PLASMA,
cv.COLORMAP_RAINBOW,
cv.COLORMAP_TURBO,
cv.COLORMAP_TWILIGHT,
cv.COLORMAP_TWILIGHT_SHIFTED,
cv.COLORMAP_VIRIDIS
]
index = 0
while True:
result = cv.applyColorMap(image,colormap[index%23])
index +=1
cv.imshow('result',result)
c = cv.waitKey(300)
if c == 27:
break
cv.destroyAllWindows()
if __name__ == '__main__':
color_map_demo()
|