개정판 0c575433
issue #0000 compare 수정
Change-Id: I9b57c124b64674f7ae618978955093b399008da5
Markus.ImageComparer/ImageCompare.cs | ||
---|---|---|
16 | 16 |
/// <param name="Originalbitmap">원본 이미지</param> |
17 | 17 |
/// <param name="TargatBitmap">비교대상 이미지</param> |
18 | 18 |
/// <param name="ResultRectSize">반환되는 Rect의 사이즈</param> |
19 |
/// <returns></returns> |
|
20 |
public Bitmap CompareDrawRects(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize) |
|
19 |
/// <param name="ResultImageSize">반환되는 이미지 사이즈. 없으면 targat사이즈로 반환</param> |
|
20 |
/// <returns>TargetBitmap에 ResultRectSize의 크기로 변환된 부분이 표시되어 반환</returns> |
|
21 |
public Bitmap CompareDrawRects(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize, Size? ResultImageSize = null) |
|
21 | 22 |
{ |
22 |
var rects = CompareReturnRects(Originalbitmap, TargatBitmap, ResultRectSize); |
|
23 |
Size resultImageSize = TargatBitmap.Size; |
|
24 |
|
|
25 |
if (ResultImageSize.HasValue) |
|
26 |
{ |
|
27 |
resultImageSize = ResultImageSize.Value; |
|
28 |
} |
|
29 |
|
|
30 |
var rects = CompareReturnRects(Originalbitmap, TargatBitmap, ResultRectSize , resultImageSize); |
|
23 | 31 |
|
24 | 32 |
if (rects.Count != 0) |
25 | 33 |
{ |
26 |
Bitmap newBitmap = new Bitmap(Originalbitmap.Width, Originalbitmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
|
34 |
Bitmap newBitmap = new Bitmap(resultImageSize.Width, resultImageSize.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
|
|
27 | 35 |
|
28 | 36 |
using (Graphics g = Graphics.FromImage(newBitmap)) |
29 | 37 |
{ |
30 |
g.DrawImage(Originalbitmap, 0, 0);
|
|
38 |
g.DrawImage(TargatBitmap, 0, 0);
|
|
31 | 39 |
} |
32 | 40 |
|
33 | 41 |
using (Graphics g = Graphics.FromImage(newBitmap)) |
... | ... | |
46 | 54 |
return Originalbitmap; |
47 | 55 |
} |
48 | 56 |
|
49 |
public System.Windows.Media.Imaging.BitmapSource CompareDrawRects(System.Windows.Media.Imaging.BitmapSource Originalbitmap, System.Windows.Media.Imaging.BitmapSource TargatBitmap, Size ResultRectSize)
|
|
57 |
public System.Windows.Media.Imaging.BitmapSource CompareDrawRects(System.Windows.Media.Imaging.BitmapSource Originalbitmap, System.Windows.Media.Imaging.BitmapSource TargatBitmap, Size ResultRectSize, Size? ResultImageSize = null)
|
|
50 | 58 |
{ |
51 | 59 |
var _Originalbitmap = CreateBitmapFromSource(Originalbitmap); |
52 | 60 |
var _TargatBitmap = CreateBitmapFromSource(TargatBitmap); |
53 | 61 |
|
54 |
var rects = CompareReturnRects(_Originalbitmap, _TargatBitmap, ResultRectSize); |
|
62 |
var rects = CompareReturnRects(_Originalbitmap, _TargatBitmap, ResultRectSize,ResultImageSize);
|
|
55 | 63 |
|
56 | 64 |
if (rects.Count != 0) |
57 | 65 |
{ |
58 |
using (Graphics g = Graphics.FromImage(_Originalbitmap))
|
|
66 |
using (Graphics g = Graphics.FromImage(_TargatBitmap))
|
|
59 | 67 |
{ |
60 | 68 |
var rect = rects.Select(x => new System.Drawing.Rectangle((int)x.X, (int)x.Y, (int)x.Width, (int)x.Height)); |
61 | 69 |
|
... | ... | |
66 | 74 |
} |
67 | 75 |
} |
68 | 76 |
|
69 |
return CreateBitmapSourceFromBitmap(_Originalbitmap);
|
|
77 |
return CreateBitmapSourceFromBitmap(_TargatBitmap);
|
|
70 | 78 |
} |
71 | 79 |
|
72 |
public List<System.Windows.Rect> CompareReturnRects(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize) |
|
80 |
public List<System.Windows.Rect> CompareReturnRects(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize, Size? ResultImageSize = null)
|
|
73 | 81 |
{ |
74 | 82 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
75 | 83 |
|
... | ... | |
81 | 89 |
Originalbitmap = LoadPicture(OriginalbitmapUri); |
82 | 90 |
TargatBitmap = LoadPicture(TargatBitmapUri); |
83 | 91 |
|
84 |
result = CompareReturnRects(Originalbitmap, TargatBitmap, ResultRectSize); |
|
92 |
result = CompareReturnRects(Originalbitmap, TargatBitmap, ResultRectSize, ResultImageSize); |
|
93 |
} |
|
94 |
catch (Exception) |
|
95 |
{ |
|
96 |
throw; |
|
97 |
} |
|
98 |
finally |
|
99 |
{ |
|
100 |
Originalbitmap.Dispose(); |
|
101 |
TargatBitmap.Dispose(); |
|
102 |
} |
|
103 |
|
|
104 |
return result; |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
public List<System.Windows.Rect> CompareReturnRects(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize, bool IsResultTargetSize = false) |
|
109 |
{ |
|
110 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
|
111 |
|
|
112 |
Bitmap Originalbitmap = null; |
|
113 |
Bitmap TargatBitmap = null; |
|
114 |
|
|
115 |
try |
|
116 |
{ |
|
117 |
Originalbitmap = LoadPicture(OriginalbitmapUri); |
|
118 |
TargatBitmap = LoadPicture(TargatBitmapUri); |
|
119 |
|
|
120 |
Size resultImageSize = Originalbitmap.Size; |
|
121 |
|
|
122 |
if (IsResultTargetSize) |
|
123 |
{ |
|
124 |
resultImageSize = TargatBitmap.Size; |
|
125 |
} |
|
126 |
|
|
127 |
result = CompareReturnRects(Originalbitmap, TargatBitmap, ResultRectSize, resultImageSize); |
|
85 | 128 |
} |
86 | 129 |
catch (Exception) |
87 | 130 |
{ |
... | ... | |
103 | 146 |
/// <param name="TargatBitmap">비교대상 이미지</param> |
104 | 147 |
/// <param name="ResultRectSize">반환되는 Rect의 사이즈</param> |
105 | 148 |
/// <returns></returns> |
106 |
public List<System.Windows.Rect> CompareReturnRects(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize) |
|
149 |
public List<System.Windows.Rect> CompareReturnRects(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize , Size? ResultImageSize = null)
|
|
107 | 150 |
{ |
108 | 151 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
109 | 152 |
|
110 | 153 |
try |
111 | 154 |
{ |
112 |
List<System.Windows.Rect> rects = new List<System.Windows.Rect>();
|
|
155 |
Size resultImageSize = TargatBitmap.Size;
|
|
113 | 156 |
|
114 |
var data = MathchesImageData(Originalbitmap, TargatBitmap); |
|
157 |
if (ResultImageSize.HasValue) |
|
158 |
{ |
|
159 |
resultImageSize = ResultImageSize.Value; |
|
160 |
} |
|
161 |
|
|
162 |
List<System.Windows.Rect> rects = new List<System.Windows.Rect>(); |
|
115 | 163 |
|
164 |
var data = MathchesImageData(Originalbitmap, TargatBitmap, resultImageSize); |
|
165 |
|
|
116 | 166 |
result = GetMatchPixels(data, ResultRectSize); |
117 | 167 |
|
168 |
|
|
169 |
//var data2 = MathchesImageData(TargatBitmap,Originalbitmap, Originalbitmap.Size); |
|
170 |
|
|
171 |
//result.AddRange(GetMatchPixels(data2, ResultRectSize)); |
|
172 |
|
|
173 |
//result = result.Distinct().ToList(); |
|
118 | 174 |
//if (rects.Count() > 0) |
119 | 175 |
//{ |
120 | 176 |
// result = Merge(rects, ResultRectSize.Height); |
... | ... | |
142 | 198 |
/// <param name="TargatBitmap">비교대상 이미지</param> |
143 | 199 |
/// <param name="ResultRectSize">반환되는 Rect의 사이즈</param> |
144 | 200 |
/// <returns></returns> |
145 |
public async Task<Bitmap> CompareDrawRectsAsync(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize) |
|
201 |
public async Task<Bitmap> CompareDrawRectsAsync(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize, Size? ResultImageSize = null)
|
|
146 | 202 |
{ |
147 | 203 |
System.Drawing.Bitmap cloneOriginal = Originalbitmap; |
148 | 204 |
|
149 |
var rects = await CompareReturnRectsAsync(cloneOriginal, TargatBitmap, ResultRectSize); |
|
205 |
var rects = await CompareReturnRectsAsync(cloneOriginal, TargatBitmap, ResultRectSize, ResultImageSize);
|
|
150 | 206 |
|
151 | 207 |
if (rects.Count != 0) |
152 | 208 |
{ |
... | ... | |
173 | 229 |
/// <param name="TargatBitmap">비교대상 이미지</param> |
174 | 230 |
/// <param name="ResultRectSize">반환되는 Rect의 사이즈</param> |
175 | 231 |
/// <returns></returns> |
176 |
public async Task<System.Windows.Media.Imaging.BitmapSource> CompareDrawRectsAsync(System.Windows.Media.Imaging.BitmapSource Originalbitmap, System.Windows.Media.Imaging.BitmapSource TargatBitmap, Size ResultRectSize) |
|
232 |
public async Task<System.Windows.Media.Imaging.BitmapSource> CompareDrawRectsAsync(System.Windows.Media.Imaging.BitmapSource Originalbitmap, System.Windows.Media.Imaging.BitmapSource TargatBitmap, Size ResultRectSize, Size? ResultImageSize = null)
|
|
177 | 233 |
{ |
178 | 234 |
|
179 | 235 |
var _Originalbitmap = CreateBitmapFromSource(Originalbitmap); |
180 | 236 |
var _TargatBitmap = CreateBitmapFromSource(TargatBitmap); |
181 | 237 |
|
182 |
var rects = await CompareReturnRectsAsync(_Originalbitmap, _TargatBitmap, ResultRectSize); |
|
238 |
var rects = await CompareReturnRectsAsync(_Originalbitmap, _TargatBitmap, ResultRectSize,ResultImageSize);
|
|
183 | 239 |
|
184 | 240 |
if (rects.Count != 0) |
185 | 241 |
{ |
... | ... | |
304 | 360 |
return result; |
305 | 361 |
} |
306 | 362 |
|
307 |
public async Task<List<System.Windows.Rect>> CompareReturnRectsAsync(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize) |
|
363 |
public async Task<List<System.Windows.Rect>> CompareReturnRectsAsync(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize, Size? ResultImageSize = null)
|
|
308 | 364 |
{ |
309 | 365 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
310 | 366 |
|
... | ... | |
317 | 373 |
Originalbitmap = LoadPicture(OriginalbitmapUri); |
318 | 374 |
TargatBitmap = LoadPicture(TargatBitmapUri); |
319 | 375 |
|
320 |
result = await CompareReturnRectsAsync(Originalbitmap, TargatBitmap, ResultRectSize); |
|
376 |
result = await CompareReturnRectsAsync(Originalbitmap, TargatBitmap, ResultRectSize, ResultImageSize);
|
|
321 | 377 |
} |
322 | 378 |
catch (Exception) |
323 | 379 |
{ |
... | ... | |
332 | 388 |
return result; |
333 | 389 |
} |
334 | 390 |
|
335 |
public async Task<System.Windows.Media.Imaging.BitmapSource> CompareDrawRectsAsync(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize) |
|
391 |
public async Task<System.Windows.Media.Imaging.BitmapSource> CompareDrawRectsAsync(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize, Size? ResultImageSize = null)
|
|
336 | 392 |
{ |
337 | 393 |
System.Windows.Media.Imaging.BitmapSource result = null; |
338 | 394 |
|
... | ... | |
345 | 401 |
Originalbitmap = LoadPicture(OriginalbitmapUri); |
346 | 402 |
TargatBitmap = LoadPicture(TargatBitmapUri); |
347 | 403 |
|
348 |
var bitmap = await CompareDrawRectsAsync(Originalbitmap, TargatBitmap, ResultRectSize); |
|
404 |
var bitmap = await CompareDrawRectsAsync(Originalbitmap, TargatBitmap, ResultRectSize, ResultImageSize);
|
|
349 | 405 |
|
350 | 406 |
result = CreateBitmapSourceFromBitmap(bitmap); |
351 | 407 |
} |
... | ... | |
369 | 425 |
/// <param name="TargatBitmap">비교대상 이미지</param> |
370 | 426 |
/// <param name="ResultRectSize">반환되는 Rect의 사이즈</param> |
371 | 427 |
/// <returns></returns> |
372 |
public async Task<List<System.Windows.Rect>> CompareReturnRectsAsync(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize) |
|
428 |
public async Task<List<System.Windows.Rect>> CompareReturnRectsAsync(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap, Size ResultRectSize,Size? ResultImageSize = null)
|
|
373 | 429 |
{ |
374 | 430 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
375 | 431 |
|
376 | 432 |
try |
377 | 433 |
{ |
378 |
var data = MathchesImageData(Originalbitmap, TargatBitmap); |
|
434 |
Size resultImageSize = Originalbitmap.Size; |
|
435 |
|
|
436 |
if(ResultImageSize.HasValue) |
|
437 |
{ |
|
438 |
resultImageSize = ResultImageSize.Value; |
|
439 |
} |
|
440 |
|
|
441 |
var data = MathchesImageData(Originalbitmap, TargatBitmap, resultImageSize); |
|
379 | 442 |
|
380 | 443 |
result = await GetMatchPixelsAsnc(data, ResultRectSize); |
381 | 444 |
|
445 |
//var data2 = MathchesImageData(TargatBitmap, Originalbitmap, Originalbitmap.Size); |
|
446 |
|
|
447 |
//var result2 = await GetMatchPixelsAsnc(data2, ResultRectSize); |
|
448 |
|
|
449 |
//result.AddRange(result2); |
|
450 |
|
|
451 |
//result = result.Distinct().ToList(); |
|
382 | 452 |
//result = JoinRectList(result); |
383 | 453 |
//if (result.Count() > 0) |
384 | 454 |
//{ |
내보내기 Unified diff