C++ OpenCV 自带颜色表操作

1.API

1.applyColorMap 应用颜色图

共3个参数

第1个参数 输入矩阵

第2个参数 输出矩阵

第3个参数 颜色图(查阅官方文档可知)

2.实例代码

循环转换颜色风格
我们首先把颜色表做成一个枚举数组



int colormap[]= {
     COLORMAP_AUTUMN,
     COLORMAP_BONE,
     COLORMAP_JET,
     COLORMAP_WINTER,
     COLORMAP_RAINBOW,
     COLORMAP_OCEAN,
     COLORMAP_SUMMER,
     COLORMAP_SPRING,
     COLORMAP_COOL,
     COLORMAP_HSV,//10
	 COLORMAP_PINK,
	 COLORMAP_HOT,
     COLORMAP_PARULA,
     COLORMAP_MAGMA,
     COLORMAP_INFERNO,
     COLORMAP_PLASMA,
     COLORMAP_VIRIDIS,
     COLORMAP_CIVIDIS,
     COLORMAP_TWILIGHT,
     COLORMAP_TWILIGHT_SHIFTED,//20
     COLORMAP_TURBO,
     COLORMAP_DEEPGREEN
};


通过applyColorMap以及1个while循环,我们便可以实现颜色风格的循环转换 



void QuickDemo::color_style_demo(Mat& image) {

	int colormap[] = {
	 COLORMAP_AUTUMN,
	 COLORMAP_BONE,
	 COLORMAP_JET,
	 COLORMAP_WINTER,
	 COLORMAP_RAINBOW,
	 COLORMAP_OCEAN,
	 COLORMAP_SUMMER,
	 COLORMAP_SPRING,
	 COLORMAP_COOL,
	 COLORMAP_HSV,//10
	 COLORMAP_PINK,
	 COLORMAP_HOT,
	 COLORMAP_PARULA,
	 COLORMAP_MAGMA,
	 COLORMAP_INFERNO,
	 COLORMAP_PLASMA,
	 COLORMAP_VIRIDIS,
	 COLORMAP_CIVIDIS,
	 COLORMAP_TWILIGHT,
	 COLORMAP_TWILIGHT_SHIFTED,//20
	 COLORMAP_TURBO,
	 COLORMAP_DEEPGREEN
	};

	Mat dst;
	int index = 0;
	while (true) {

		int c = waitKey(500);

		if (c == 27) {//退出
			break;
		}
		applyColorMap(image, dst, colormap[index % 22]);

		index++;
		imshow("22种颜色风格",dst);
	}
}

你可能感兴趣的:(C++,opencv,opencv,人工智能,计算机视觉)