-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMainWindow.cs
More file actions
352 lines (327 loc) · 11.6 KB
/
MainWindow.cs
File metadata and controls
352 lines (327 loc) · 11.6 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace team_Project
{
public partial class MainWindow : Form
{
Bitmap O_left_img;
Bitmap O_right_img;
public static Rectangle rect;
public static Rectangle rect2;
private Minimapdlg minimapdlg = null;
private Minimapdlg minimapdlg2 = null;
bool isModalOpened = false;
bool isModalOpened2 = false;
public MainWindow()
{
InitializeComponent();
saveFileDialog1.DefaultExt = "bmp";
saveFileDialog1.Filter = "BMP files(*.bmp)|*.bmp";
}
public static Image resizeImage(Image image)
{
if (image != null)
{
rect2 = rect;
Bitmap cutBitmap = new Bitmap(image);
cutBitmap = cutBitmap.Clone(new Rectangle(rect2.X, rect2.Y, rect2.Width, rect2.Height), System.Drawing.Imaging.PixelFormat.Undefined);
return cutBitmap;
}
else
{
return image;
}
}
private void btn_load1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
LeftBox.Load(openFileDialog1.FileName);
O_left_img = new Bitmap(LeftBox.Image);
rect.X = 0;
rect.Y = 0;
rect.Width = O_left_img.Width;
rect.Height = O_left_img.Height;
rect2.X = 0;
rect2.Y = 0;
rect2.Width = O_left_img.Width;
rect2.Height = O_left_img.Height;
}
}
private void btn_load2_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
RightBox.Load(openFileDialog1.FileName);
O_right_img = new Bitmap(RightBox.Image);
rect2.X = 0;
rect2.Y = 0;
rect2.Width = O_right_img.Width;
rect2.Height = O_right_img.Height;
}
}
private void Save_dlg(Bitmap buf)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string loc = saveFileDialog1.FileName.ToString();
buf.Save(loc);
}
}
private void btn_save1_Click(object sender, EventArgs e)
{
if (LeftBox.Image != null)
{
switch (MessageBox.Show("선택하신 부분을 저장하시겠습니까? \n (예 : 부분 저장, 아니요 : 전체 저장)",
"저장", MessageBoxButtons.YesNoCancel))
{
case DialogResult.Yes:
Bitmap buf = new Bitmap(LeftBox.Image);
Save_dlg(buf);
break;
case DialogResult.No:
Save_dlg(new Bitmap(O_left_img));
break;
case DialogResult.Cancel:
break;
}
}
}
private void btn_save2_Click(object sender, EventArgs e)
{
if (RightBox.Image != null)
{
switch (MessageBox.Show("선택하신 부분을 저장하시겠습니까? \n (예 : 부분 저장, 아니요 : 전체 저장)",
"저장", MessageBoxButtons.YesNoCancel))
{
case DialogResult.Yes:
Bitmap buf = new Bitmap(RightBox.Image);
Save_dlg(buf);
break;
case DialogResult.No:
Save_dlg(new Bitmap(O_right_img));
break;
case DialogResult.Cancel:
break;
}
}
}
private void btn_exp_Click(object sender, EventArgs e)
{
try
{
O_right_img = new Bitmap(O_left_img);
O_right_img.expansion_oper(O_left_img, progressBar1);
RightBox.Image = resizeImage(O_right_img);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void btn_ero_Click(object sender, EventArgs e)
{
try
{
O_right_img = new Bitmap(O_left_img);
O_right_img.erosion_oper(O_left_img, progressBar1);
RightBox.Image = resizeImage(O_right_img);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void btn_hist_Click(object sender, EventArgs e)
{
try
{
O_right_img = new Bitmap(O_left_img);
O_right_img.hist_equal_oper(progressBar1);
RightBox.Image = resizeImage(O_right_img);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void btn_otsu_Click(object sender, EventArgs e)
{
try
{
O_right_img = new Bitmap(O_left_img);
O_right_img.otsu_oper(progressBar1);
RightBox.Image = resizeImage(O_right_img);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void btn_gau_Click(object sender, EventArgs e)
{
try
{
O_right_img = new Bitmap(O_left_img);
O_right_img.gaussian_oper(O_left_img, progressBar1);
RightBox.Image = resizeImage(O_right_img);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void btn_lap_Click(object sender, EventArgs e)
{
try
{
O_right_img = new Bitmap(O_left_img);
O_right_img.laplacian_oper(O_left_img, progressBar1);
RightBox.Image = resizeImage(O_right_img);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void btn_match_Click(object sender, EventArgs e)
{
if (LeftBox.Image != null && RightBox.Image != null)
{
Bitmap left_bmp = new Bitmap(LeftBox.Image);
Bitmap right_bmp = new Bitmap(RightBox.Image);
Point match_p = left_bmp.match_img(right_bmp, progressBar1);
MessageBox.Show($"X:{match_p.X}, Y:{match_p.Y}", "매칭 좌표");
Bitmap Square = new Bitmap((Bitmap)LeftBox.Image.Clone());
for (int x = match_p.X; x <= match_p.X + right_bmp.Width; ++x)
{
for (int y = match_p.Y; y <= match_p.Y + right_bmp.Height; ++y)
{
if (x < left_bmp.Width && y < left_bmp.Height)
{
if (x == match_p.X || x == match_p.X + right_bmp.Width || y == match_p.Y || y == match_p.Y + right_bmp.Height)
{
Square.SetPixel(x, y, Color.FromArgb(0, 0, 255));
}
}
}
}
LeftBox.Image = Square;
}
}
private void LeftBox_Click(object sender, EventArgs e)
{
if (isModalOpened || LeftBox.Image == null)
{
return;
}
if (minimapdlg == null)
{
isModalOpened = true;
minimapdlg = new Minimapdlg(LeftBox, O_left_img);
minimapdlg.FormClosed += (o, exx) => isModalOpened = false;
minimapdlg.Owner = this;
minimapdlg?.Show(); //null이 아니면 show!
}
else
minimapdlg.Focus();
if (minimapdlg.open == false)
{
minimapdlg = null;
LeftBox_Click(sender, e);
}
}
private void RightBox_Click(object sender, EventArgs e)
{
if (isModalOpened2 || RightBox.Image == null)
{
return;
}
if (minimapdlg2 == null)
{
isModalOpened2 = true;
minimapdlg2 = new Minimapdlg(RightBox, O_right_img, false);
minimapdlg2.FormClosed += (o, exx) => isModalOpened2 = false;
minimapdlg2.Owner = this;
minimapdlg2?.Show();
}
else
minimapdlg2.Focus();
if (minimapdlg2.open == false)
{
minimapdlg2 = null;
RightBox_Click(sender, e);
}
}
private void LeftBox_MouseMove(object sender, MouseEventArgs e)
{
scope_img(ref LeftBox, e, rect);
}
private void RightBox_MouseMove(object sender, MouseEventArgs e)
{
scope_img(ref RightBox, e, rect2);
}
private void scope_img(ref PictureBox pic_box, MouseEventArgs e, Rectangle rect)
{
if (pic_box.Image == null)
{
label1.Text = $" X : {e.X}";
label2.Text = $" Y : {e.Y}";
}
else
{
int realX = (int)(e.X * ((double)pic_box.Image.Width / (double)pic_box.Width));
int realY = (int)(e.Y * ((double)pic_box.Image.Height / (double)pic_box.Height));
//label1.Text = $"X : " + realX;
//label2.Text = $"Y : " + realY;
label1.Text = $"X : {realX + rect.X}";
label2.Text = $"Y : {realY + rect.Y}";
Bitmap bitmap = new Bitmap(31, 31);
for (int i = -15; i < 15; ++i)
{
for (int j = -15; j < 15; ++j)
{
if (((realX + i) < 0 || (realY + j) < 0 || (realY + j) >= pic_box.Image.Height || (realX + i) >= pic_box.Image.Width))
{
continue;
}
else
{
bitmap.SetPixel(15 + i, 15 + j, ((Bitmap)(pic_box.Image)).GetPixel(realX + i, realY + j));
}
}
}
byte temp = ((Bitmap)(pic_box.Image)).GetPixel(realX, realY).R;
lbl_gray.Text = $"Gray : {temp}";
scope_box.Image = bitmap;
}
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
try
{
VisitLink();
}
catch (Exception ex)
{
MessageBox.Show("Unable to open link that was clicked.");
}
}
private void VisitLink()
{
// Change the color of the link text by setting LinkVisited
// to true.
linkLabel1.LinkVisited = true;
//Call the Process.Start method to open the default browser
//with a URL:
System.Diagnostics.Process.Start("https://github.com/Hyeoun/team_Project");
}
}
}