npr_demo.cpp 2.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
* npr_demo.cpp
*
* Author:
* Siddharth Kherada <siddharthkherada27[at]gmail[dot]com>
*
* This tutorial demonstrates how to use OpenCV Non-Photorealistic Rendering Module.
* 1) Edge Preserve Smoothing
*    -> Using Normalized convolution Filter
*    -> Using Recursive Filter
* 2) Detail Enhancement
* 3) Pencil sketch/Color Pencil Drawing
* 4) Stylization
*
*/

#include <signal.h>
#include "opencv2/photo.hpp"
#include "opencv2/imgproc.hpp"
20
#include "opencv2/imgcodecs.hpp"
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include <iostream>
#include <stdlib.h>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])
{
    if(argc < 2)
    {
        cout << "usage: " << argv[0] << " <Input image> "  << endl;
        exit(0);
    }

37 38 39 40
    int num,type;

    Mat I = imread(argv[1]);

41
    if(I.empty())
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
    {
        cout <<  "Image not found" << endl;
        exit(0);
    }

    cout << endl;
    cout << " Edge Preserve Filter" << endl;
    cout << "----------------------" << endl;

    cout << "Options: " << endl;
    cout << endl;

    cout << "1) Edge Preserve Smoothing" << endl;
    cout << "   -> Using Normalized convolution Filter" << endl;
    cout << "   -> Using Recursive Filter" << endl;
    cout << "2) Detail Enhancement" << endl;
    cout << "3) Pencil sketch/Color Pencil Drawing" << endl;
    cout << "4) Stylization" << endl;
    cout << endl;

62
    cout << "Press number 1-4 to choose from above techniques: ";
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

    cin >> num;

    Mat img;

    if(num == 1)
    {
        cout << endl;
        cout << "Press 1 for Normalized Convolution Filter and 2 for Recursive Filter: ";

        cin >> type;

        edgePreservingFilter(I,img,type);
        imshow("Edge Preserve Smoothing",img);

    }
    else if(num == 2)
    {
        detailEnhance(I,img);
        imshow("Detail Enhanced",img);
    }
    else if(num == 3)
    {
        Mat img1;
Ilya Lavrenov's avatar
Ilya Lavrenov committed
87
        pencilSketch(I,img1, img, 10 , 0.1f, 0.03f);
88 89 90 91 92 93 94 95 96 97
        imshow("Pencil Sketch",img1);
        imshow("Color Pencil Sketch",img);
    }
    else if(num == 4)
    {
        stylization(I,img);
        imshow("Stylization",img);
    }
    waitKey(0);
}