프로젝트

일반

사용자정보

개정판 9f61d7b6

ID9f61d7b64326f9595e87f955ac737347e6d88ce5
상위 6b6bc870
하위 51477835

김태성이(가) 4년 이상 전에 추가함

ImageCompare CompareStatus 추가
- 진행 상테를 Progress로 저장

Change-Id: I6d326cb72fb5a695a93cb0d1c2f7dd2f305f4ee2

차이점 보기:

ImageComparer/Markus.ImageComparer/ImageComparer.cs
8 8

  
9 9
namespace Markus.Image
10 10
{
11
    public class ImageComparer : ImageComparerBase
11
    public class ImageCompare : ImageCompareBase
12 12
    {
13 13
        /// <summary>
14 14
        /// 이미지를 비교 후 원본 이미지에 Rect를 그린다.
......
37 37
            return Originalbitmap;
38 38
        }
39 39

  
40
        // JoinRects: will return a rectangle composed of r1 and r2.
41
        private System.Windows.Rect JoinRects(System.Windows.Rect r1, System.Windows.Rect r2)
42
        {
43
            return new System.Windows.Rect(Math.Min(r1.X, r2.X),
44
                            Math.Min(r1.Y, r2.Y),
45
                            Math.Max(r1.Y + r1.Width, r2.Y + r2.Width),
46
                            Math.Max(r1.X + r1.Height, r2.X + r2.Height));
47
        }
48

  
49
        private System.Windows.Rect RectSizeUp(System.Windows.Rect rect,int UpSize)
50
        {
51
            return new System.Windows.Rect(rect.X - UpSize, rect.Y - UpSize, rect.Width + UpSize, rect.Height + UpSize);
52
        }
53

  
54 40
        public System.Windows.Media.Imaging.BitmapSource CompareDrawRects(System.Windows.Media.Imaging.BitmapSource Originalbitmap, System.Windows.Media.Imaging.BitmapSource TargatBitmap, Size ResultRectSize)
55 41
        {
56 42
            var _Originalbitmap = CreateBitmapFromSource(Originalbitmap);
......
83 69

  
84 70
            try
85 71
            {
86

  
87 72
                Originalbitmap = LoadPicture(OriginalbitmapUri);
88 73
                TargatBitmap = LoadPicture(TargatBitmapUri);
89 74

  
......
140 125
            return result;
141 126
        }
142 127

  
143
        private List<System.Windows.Rect> JoinRectList(List<System.Windows.Rect> rects)
144
        {
145
            List<System.Windows.Rect> result = new List<System.Windows.Rect>();
146

  
147
            if (rects.Count() > 0)
148
            {
149
                System.Windows.Rect rect = rects[0];
150
                System.Windows.Rect joinRect = rects[0];
151

  
152
                while (rects.Count() > 0)
153
                {
154
                    var joinItems = rects.Where(x => RectSizeUp(joinRect, 1).Contains(x)).ToList();
155

  
156
                    if (joinItems.Count() == 0)
157
                    {
158
                        result.Add(joinRect);
159
                    }
160
                    else
161
                    {
162
                        for (int i = 0; i < joinItems.Count(); i++)
163
                        {
164
                            rect = JoinRects(rect, joinItems[i]);
165
                            rects.Remove(joinItems[i]);
166
                        }
167

  
168
                        if (rects.Count() > 0)
169
                        {
170
                            rects.RemoveAt(0);
171
                        }
172

  
173
                        result.Add(joinRect);
174
                    }
175
                }
176
            }
177

  
178
            return result;
179
        }
180

  
181
        private List<System.Windows.Rect> Merge(List<System.Windows.Rect> r,int rectHeight)
182
        {
183
            // Computing the bound
184
            System.Windows.Rect bound = new System.Windows.Rect(r[0].X, r[0].Y, r[0].Width, r[0].Height);
185
            for (int i = 1; i < r.Count(); ++i)
186
            {
187
                bound.X = Math.Min(bound.X, r[i].X);
188
                bound.Y = Math.Min(bound.Y, r[i].Y);
189
                bound.Width = Math.Max(bound.Right, r[i].Right) - bound.X;
190
                bound.Height = Math.Max(bound.Bottom, r[i].Bottom) - bound.Y;
191
            }
192

  
193
            // Create number of rectangle will be created by vertical strip expansion
194
            System.Windows.Rect[] m = new System.Windows.Rect[(int)bound.Height / (int)rectHeight];
195
            for (int i = 0; i < m.Length; ++i)
196
            {
197
                m[i] = new System.Windows.Rect(bound.X, bound.Y + i * rectHeight, bound.Y, rectHeight);
198
            }
199

  
200
            for (int i = 0; i < r.Count(); ++i)
201
            {
202
                int index = ((int)r[i].Y - (int)bound.Y) / rectHeight;
203

  
204
                if (m[index].Width <= 0)
205
                {
206
                    m[index].Width = r[i].Width;
207
                    m[index].X = r[i].X;
208
                }
209
                else
210
                {
211
                    int right = (int)m[index].Right;
212
                    m[index].X = Math.Min(m[index].X, r[i].X);
213
                    m[index].Width = Math.Max(right, r[i].Right) - m[index].X;
214
                }
215
            }
216

  
217
            // Merge horozontally
218
            for (int i = m.Length - 1; i > 0; --i)
219
            {
220
                // can only merge when two rect has the same X and Width
221
                if ((m[i].X == m[i - 1].X) && (m[i].Width == m[i - 1].Width))
222
                {
223
                    m[i - 1].Height += m[i].Height; // expanse the rectangle
224
                    m[i].Width = 0;                // remove one rectangle
225
                }
226
            }
227

  
228
            // Remove all the empty rectangle
229
            List<System.Windows.Rect> result = new List<System.Windows.Rect>();
230
            for (int i = m.Length - 1; i >= 0; --i)
231
            {
232
                if (m[i].Width > 0)
233
                    result.Add(m[i]);
234
            }
235

  
236
            return result;
237
        }
238 128
        /// <summary>
239 129
        /// 이미지를 비교 후 원본 이미지에 Rect를 그린다.
240 130
        /// 메모리 문제 발생

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)