-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_desktop.cpp
81 lines (63 loc) · 2.1 KB
/
main_desktop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//header files
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/opencv.hpp"
#include<iostream>
//namespaces
using namespace cv;
using namespace std;
int main()
{
//read the image data in the file "me.jpg" and store it in 'img'
Mat img = imread("me.jpg", CV_LOAD_IMAGE_UNCHANGED);
//check whether the image is loaded or not
if(img.empty())
{
cout<<"Error:Image cannot be loaded..!!"<<endl;
//wait for a key press
system("pause");
// return -1;
}
//create windows to display the image
namedWindow("OriginalWindow", CV_WINDOW_AUTOSIZE);
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
namedWindow("MyWindow2", CV_WINDOW_AUTOSIZE);
//display the image which is stored in the 'img' in the "MyWindow" window
imshow("OriginalWindow", img);
Mat gray;
Mat edges;
Mat mask;
cvtColor(img, gray, CV_BGR2GRAY);
const int MEDIAN_BLUR_FILTER_SIZE = 7;
medianBlur(gray, gray, MEDIAN_BLUR_FILTER_SIZE);
const int LAPLACIAN_FILTER_SIZE = 5;
Laplacian(gray, edges, CV_8U, LAPLACIAN_FILTER_SIZE);
const int EDGES_THRESHOLD = 80;
threshold(edges, mask, EDGES_THRESHOLD, 255, THRESH_BINARY_INV);
imshow("MyWindow", mask);
//For painting
Size size = img.size();
Size smallSize;
smallSize.width = size.width/2;
smallSize.height = size.height/2;
Mat smallImg = Mat (smallSize, CV_8UC3);
resize(img, smallImg, smallSize, 0, 0, INTER_LINEAR);
Mat tmp = Mat (smallSize, CV_8UC3);
// Repetitions for strong cartoon effect.
int repetitions = 7;
for (int i=0; i<repetitions; i++) {
//Filter size. Has a large effect on speed.
int ksize = 9;
double sigmaColor = 9;
double sigmaSpace = 7;
bilateralFilter (smallImg, tmp, ksize, sigmaColor, sigmaSpace);
bilateralFilter (tmp, smallImg, ksize, sigmaColor, sigmaSpace);
}
Mat bigImg;
Mat mask1;
resize(smallImg, bigImg, size, 0, 0, INTER_LINEAR);
bigImg.copyTo(mask1);
imshow("MyWindow2", mask1);
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
return 0;
}