markus / ImageComparer / ComparerTestWPF / MainWindow.xaml.cs @ fdab8f9c
이력 | 보기 | 이력해설 | 다운로드 (7.6 KB)
1 |
using Microsoft.Win32; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Text; |
6 |
using System.Threading.Tasks; |
7 |
using System.Windows; |
8 |
using System.Windows.Controls; |
9 |
using System.Windows.Data; |
10 |
using System.Windows.Documents; |
11 |
using System.Windows.Input; |
12 |
using System.Windows.Media; |
13 |
using System.Windows.Media.Imaging; |
14 |
using System.Windows.Navigation; |
15 |
using System.Windows.Shapes; |
16 | |
17 |
namespace ComparerTestWPF |
18 |
{ |
19 |
/// <summary> |
20 |
/// MainWindow.xaml에 대한 상호 작용 논리 |
21 |
/// </summary> |
22 |
public partial class MainWindow : Window |
23 |
{ |
24 |
public MainWindow() |
25 |
{ |
26 |
InitializeComponent(); |
27 |
} |
28 | |
29 | |
30 |
private void btFindOriginalFile_click(object sender, RoutedEventArgs e) |
31 |
{ |
32 |
TxtOriginalImage.Text = FileOpen(); |
33 |
} |
34 | |
35 |
private void btFindTargetFile_click(object sender, RoutedEventArgs e) |
36 |
{ |
37 |
TxtTargetImage.Text = FileOpen(); |
38 |
} |
39 | |
40 |
private string FileOpen() |
41 |
{ |
42 |
string result = null; |
43 | |
44 |
OpenFileDialog openFileDialog = new OpenFileDialog(); |
45 | |
46 |
openFileDialog.Filter = "Image Files|*.png;*.jpg;*.bmp"; |
47 | |
48 |
if (openFileDialog.ShowDialog() == true) |
49 |
result = openFileDialog.FileName; |
50 |
else |
51 |
result = null; |
52 | |
53 |
return result; |
54 |
} |
55 | |
56 | |
57 |
private void btNoneTask_Click(object sender, RoutedEventArgs e) |
58 |
{ |
59 |
BitmapSource bitmapSource = null; |
60 |
BitmapSource TargetSource = null; |
61 | |
62 |
using (Markus.Image.ImageCompare imageCompare = new Markus.Image.ImageCompare()) |
63 |
{ |
64 |
var original = new System.Drawing.Bitmap(TxtOriginalImage.Text,true); |
65 |
var target = new System.Drawing.Bitmap(TxtTargetImage.Text, true); |
66 | |
67 |
var result = imageCompare.CompareDrawRects(original, target, new System.Drawing.Size(1, 1)); |
68 |
|
69 |
bitmapSource = imageCompare.CreateWriteableBitmapFromBitmap(new[]{ result },result.Size); |
70 | |
71 |
var original2= new System.Drawing.Bitmap(TxtOriginalImage.Text, true); |
72 |
var target2 = new System.Drawing.Bitmap(TxtTargetImage.Text, true); |
73 | |
74 | |
75 |
var result2 = imageCompare.CompareDrawRects(target2, original2, new System.Drawing.Size(1, 1)); |
76 |
TargetSource = imageCompare.CreateBitmapSourceFromBitmap(result2); |
77 |
|
78 |
original.Dispose(); |
79 |
target.Dispose(); |
80 |
} |
81 | |
82 |
if (bitmapSource != null && TargetSource != null) |
83 |
{ |
84 |
ImageView imageView = new ImageView(bitmapSource); |
85 | |
86 |
imageView.Show(); |
87 | |
88 | |
89 |
ImageView imageView2 = new ImageView(TargetSource); |
90 | |
91 |
imageView2.Show(); |
92 |
} |
93 |
else |
94 |
{ |
95 |
MessageBox.Show("bitmapSource is null"); |
96 |
} |
97 | |
98 |
} |
99 | |
100 |
private async void btTask_Click(object sender, RoutedEventArgs e) |
101 |
{ |
102 |
BitmapSource bitmapSource = null; |
103 |
BitmapSource TargetSource = null; |
104 | |
105 |
using (Markus.Image.ImageCompare imageComparer = new Markus.Image.ImageCompare()) |
106 |
{ |
107 | |
108 |
var original = new System.Drawing.Bitmap(TxtOriginalImage.Text); |
109 |
var target = new System.Drawing.Bitmap(TxtTargetImage.Text); |
110 | |
111 |
var result = await imageComparer.CompareReturnRectsAsync(original, target, new System.Drawing.Size(20, 20)); |
112 |
// bitmapSource = imageComparer.CreateWriteableBitmapFromBitmap(result); |
113 | |
114 |
lstView.ItemsSource = result; |
115 | |
116 |
var original2 = new System.Drawing.Bitmap(TxtOriginalImage.Text); |
117 |
var target2 = new System.Drawing.Bitmap(TxtTargetImage.Text); |
118 | |
119 | |
120 |
var result2 = await imageComparer.CompareReturnRectsAsync(target2, original2, new System.Drawing.Size(20, 20)); |
121 | |
122 |
lstView2.ItemsSource = result2; |
123 |
//TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2); |
124 | |
125 |
original.Dispose(); |
126 |
target.Dispose(); |
127 |
} |
128 |
|
129 | |
130 |
//ImageView imageView = new ImageView(bitmapSource); |
131 | |
132 |
//imageView.Show(); |
133 | |
134 |
//ImageView imageView2 = new ImageView(TargetSource); |
135 | |
136 |
//imageView2.Show(); |
137 |
} |
138 | |
139 |
private async void btTaskUri_Click(object sender, RoutedEventArgs e) |
140 |
{ |
141 |
BitmapSource bitmapSource = null; |
142 |
//http://10.10.130.12:8977/TileSource/12345_Tile/24771794/2477179440/1.png |
143 |
//http://10.10.130.12:8977/TileSource/12345_Tile/24771794/2477179438/1.png |
144 | |
145 | |
146 | |
147 | |
148 | |
149 |
using (Markus.Image.ImageCompare imageComparer = new Markus.Image.ImageCompare()) |
150 |
{ |
151 |
var rects = imageComparer.CompareReturnRects(TxtOriginalImage.Text, TxtTargetImage.Text, new System.Drawing.Size(20, 20)); |
152 | |
153 |
MessageBox.Show(rects.Count().ToString()); |
154 | |
155 |
var result = await imageComparer.CompareDrawRectsAsync(TxtOriginalImage.Text |
156 |
, TxtTargetImage.Text, new System.Drawing.Size(20, 20)); |
157 | |
158 |
bitmapSource = result; |
159 | |
160 |
//lstView.ItemsSource = result; |
161 | |
162 |
//var result2 = await imageComparer.CompareReturnRectsAsync("http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000101/1.png" |
163 |
// , "http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000102/1.png", new System.Drawing.Size(20, 20)); |
164 | |
165 |
//lstView2.ItemsSource = result2; |
166 |
//TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2); |
167 | |
168 |
} |
169 | |
170 |
ImageView imageView = new ImageView(bitmapSource); |
171 | |
172 |
imageView.Show(); |
173 |
} |
174 | |
175 |
private void btDrawContours_Click(object sender, RoutedEventArgs e) |
176 |
{ |
177 |
BitmapSource bitmapSource = null; |
178 |
BitmapSource TargetSource = null; |
179 |
BitmapSource bitmapSourceContours = null; |
180 |
BitmapSource TargetSourceContours = null; |
181 |
var rectColor = System.Drawing.Color.FromArgb(150, 244, 15, 126); |
182 | |
183 |
using (Markus.Image.ImageCompare imageCompare = new Markus.Image.ImageCompare()) |
184 |
{ |
185 |
var original = new System.Drawing.Bitmap(TxtOriginalImage.Text, true); |
186 |
var target = new System.Drawing.Bitmap(TxtTargetImage.Text, true); |
187 | |
188 |
var sourceContours = imageCompare.CompareReturnDrawContours(original, target, rectColor); |
189 | |
190 |
bitmapSource = imageCompare.CreateWriteableBitmapFromBitmap( |
191 |
new List<System.Drawing.Bitmap> { new System.Drawing.Bitmap(TxtOriginalImage.Text, true),sourceContours }, original.Size); |
192 | |
193 |
var original2 = new System.Drawing.Bitmap(TxtOriginalImage.Text, true); |
194 |
var target2 = new System.Drawing.Bitmap(TxtTargetImage.Text, true); |
195 | |
196 |
var targetContours = imageCompare.CompareReturnDrawContours(target2, original2, rectColor); |
197 | |
198 |
TargetSource = imageCompare.CreateWriteableBitmapFromBitmap( |
199 |
new List<System.Drawing.Bitmap> { new System.Drawing.Bitmap(TxtTargetImage.Text, true), targetContours }, target2.Size); |
200 | |
201 |
original.Dispose(); |
202 |
target.Dispose(); |
203 |
} |
204 | |
205 |
if (bitmapSource != null && TargetSource != null) |
206 |
{ |
207 |
ImageView imageView = new ImageView(bitmapSource); |
208 | |
209 |
imageView.Show(); |
210 | |
211 | |
212 |
ImageView imageView2 = new ImageView(TargetSource); |
213 | |
214 |
imageView2.Show(); |
215 |
} |
216 |
else |
217 |
{ |
218 |
MessageBox.Show("bitmapSource is null"); |
219 |
} |
220 |
} |
221 |
} |
222 |
} |