-
Notifications
You must be signed in to change notification settings - Fork 14
/
main.cpp
204 lines (169 loc) · 5.34 KB
/
main.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
Copyright (C) 2015 Yasutomo Kawanishi
Copyright (C) 2013 Christoffer Holmstedt
Copyright (C) 2010 Salik Syed
Copyright (C) 2006 Pedro Felzenszwalb
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cassert>
#include "egbis.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
using namespace std;
/****
* END OF: OpenCV C++ Wrapper using the Mat class
***/
Mat egbisImage;
Mat img;
char* imageName;
int num_ccs;
/****
* GUI related variables and functions (trackBars/Sliders).
* TODO: Move this to separate file.
***/
int sigma_switch_value = 1;
int sigma_switch_high = 30;
int k_switch_value = 500;
int k_switch_high = 5000;
int c_switch_value = 200;
int c_switch_high = 5000;
int run_switch_value = 0;
int run_switch_high = 1;
int save_switch_value = 0;
int save_switch_high = 1;
float sigma_value;
void switch_callback_sigma( int position, void* ){
sigma_switch_value = position;
sigma_value = static_cast<float>(sigma_switch_value)/10;
/*
switch (sigma_switch_value) {
case 0:
sigma_value = 0;
break;
case 1:
sigma_value = 0.1;
break;
case 2:
sigma_value = 0.2;
break;
case 3:
sigma_value = 0.3;
break;
case 4:
sigma_value = 0.4;
break;
case 5:
sigma_value = 0.5;
break;
case 6:
sigma_value = 0.6;
break;
case 7:
sigma_value = 0.7;
break;
case 8:
sigma_value = 0.8;
break;
case 9:
sigma_value = 0.9;
break;
case 10:
sigma_value = 1;
break;
}
*/
}
void switch_callback_k( int position, void* ){
k_switch_value = position;
}
void switch_callback_c( int position, void* ){
c_switch_value = position;
}
void switch_callback_save( int position, void* ){
if (position == 1)
{
// TODO: Add variables sigma, k and c to filename
// so multiple images can be saved.
imwrite( "../images/egbisImage.jpg", egbisImage);
c_switch_value = 0;
}
}
void switch_callback_run( int position, void* ){
if (position == 1)
{
// Calculate new EGBIS segmentation
// (Mat *input, float sigma, float k, int min_size, int *numccs) {
egbisImage = runEgbisOnMat(img, sigma_value, static_cast<float>(k_switch_value), c_switch_value, &num_ccs);
// Change image shown
imshow( "EGBIS", egbisImage);
run_switch_value = 0;
// TODO: Fix this, it doesn't work as intended.
// http://docs.opencv.org/modules/highgui/doc/user_interface.html#settrackbarpos
//setTrackbarPos("Run", "EGBIS", run_switch_value);
}
}
/****
* END OF: GUI related variables and functions (trackBars/Sliders).
***/
/****
* Main
***/
int main(int argc, char **argv) {
assert(argc > 1);
img = imread( argv[1], cv::IMREAD_COLOR );
if( !img.data )
{
cout << "Could not open or find the image." << std::endl;
return -1;
}
imageName = argv[1];
// Create the first EGBIS version with standard values.
// TODO: Set this input values to match the ones define in global scope
egbisImage = runEgbisOnMat(img, 0.5, 500, 200, &num_ccs);
// 4. Present image
namedWindow( imageName , cv::WINDOW_AUTOSIZE );
imshow( imageName , img );
// TODO: Change to C++ method
// http://docs.opencv.org/modules/highgui/doc/user_interface.html#createtrackbar
cv::createTrackbar("Sigma [x/10]", imageName, &sigma_switch_value, sigma_switch_high, switch_callback_sigma);
cv::createTrackbar("k",imageName, &k_switch_value, k_switch_high, switch_callback_k);
cv::createTrackbar("c",imageName, &c_switch_value, c_switch_high, switch_callback_c);
cv::createTrackbar("Run",imageName, &run_switch_value, run_switch_high, switch_callback_run);
cv::createTrackbar("Save EGBIS image",imageName, &save_switch_value, save_switch_high, switch_callback_save);
namedWindow( "EGBIS", cv::WINDOW_AUTOSIZE );
imshow( "EGBIS", egbisImage);
/*
float sigma = atof(argv[1]);
float k = atof(argv[2]);
int min_size = atoi(argv[3]);
printf("loading input image.\n");
image<rgb> *input = loadPPM(argv[4]);
printf("processing\n");
int num_ccs;
image<rgb> *seg = segment_image(input, sigma, k, min_size, &num_ccs);
savePPM(seg, argv[5]);
Mat gray_image;
cvtColor( image, gray_image, cv::COLOR_BGR2GRAY );
imwrite( "../../images/tempImage.jpg", gray_image );
*/
waitKey(0);
return 0;
}
/****
* END OF: Main
***/