samples/cpp/tutorial_code/photo/non_photorealistic_rendering/npr_demo.cpp#
An example using non-photorealistic line drawing functions
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 "opencv2/photo.hpp"
18#include "opencv2/imgproc.hpp"
19#include "opencv2/highgui.hpp"
20#include <iostream>
21
22using namespace std;
23using namespace cv;
24
25int main(int argc, char* argv[])
26{
27 int num,type;
28 CommandLineParser parser(argc, argv, "{@input | lena.jpg | input image}");
29 Mat src = imread( samples::findFile( parser.get<String>("@input") ), IMREAD_COLOR);
30
31 if(src.empty())
32 {
33 cout << "Could not open or find the image!\n" << endl;
34 cout << "Usage: " << argv[0] << " <Input image>" << endl;
35 exit(0);
36 }
37
38 cout << endl;
39 cout << " Edge Preserve Filter" << endl;
40 cout << "----------------------" << endl;
41
42 cout << "Options: " << endl;
43 cout << endl;
44
45 cout << "1) Edge Preserve Smoothing" << endl;
46 cout << " -> Using Normalized convolution Filter" << endl;
47 cout << " -> Using Recursive Filter" << endl;
48 cout << "2) Detail Enhancement" << endl;
49 cout << "3) Pencil sketch/Color Pencil Drawing" << endl;
50 cout << "4) Stylization" << endl;
51 cout << endl;
52
53 cout << "Press number 1-4 to choose from above techniques: ";
54
55 cin >> num;
56
57 Mat img;
58
59 if(num == 1)
60 {
61 cout << endl;
62 cout << "Press 1 for Normalized Convolution Filter and 2 for Recursive Filter: ";
63
64 cin >> type;
65
66 edgePreservingFilter(src,img,type);
67 imshow("Edge Preserve Smoothing",img);
68
69 }
70 else if(num == 2)
71 {
72 detailEnhance(src,img);
73 imshow("Detail Enhanced",img);
74 }
75 else if(num == 3)
76 {
77 Mat img1;
78 pencilSketch(src,img1, img, 10 , 0.1f, 0.03f);
79 imshow("Pencil Sketch",img1);
80 imshow("Color Pencil Sketch",img);
81 }
82 else if(num == 4)
83 {
84 stylization(src,img);
85 imshow("Stylization",img);
86 }
87 waitKey(0);
88}