【原文:http://blog.csdn.net/yangtrees/article/details/9096435】
==============================================
版权所有:小熊不去实验室CSDN博客
==============================================
使用 applyColorMap()
enum
{
COLORMAP_AUTUMN = 0,
COLORMAP_BONE = 1,
COLORMAP_JET = 2,
COLORMAP_WINTER = 3,
COLORMAP_RAINBOW = 4,
COLORMAP_OCEAN = 5,
COLORMAP_SUMMER = 6,
COLORMAP_SPRING = 7,
COLORMAP_COOL = 8,
COLORMAP_HSV = 9,
COLORMAP_PINK = 10,
COLORMAP_HOT = 11
}
- #include <math.h>
- #include <opencv2/contrib/contrib.hpp>
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- using namespace cv;
- using namespace std;
- int main()
- {
- Mat src = imread("D:/img/face03.jpeg",1);
- int width = src.cols;
- int heigh = src.rows;
- Mat gray;
- Mat imgColor[12];
- Mat display(heigh*3,width*4,CV_8UC3);
- cvtColor(src,gray,CV_BGR2GRAY);
- for(int i=0; i<12; i++)
- {
- applyColorMap(gray,imgColor[i],i);
- int x=i%4;
- int y=i/4;
- Mat displayROI = display(Rect(x*width,y*heigh,width,heigh));
- resize(imgColor[i],displayROI,displayROI.size());
- }
- imshow("colorImg",display);
- waitKey();
- imwrite("D:/img/幻彩颜色02.jpg",display);
- }
原图:
颜色变幻: