自带颜色表操作
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
//自带颜色表
void color_style_demo(cv::Mat& image)
{
int colorMap[] = {
COLORMAP_AUTUMN,
COLORMAP_BONE,
COLORMAP_JET,
COLORMAP_WINTER,
COLORMAP_RAINBOW,
COLORMAP_OCEAN,
COLORMAP_SUMMER,
COLORMAP_SPRING,
COLORMAP_COOL,
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(2000);
if (c == 27)//esc键
{
break;
}
applyColorMap(image, dst, colorMap[index % 19]);
index++;
imshow("颜色风格", dst);
if (c == 49)
{
imwrite("C:\\Users\\四明\\Pictures\\index.jpg" ,dst);
}
}
}
int main()
{
string path = "C:\\Users\\四明\\Pictures\\QQ图片20200608155343.jpg";
Mat img = imread(path);
if (img.empty())
{
cout << "图片加载失败!" << endl;
return -1;
}
namedWindow("image", WINDOW_FREERATIO);
imshow("image", img);
color_style_demo(img);
waitKey(0);
destroyAllWindows();
return 0;
}
效果图(简单展示几张)