Home | History | Annotate | Download | only in cpp
      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 
     29 int main(int argc, char* argv[])
     30 {
     31     if(argc < 2)
     32     {
     33         cout << "usage: " << argv[0] << " <Input image> "  << endl;
     34         exit(0);
     35     }
     36 
     37     int num,type;
     38 
     39     Mat I = imread(argv[1]);
     40 
     41     if(I.empty())
     42     {
     43         cout <<  "Image not found" << endl;
     44         exit(0);
     45     }
     46 
     47     cout << endl;
     48     cout << " Edge Preserve Filter" << endl;
     49     cout << "----------------------" << endl;
     50 
     51     cout << "Options: " << endl;
     52     cout << endl;
     53 
     54     cout << "1) Edge Preserve Smoothing" << endl;
     55     cout << "   -> Using Normalized convolution Filter" << endl;
     56     cout << "   -> Using Recursive Filter" << endl;
     57     cout << "2) Detail Enhancement" << endl;
     58     cout << "3) Pencil sketch/Color Pencil Drawing" << endl;
     59     cout << "4) Stylization" << endl;
     60     cout << endl;
     61 
     62     cout << "Press number 1-4 to choose from above techniques: ";
     63 
     64     cin >> num;
     65 
     66     Mat img;
     67 
     68     if(num == 1)
     69     {
     70         cout << endl;
     71         cout << "Press 1 for Normalized Convolution Filter and 2 for Recursive Filter: ";
     72 
     73         cin >> type;
     74 
     75         edgePreservingFilter(I,img,type);
     76         imshow("Edge Preserve Smoothing",img);
     77 
     78     }
     79     else if(num == 2)
     80     {
     81         detailEnhance(I,img);
     82         imshow("Detail Enhanced",img);
     83     }
     84     else if(num == 3)
     85     {
     86         Mat img1;
     87         pencilSketch(I,img1, img, 10 , 0.1f, 0.03f);
     88         imshow("Pencil Sketch",img1);
     89         imshow("Color Pencil Sketch",img);
     90     }
     91     else if(num == 4)
     92     {
     93         stylization(I,img);
     94         imshow("Stylization",img);
     95     }
     96     waitKey(0);
     97 }
     98