colormap.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * OpenCV Colormap Example
  3. *
  4. * Copyright 2015 by Satya Mallick <spmallick@learnopencv.com>
  5. *
  6. */
  7. #include "opencv2/opencv.hpp"
  8. using namespace cv;
  9. using namespace std;
  10. string colormap_name(int id)
  11. {
  12. switch(id){
  13. case COLORMAP_AUTUMN :
  14. return "COLORMAP_AUTUMN";
  15. case COLORMAP_BONE :
  16. return "COLORMAP_BONE";
  17. case COLORMAP_JET :
  18. return "COLORMAP_JET";
  19. case COLORMAP_WINTER :
  20. return "COLORMAP_WINTER";
  21. case COLORMAP_RAINBOW :
  22. return "COLORMAP_RAINBOW";
  23. case COLORMAP_OCEAN :
  24. return "COLORMAP_OCEAN";
  25. case COLORMAP_SUMMER:
  26. return "COLORMAP_SUMMER";
  27. case COLORMAP_SPRING :
  28. return "COLORMAP_SPRING";
  29. case COLORMAP_COOL :
  30. return "COLORMAP_COOL";
  31. case COLORMAP_HSV :
  32. return "COLORMAP_HSV";
  33. case COLORMAP_PINK :
  34. return "COLORMAP_PINK";
  35. case COLORMAP_HOT :
  36. return "COLORMAP_HOT";
  37. }
  38. return "NONE";
  39. }
  40. int main( int argc, char** argv )
  41. {
  42. // Read 8-bit grayscale image
  43. Mat im = imread("pluto.jpg", IMREAD_GRAYSCALE);
  44. Mat im_out = Mat::zeros(600, 800, CV_8UC3);
  45. for (int i=0; i < 4; i++){
  46. for(int j=0; j < 3; j++){
  47. int k = i + j * 4;
  48. Mat im_color = im_out(Rect(i * 200, j * 200, 200, 200));
  49. applyColorMap(im, im_color, k);
  50. putText(im_color, colormap_name(k), Point(30, 180), cv::FONT_HERSHEY_DUPLEX, 0.5, Scalar::all(255), 1, cv::LINE_AA);
  51. }
  52. }
  53. imshow("Pseudo Colored", im_out);
  54. waitKey(0);
  55. }