学习OpenCV:滤镜系列(3)——颜色变幻

来源:互联网 发布:天津资源网络平台 编辑:程序博客网 时间:2024/04/29 12:46

【原文: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
    }


[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #include <math.h>  
  2. #include <opencv2/contrib/contrib.hpp>  
  3. #include <opencv2/core/core.hpp>  
  4. #include <opencv2/highgui/highgui.hpp>  
  5.   
  6. using namespace cv;  
  7. using namespace std;  
  8.   
  9. int main()  
  10. {  
  11.     Mat src = imread("D:/img/face03.jpeg",1);  
  12.     int width = src.cols;  
  13.     int heigh = src.rows;  
  14.     Mat gray;  
  15.     Mat imgColor[12];  
  16.     Mat display(heigh*3,width*4,CV_8UC3);  
  17.   
  18.     cvtColor(src,gray,CV_BGR2GRAY);  
  19.     for(int i=0; i<12; i++)  
  20.     {  
  21.         applyColorMap(gray,imgColor[i],i);  
  22.         int x=i%4;  
  23.         int y=i/4;  
  24.         Mat displayROI = display(Rect(x*width,y*heigh,width,heigh));  
  25.         resize(imgColor[i],displayROI,displayROI.size());  
  26.     }  
  27.     imshow("colorImg",display);   
  28.     waitKey();  
  29.     imwrite("D:/img/幻彩颜色02.jpg",display);  
  30. }  

原图:


颜色变幻


0 0
原创粉丝点击