个人资料,仅供学习使用
学习课程:OpenCV4 C++ 快速入门视频30讲——贾志刚
opencv知识点:
本科所解决的问题:
opencv提供22种颜色风格的查找表映射,官方文档查阅ColormapTypes
即可
在使用的时候要用到applyColorMap
,传入对应colormap
,就可以进行颜色风格的转换
applyColorMap
应用颜色图
共3个参数
第1个参数 输入
第2个参数 输出
第3个参数 颜色图(查阅官方文档可知)
如我们传入COLORMAP_DEEPGREEN
,就会有如下效果
void QuickDemo::color_style_demo(Mat& image) {
Mat dst;
applyColorMap(image, dst, COLORMAP_DEEPGREEN);
imshow("COLORMAP_DEEPGREEN", dst);
}
我们首先把颜色表做成一个枚举数组
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);
}
}
OpenCV 4.6.0 官方文档