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 
17 #include <signal.h>
18 #include "opencv2/photo.hpp"
19 #include "opencv2/imgproc.hpp"
20 #include "opencv2/imgcodecs.hpp"
21 #include "opencv2/highgui.hpp"
22 #include "opencv2/core.hpp"
23 #include <iostream>
24 #include <stdlib.h>
25 
26 using namespace std;
27 using namespace cv;
28 
main(int argc,char * argv[])29 int main(int argc, char* argv[])
30 {
31     cv::CommandLineParser parser(argc, argv, "{help h||show help message}{@image|lena.jpg|input image}");
32     if (parser.has("help"))
33     {
34         parser.printMessage();
35         return 0;
36     }
37     string filename = samples::findFile(parser.get<string>("@image"));
38 
39     Mat I = imread(filename);
40 
41     int num,type;
42 
43     if(I.empty())
44     {
45         cout <<  "Image not found" << endl;
46         return 1;
47     }
48 
49     cout << endl;
50     cout << " Edge Preserve Filter" << endl;
51     cout << "----------------------" << endl;
52 
53     cout << "Options: " << endl;
54     cout << endl;
55 
56     cout << "1) Edge Preserve Smoothing" << endl;
57     cout << "   -> Using Normalized convolution Filter" << endl;
58     cout << "   -> Using Recursive Filter" << endl;
59     cout << "2) Detail Enhancement" << endl;
60     cout << "3) Pencil sketch/Color Pencil Drawing" << endl;
61     cout << "4) Stylization" << endl;
62     cout << endl;
63 
64     cout << "Press number 1-4 to choose from above techniques: ";
65 
66     cin >> num;
67 
68     Mat img;
69 
70     if(num == 1)
71     {
72         cout << endl;
73         cout << "Press 1 for Normalized Convolution Filter and 2 for Recursive Filter: ";
74 
75         cin >> type;
76 
77         edgePreservingFilter(I,img,type);
78         imshow("Edge Preserve Smoothing",img);
79 
80     }
81     else if(num == 2)
82     {
83         detailEnhance(I,img);
84         imshow("Detail Enhanced",img);
85     }
86     else if(num == 3)
87     {
88         Mat img1;
89         pencilSketch(I,img1, img, 10 , 0.1f, 0.03f);
90         imshow("Pencil Sketch",img1);
91         imshow("Color Pencil Sketch",img);
92     }
93     else if(num == 4)
94     {
95         stylization(I,img);
96         imshow("Stylization",img);
97     }
98     waitKey(0);
99 }
100