npr_demo.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * npr_demo.cpp
  3. *
  4. * Author:
  5. * Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
  6. *
  7. * This tutorial demonstrates how to use OpenCV Non-Photorealistic Rendering Module.
  8. * 1) Edge Preserve Smoothing
  9. * -> Using Normalized convolution Filter
  10. * -> Using Recursive Filter
  11. * 2) Detail Enhancement
  12. * 3) Pencil sketch/Color Pencil Drawing
  13. * 4) Stylization
  14. *
  15. */
  16. #include <signal.h>
  17. #include "opencv2/photo.hpp"
  18. #include "opencv2/imgproc.hpp"
  19. #include "opencv2/imgcodecs.hpp"
  20. #include "opencv2/highgui.hpp"
  21. #include "opencv2/core.hpp"
  22. #include <iostream>
  23. #include <stdlib.h>
  24. using namespace std;
  25. using namespace cv;
  26. int main(int argc, char* argv[])
  27. {
  28. cv::CommandLineParser parser(argc, argv, "{help h||show help message}{@image|lena.jpg|input image}");
  29. if (parser.has("help"))
  30. {
  31. parser.printMessage();
  32. return 0;
  33. }
  34. string filename = samples::findFile(parser.get<string>("@image"));
  35. Mat I = imread(filename);
  36. int num,type;
  37. if(I.empty())
  38. {
  39. cout << "Image not found" << endl;
  40. return 1;
  41. }
  42. cout << endl;
  43. cout << " Edge Preserve Filter" << endl;
  44. cout << "----------------------" << endl;
  45. cout << "Options: " << endl;
  46. cout << endl;
  47. cout << "1) Edge Preserve Smoothing" << endl;
  48. cout << " -> Using Normalized convolution Filter" << endl;
  49. cout << " -> Using Recursive Filter" << endl;
  50. cout << "2) Detail Enhancement" << endl;
  51. cout << "3) Pencil sketch/Color Pencil Drawing" << endl;
  52. cout << "4) Stylization" << endl;
  53. cout << endl;
  54. cout << "Press number 1-4 to choose from above techniques: ";
  55. cin >> num;
  56. Mat img;
  57. if(num == 1)
  58. {
  59. cout << endl;
  60. cout << "Press 1 for Normalized Convolution Filter and 2 for Recursive Filter: ";
  61. cin >> type;
  62. edgePreservingFilter(I,img,type);
  63. imshow("Edge Preserve Smoothing",img);
  64. }
  65. else if(num == 2)
  66. {
  67. detailEnhance(I,img);
  68. imshow("Detail Enhanced",img);
  69. }
  70. else if(num == 3)
  71. {
  72. Mat img1;
  73. pencilSketch(I,img1, img, 10 , 0.1f, 0.03f);
  74. imshow("Pencil Sketch",img1);
  75. imshow("Color Pencil Sketch",img);
  76. }
  77. else if(num == 4)
  78. {
  79. stylization(I,img);
  80. imshow("Stylization",img);
  81. }
  82. waitKey(0);
  83. }