1、applyColorMap()函数的使用:
使用applyColorMap()函数,可以将灰度图或彩色图转换成自定义的彩色图,或opencv提供的20多种色彩值文章来源:https://www.toymoban.com/news/detail-518875.html
(1)函数原型:
void applyColorMap(InputArray src, OutputArray dst, int colormap)
- src:源图像,灰度图或彩色图( CV_8UC1 or CV_8UC3 );
- dst:在源图像上进行色彩映射后的结果图像;
- colormap:opencv提供的色彩值;
// opencv提供的色彩值 int colorMap[] = { COLORMAP_AUTUMN, COLORMAP_BONE, COLORMAP_JET, COLORMAP_WINTER, COLORMAP_RAINBOW, COLORMAP_OCEAN, COLORMAP_SUMMER, COLORMAP_SPRING, COLORMAP_COOL, COLORMAP_HSV, COLORMAP_PINK, COLORMAP_HOT, COLORMAP_PARULA, COLORMAP_MAGMA, COLORMAP_INFERNO, COLORMAP_PLASMA, COLORMAP_VIRIDIS, COLORMAP_CIVIDIS, COLORMAP_TWILIGHT, COLORMAP_TWILIGHT_SHIFTED };
void applyColorMap(InputArray src, OutputArray dst, InputArray userColor)
- src:源图像,灰度图或彩色图( CV_8UC1 or CV_8UC3 );
- dst:在源图像上进行色彩映射后的结果图像;
- userColor:用户自定义的色彩(CV_8UC1 or CV_8UC3 and size 256);
(2)示例:
// 将灰度图或彩色图转换成opencv提供的20多种色彩值
void QuickDemo::colorStyle(Mat &image) {
// opencv提供的色彩值
int colorMap[] = {
COLORMAP_AUTUMN,
COLORMAP_BONE,
COLORMAP_JET,
COLORMAP_WINTER,
COLORMAP_RAINBOW,
COLORMAP_OCEAN,
COLORMAP_SUMMER,
COLORMAP_SPRING,
COLORMAP_COOL,
COLORMAP_HSV,
COLORMAP_PINK,
COLORMAP_HOT,
COLORMAP_PARULA,
COLORMAP_MAGMA,
COLORMAP_INFERNO,
COLORMAP_PLASMA,
COLORMAP_VIRIDIS,
COLORMAP_CIVIDIS,
COLORMAP_TWILIGHT,
COLORMAP_TWILIGHT_SHIFTED
};
Mat dst;
int index = 0;
while (true) {
int c = waitKey(200);
if (c == 27) { // 退出
break;
}
// index%19,index取模之后下标值在 0 - 19 之间循环,下标不会超过19
applyColorMap(image, dst, colorMap[index%19]);
index++;
namedWindow("colorStyle", WINDOW_NORMAL);
imshow("colorStyle", dst);
}
}
成果展示:
文章来源地址https://www.toymoban.com/news/detail-518875.html
到了这里,关于opencv使用applyColorMap()函数,可以将灰度图或彩色图转换成自定义的彩色图,或opencv提供的20多种色彩值的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!