개정판 0c575433
issue #0000 compare 수정
Change-Id: I9b57c124b64674f7ae618978955093b399008da5
Markus.ImageComparer/ImageCompareBase.cs | ||
---|---|---|
8 | 8 |
using System.Net; |
9 | 9 |
using System.Runtime.InteropServices; |
10 | 10 |
using System.Text; |
11 |
using System.Threading; |
|
11 | 12 |
using System.Threading.Tasks; |
12 | 13 |
using Point = System.Drawing.Point; |
13 | 14 |
using Size = System.Drawing.Size; |
... | ... | |
38 | 39 |
/// <param name="Originalbitmap">원본 이미지</param> |
39 | 40 |
/// <param name="TargatBitmap">비교대상 이미지</param> |
40 | 41 |
/// <returns>Emgu.CV.TDepth형식의 byte[,,]</returns> |
41 |
protected Mat MathchesImageData(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap) |
|
42 |
protected Mat MathchesImageData(System.Drawing.Bitmap Originalbitmap, System.Drawing.Bitmap TargatBitmap,Size resultSize)
|
|
42 | 43 |
{ |
43 | 44 |
Mat result = new Mat(); |
44 | 45 |
|
... | ... | |
46 | 47 |
{ |
47 | 48 |
SetStatus("Image Load", 0, CompareStatus.Loading); |
48 | 49 |
|
49 |
Originalbitmap = ChangeBitmapFormatAndSize(Originalbitmap, Originalbitmap.Size, PixelFormat.Format24bppRgb);
|
|
50 |
TargatBitmap = ChangeBitmapFormatAndSize(TargatBitmap, Originalbitmap.Size, PixelFormat.Format24bppRgb);
|
|
50 |
Originalbitmap = ChangeBitmapFormatAndSize(Originalbitmap, resultSize, PixelFormat.Format24bppRgb);
|
|
51 |
TargatBitmap = ChangeBitmapFormatAndSize(TargatBitmap, resultSize, PixelFormat.Format24bppRgb);
|
|
51 | 52 |
|
52 | 53 |
// 원본이미지의 크키와 Format24bppRgb로 타켓 이미지를 변경 |
53 | 54 |
// 크기가 틀린 경우 비교시 바이트배열 오류 발생 |
... | ... | |
137 | 138 |
SetStatus("Comparison", 0, CompareStatus.Comparison); |
138 | 139 |
contoursLongCount = contours.Sum(x => x.Count()); |
139 | 140 |
|
141 |
//var rects = contours.AsParallel() |
|
142 |
// .Select(points => GetRectList(points, block)) |
|
143 |
// .SelectMany(x => x); |
|
144 |
|
|
140 | 145 |
var rects = contours.AsParallel() |
141 |
.Select(points => GetRectList(points, block)) |
|
142 |
.SelectMany(x => x); |
|
146 |
.SelectMany(points => GetRectList(points, block)); |
|
143 | 147 |
|
144 | 148 |
results.AddRange(rects); |
145 | 149 |
|
146 | 150 |
return results; |
147 | 151 |
} |
152 |
private List<System.Windows.Rect> GetRectList(OpenCvSharp.Point[] points, Size block) |
|
153 |
{ |
|
154 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
|
155 |
HashSet<System.Windows.Rect> rectSet = new HashSet<System.Windows.Rect>(); |
|
156 |
|
|
157 |
Parallel.For(0, points.Length, i => |
|
158 |
{ |
|
159 |
var rect = new System.Windows.Rect |
|
160 |
{ |
|
161 |
X = points[i].X - block.Width / 2, |
|
162 |
Y = points[i].Y - block.Height / 2, |
|
163 |
Width = block.Width, |
|
164 |
Height = block.Height |
|
165 |
}; |
|
166 |
|
|
167 |
lock (rectSet) |
|
168 |
{ |
|
169 |
if (!rectSet.Any(r => r.IntersectsWith(rect))) |
|
170 |
{ |
|
171 |
rectSet.Add(rect); |
|
172 |
result.Add(rect); |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
int comparisonCount = 0; |
|
177 |
Interlocked.Increment(ref comparisonCount); |
|
178 |
|
|
179 |
ComparisonCount = comparisonCount; |
|
180 |
|
|
181 |
SetStatus("Comparison", ComparisonCount / (double)contoursLongCount * 100, CompareStatus.Comparison); |
|
182 |
}); |
|
183 |
|
|
184 |
return result; |
|
185 |
} |
|
148 | 186 |
|
149 |
private List<System.Windows.Rect> GetRectList(OpenCvSharp.Point[] points,Size block) |
|
187 |
private List<System.Windows.Rect> GetRectList2(OpenCvSharp.Point[] points,Size block)
|
|
150 | 188 |
{ |
151 | 189 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
152 | 190 |
|
내보내기 Unified diff