forked from arcreane/gimpsep-photowish
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdilation.cpp
74 lines (53 loc) · 1.77 KB
/
dilation.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
#include <iostream>
#include "Menu.h"
#include "Header.h"
#include <opencv2/opencv.hpp>
#include "opencv2/core/utils/logger.hpp"
using namespace std;
using namespace cv;
Mat dilatedImage, imageSrc;
int dilation_type = 0;
int dilation_elem = 0;
int dilation_size = 0;
int const max_elem = 2;
int const max_kernel_size = 21;
void dilate(int, void*) {
if (dilation_elem == 0) { dilation_type = MORPH_RECT; }
else if (dilation_elem == 1) { dilation_type = MORPH_CROSS; }
else if (dilation_elem == 2) { dilation_type = MORPH_ELLIPSE; }
Mat element = getStructuringElement(dilation_type,
Size(2 * dilation_size + 1, 2 * dilation_size + 1),
Point(dilation_size, dilation_size));
dilate(imageSrc, dilatedImage, element);
imshow("GimpLike Application", dilatedImage);
}
int dilation(Mat image) {
//test image path: C:/Users/arthu/Desktop/Ecole/AppMultimedia/C++/crocodile.png
string white = getColor("white");
string blue = getColor("blue");
string red = getColor("red");
imageSrc = image;
cout << white << "\nWhat is the dilation element ? (between 0 and 2)\n";
cout << white << "[ 1: Rectangle | 2: Cross | 3: Ellipse ]\n";
cout << white << "Dilation element : ";
cin >> dilation_elem;
cout << white << "\nWhat is the dilation size ? (between 0 and 21)\n";
cout << white << "Dilation size : ";
cin >> dilation_size;
namedWindow("GimpLike Application", WINDOW_AUTOSIZE);
createTrackbar("Element:\n 0: Rect \n 1: Cross \n 2: Ellipse", "GimpLike Application",
&dilation_elem, max_elem,
dilate);
createTrackbar("Kernel size:\n 2n +1", "GimpLike Application",
&dilation_size, max_kernel_size,
dilate);
dilate(0, 0);
waitKey(0);
saveImage(dilatedImage);
system("pause");
destroyAllWindows();
system("CLS");
dilatedImage.release();
imageSrc.release();
return 0;
}