개정판 503cb09e
service controller 참조 DLL 추가
Change-Id: I71275da928adc2181aa4c8da4b377eccabe90669
ImageComparer/Markus.ImageComparer/ImageComparer.cs | ||
---|---|---|
27 | 27 |
{ |
28 | 28 |
using (Graphics g = Graphics.FromImage(Originalbitmap)) |
29 | 29 |
{ |
30 |
var rect = rects.Select(x => new System.Drawing.Rectangle((int)x.X, (int)x.Y, (int)x.Width, (int)x.Height)); |
|
30 |
var rect = rects.Select(x => new System.Drawing.Rectangle((int)x.X, (int)x.Y, (int)x.Width, (int)x.Height)).ToList();
|
|
31 | 31 |
|
32 | 32 |
g.DrawRectangles(new Pen(Brushes.Blue, 3f), rect.ToArray()); |
33 | 33 |
g.Save(); |
... | ... | |
39 | 39 |
return Originalbitmap; |
40 | 40 |
} |
41 | 41 |
|
42 |
// JoinRects: will return a rectangle composed of r1 and r2. |
|
43 |
private System.Windows.Rect JoinRects(System.Windows.Rect r1, System.Windows.Rect r2) |
|
44 |
{ |
|
45 |
return new System.Windows.Rect(Math.Min(r1.X, r2.X), |
|
46 |
Math.Min(r1.Y, r2.Y), |
|
47 |
Math.Max(r1.Y + r1.Width, r2.Y + r2.Width), |
|
48 |
Math.Max(r1.X + r1.Height, r2.X + r2.Height)); |
|
49 |
} |
|
50 |
|
|
51 |
private System.Windows.Rect RectSizeUp(System.Windows.Rect rect,int UpSize) |
|
52 |
{ |
|
53 |
return new System.Windows.Rect(rect.X - UpSize, rect.Y - UpSize, rect.Width + UpSize, rect.Height + UpSize); |
|
54 |
} |
|
55 |
|
|
42 | 56 |
public System.Windows.Media.Imaging.BitmapSource CompareDrawRects(System.Windows.Media.Imaging.BitmapSource Originalbitmap, System.Windows.Media.Imaging.BitmapSource TargatBitmap, Size ResultRectSize) |
43 | 57 |
{ |
44 | 58 |
var _Originalbitmap = CreateBitmapFromSource(Originalbitmap); |
... | ... | |
103 | 117 |
|
104 | 118 |
try |
105 | 119 |
{ |
120 |
List<System.Windows.Rect> rects = new List<System.Windows.Rect>(); |
|
121 |
|
|
106 | 122 |
byte[,,] data = MathchesImageData(Originalbitmap, TargatBitmap); |
107 | 123 |
|
108 |
result = GetMatchPixels(data, ResultRectSize); |
|
124 |
rects = GetMatchPixels(data, ResultRectSize); |
|
125 |
|
|
126 |
if (rects.Count() > 0) |
|
127 |
{ |
|
128 |
result = Merge(rects, ResultRectSize.Height); |
|
129 |
} |
|
130 |
|
|
131 |
//result = JoinRectList(rects); |
|
109 | 132 |
} |
110 | 133 |
catch (Exception ex) |
111 | 134 |
{ |
... | ... | |
119 | 142 |
return result; |
120 | 143 |
} |
121 | 144 |
|
145 |
private List<System.Windows.Rect> JoinRectList(List<System.Windows.Rect> rects) |
|
146 |
{ |
|
147 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
|
148 |
|
|
149 |
if (rects.Count() > 0) |
|
150 |
{ |
|
151 |
System.Windows.Rect rect = rects[0]; |
|
152 |
System.Windows.Rect joinRect = rects[0]; |
|
153 |
|
|
154 |
while (rects.Count() > 0) |
|
155 |
{ |
|
156 |
var joinItems = rects.Where(x => RectSizeUp(joinRect, 1).Contains(x)).ToList(); |
|
157 |
|
|
158 |
if (joinItems.Count() == 0) |
|
159 |
{ |
|
160 |
result.Add(joinRect); |
|
161 |
} |
|
162 |
else |
|
163 |
{ |
|
164 |
for (int i = 0; i < joinItems.Count(); i++) |
|
165 |
{ |
|
166 |
rect = JoinRects(rect, joinItems[i]); |
|
167 |
rects.Remove(joinItems[i]); |
|
168 |
} |
|
169 |
|
|
170 |
if (rects.Count() > 0) |
|
171 |
{ |
|
172 |
rects.RemoveAt(0); |
|
173 |
} |
|
174 |
|
|
175 |
result.Add(joinRect); |
|
176 |
} |
|
177 |
} |
|
178 |
} |
|
179 |
|
|
180 |
return result; |
|
181 |
} |
|
182 |
|
|
183 |
private List<System.Windows.Rect> Merge(List<System.Windows.Rect> r,int rectHeight) |
|
184 |
{ |
|
185 |
// Computing the bound |
|
186 |
System.Windows.Rect bound = new System.Windows.Rect(r[0].X, r[0].Y, r[0].Width, r[0].Height); |
|
187 |
for (int i = 1; i < r.Count(); ++i) |
|
188 |
{ |
|
189 |
bound.X = Math.Min(bound.X, r[i].X); |
|
190 |
bound.Y = Math.Min(bound.Y, r[i].Y); |
|
191 |
bound.Width = Math.Max(bound.Right, r[i].Right) - bound.X; |
|
192 |
bound.Height = Math.Max(bound.Bottom, r[i].Bottom) - bound.Y; |
|
193 |
} |
|
194 |
|
|
195 |
// Create number of rectangle will be created by vertical strip expansion |
|
196 |
System.Windows.Rect[] m = new System.Windows.Rect[(int)bound.Height / (int)rectHeight]; |
|
197 |
for (int i = 0; i < m.Length; ++i) |
|
198 |
{ |
|
199 |
m[i] = new System.Windows.Rect(Int32.MaxValue,bound.Y + i * rectHeight, 0, rectHeight); |
|
200 |
} |
|
201 |
|
|
202 |
for (int i = 0; i < r.Count(); ++i) |
|
203 |
{ |
|
204 |
int index = ((int)r[i].Y - (int)bound.Y) / rectHeight; |
|
205 |
|
|
206 |
if (m[index].Width <= 0) |
|
207 |
{ |
|
208 |
m[index].Width = r[i].Width; |
|
209 |
m[index].X = r[i].X; |
|
210 |
} |
|
211 |
else |
|
212 |
{ |
|
213 |
int right = (int)m[index].Right; |
|
214 |
m[index].X = Math.Min(m[index].X, r[i].X); |
|
215 |
m[index].Width = Math.Max(right, r[i].Right) - m[index].X; |
|
216 |
} |
|
217 |
} |
|
218 |
|
|
219 |
// Merge horozontally |
|
220 |
for (int i = m.Length - 1; i > 0; --i) |
|
221 |
{ |
|
222 |
// can only merge when two rect has the same X and Width |
|
223 |
if ((m[i].X == m[i - 1].X) && (m[i].Width == m[i - 1].Width)) |
|
224 |
{ |
|
225 |
m[i - 1].Height += m[i].Height; // expanse the rectangle |
|
226 |
m[i].Width = 0; // remove one rectangle |
|
227 |
} |
|
228 |
} |
|
229 |
|
|
230 |
// Remove all the empty rectangle |
|
231 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
|
232 |
for (int i = m.Length - 1; i >= 0; --i) |
|
233 |
{ |
|
234 |
if (m[i].Width > 0) |
|
235 |
result.Add(m[i]); |
|
236 |
} |
|
237 |
|
|
238 |
return result; |
|
239 |
} |
|
122 | 240 |
/// <summary> |
123 | 241 |
/// 이미지를 비교 후 원본 이미지에 Rect를 그린다. |
124 | 242 |
/// 메모리 문제 발생 |
... | ... | |
137 | 255 |
{ |
138 | 256 |
using (Graphics g = Graphics.FromImage(cloneOriginal)) |
139 | 257 |
{ |
258 |
|
|
140 | 259 |
var rect = rects.Select(x => new System.Drawing.Rectangle((int)x.X, (int)x.Y, (int)x.Width, (int)x.Height)); |
141 | 260 |
|
142 | 261 |
g.DrawRectangles(new Pen(Brushes.Blue, 3f), rect.ToArray()); |
... | ... | |
326 | 445 |
byte[,,] data = MathchesImageData(Originalbitmap, TargatBitmap); |
327 | 446 |
|
328 | 447 |
result = await GetMatchPixelsAsnc(data, ResultRectSize); |
329 |
|
|
448 |
|
|
449 |
//result = JoinRectList(result); |
|
450 |
if (result.Count() > 0) |
|
451 |
{ |
|
452 |
result = Merge(result, ResultRectSize.Height); |
|
453 |
} |
|
454 |
|
|
330 | 455 |
data = null; |
331 | 456 |
} |
332 | 457 |
catch (Exception ex) |
내보내기 Unified diff