개정판 fc5ed14c
issue #0000 compar기능을 client에서 하도록 수정
Change-Id: I5654925814de0f9fbace8b8f0a224f878dc4f258
Markus.ImageComparer/ImageCompareBase.cs | ||
---|---|---|
19 | 19 |
{ |
20 | 20 |
public class ImageCompareBase : IDisposable |
21 | 21 |
{ |
22 |
Mat OriginalImageData = null; |
|
23 |
Mat TargatImageData = null; |
|
24 |
|
|
25 | 22 |
double contoursLongCount = 0; |
26 | 23 |
int ComparisonCount = 0; |
27 | 24 |
public CompareProgress Progress = new CompareProgress(); |
... | ... | |
54 | 51 |
|
55 | 52 |
// 원본이미지의 크키와 Format24bppRgb로 타켓 이미지를 변경 |
56 | 53 |
// 크기가 틀린 경우 비교시 바이트배열 오류 발생 |
57 |
OriginalImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(Originalbitmap); |
|
58 |
TargatImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(TargatBitmap); |
|
59 |
|
|
60 |
if (OriginalImageData.Size() != TargatImageData.Size()) |
|
54 |
using (Mat OriginalImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(Originalbitmap)) |
|
61 | 55 |
{ |
62 |
Cv2.Resize(TargatImageData, TargatImageData, OriginalImageData.Size()); |
|
56 |
using (Mat TargatImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(TargatBitmap)) |
|
57 |
{ |
|
58 |
if (OriginalImageData.Size() != TargatImageData.Size()) |
|
59 |
{ |
|
60 |
Cv2.Resize(TargatImageData, TargatImageData, OriginalImageData.Size()); |
|
61 |
} |
|
62 |
|
|
63 |
Cv2.CvtColor(OriginalImageData, OriginalImageData, ColorConversionCodes.BGR2GRAY); |
|
64 |
Cv2.CvtColor(TargatImageData, TargatImageData, ColorConversionCodes.BGR2GRAY); |
|
65 |
|
|
66 |
using (Mat outputData = new Mat(new OpenCvSharp.Size(resultSize.Width, resultSize.Height), MatType.CV_8UC1)) |
|
67 |
{ |
|
68 |
Cv2.Absdiff(OriginalImageData, TargatImageData, outputData); |
|
69 |
// 틀린부분을 반환 |
|
70 |
Cv2.BitwiseNot(outputData, result); |
|
71 |
} |
|
72 |
} |
|
63 | 73 |
} |
64 |
|
|
65 |
Cv2.CvtColor(OriginalImageData, OriginalImageData, ColorConversionCodes.BGR2GRAY); |
|
66 |
Cv2.CvtColor(TargatImageData, TargatImageData, ColorConversionCodes.BGR2GRAY); |
|
67 |
|
|
68 |
Mat outputData = new Mat(new OpenCvSharp.Size(resultSize.Width, resultSize.Height), MatType.CV_8UC1); |
|
69 |
|
|
70 |
Cv2.Absdiff(OriginalImageData, TargatImageData, outputData); |
|
71 |
|
|
72 |
// 틀린부분을 반환 |
|
73 |
Cv2.BitwiseNot(outputData, result); |
|
74 | 74 |
} |
75 | 75 |
catch (Exception ex) |
76 | 76 |
{ |
... | ... | |
102 | 102 |
System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); |
103 | 103 |
stopwatch.Start(); |
104 | 104 |
|
105 |
Mat outputMat = new Mat(data.Size(), MatType.CV_8UC1); |
|
105 |
//Mat outputMat = new Mat(data.Size(), MatType.CV_8UC1);
|
|
106 | 106 |
|
107 | 107 |
HierarchyIndex[] hierarchy; |
108 | 108 |
OpenCvSharp.Point[][] contours; |
... | ... | |
120 | 120 |
// .Select(points => GetRectList(points, block)) |
121 | 121 |
// .SelectMany(x => x); |
122 | 122 |
|
123 |
var rects = contours.AsParallel() |
|
124 |
.SelectMany(points => GetRectList(points, block)); |
|
123 |
var rects = contours.SelectMany(points => GetRectList(points, block)); |
|
125 | 124 |
|
126 | 125 |
results.AddRange(rects); |
127 | 126 |
|
128 | 127 |
return results; |
129 | 128 |
} |
130 | 129 |
|
131 |
private List<System.Windows.Rect> GetRectList(OpenCvSharp.Point[] points, Size block) |
|
130 |
private List<System.Windows.Rect> GetRectListAsParallel(OpenCvSharp.Point[] points, Size block)
|
|
132 | 131 |
{ |
133 | 132 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
134 | 133 |
ConcurrentBag<System.Windows.Rect> rectBag = new ConcurrentBag<System.Windows.Rect>(); |
135 | 134 |
|
136 | 135 |
Parallel.For(0, points.Length, i => |
137 | 136 |
{ |
137 |
if (i >= points.Length) return; // 배열 길이 확인 |
|
138 |
|
|
138 | 139 |
var rect = new System.Windows.Rect |
139 | 140 |
{ |
140 | 141 |
X = points[i].X - block.Width / 2, |
... | ... | |
183 | 184 |
} |
184 | 185 |
|
185 | 186 |
|
186 |
private List<System.Windows.Rect> GetRectList2(OpenCvSharp.Point[] points,Size block)
|
|
187 |
private List<System.Windows.Rect> GetRectList(OpenCvSharp.Point[] points,Size block) |
|
187 | 188 |
{ |
188 | 189 |
List<System.Windows.Rect> result = new List<System.Windows.Rect>(); |
189 | 190 |
|
... | ... | |
294 | 295 |
// 이 코드를 변경하지 마세요. 위의 Dispose(bool disposing)에 정리 코드를 입력하세요. |
295 | 296 |
Dispose(true); |
296 | 297 |
|
297 |
|
|
298 |
if (OriginalImageData != null) |
|
299 |
{ |
|
300 |
OriginalImageData.Dispose(); |
|
301 |
} |
|
302 |
|
|
303 |
if (TargatImageData != null) |
|
304 |
{ |
|
305 |
TargatImageData.Dispose(); |
|
306 |
} |
|
307 |
|
|
308 | 298 |
// TODO: 위의 종료자가 재정의된 경우 다음 코드 줄의 주석 처리를 제거합니다. |
309 | 299 |
// GC.SuppressFinalize(this); |
310 | 300 |
GC.Collect(); |
내보내기 Unified diff