개정판 66351e6d
ImageCompare 정확도 수정
Change-Id: If781225b99a2e230514abaaef8b9972e66463c07
ImageComparer/ComparerTestWPF/ComparerTestWPF.csproj | ||
---|---|---|
1 | 1 |
<?xml version="1.0" encoding="utf-8"?> |
2 | 2 |
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
3 |
<Import Project="..\packages\OpenCvSharp4.runtime.win.4.3.0.20200524\build\net\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.3.0.20200524\build\net\OpenCvSharp4.runtime.win.props')" /> |
|
4 | 3 |
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> |
5 | 4 |
<PropertyGroup> |
6 | 5 |
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
... | ... | |
55 | 54 |
<Prefer32Bit>false</Prefer32Bit> |
56 | 55 |
</PropertyGroup> |
57 | 56 |
<ItemGroup> |
58 |
<Reference Include="Markus.Image.OpenCV, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> |
|
59 |
<HintPath>..\packages\Markus.Image.ImageCompare.1.0.0\lib\net461\Markus.Image.OpenCV.dll</HintPath> |
|
60 |
</Reference> |
|
61 |
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> |
|
62 |
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200524\lib\net461\OpenCvSharp.dll</HintPath> |
|
63 |
</Reference> |
|
64 |
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> |
|
65 |
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200524\lib\net461\OpenCvSharp.Blob.dll</HintPath> |
|
66 |
</Reference> |
|
67 |
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL"> |
|
68 |
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200524\lib\net461\OpenCvSharp.Extensions.dll</HintPath> |
|
69 |
</Reference> |
|
70 | 57 |
<Reference Include="System" /> |
71 | 58 |
<Reference Include="System.Data" /> |
72 | 59 |
<Reference Include="System.Drawing" /> |
73 |
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> |
|
74 |
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath> |
|
75 |
</Reference> |
|
76 | 60 |
<Reference Include="System.Xml" /> |
77 | 61 |
<Reference Include="Microsoft.CSharp" /> |
78 | 62 |
<Reference Include="System.Core" /> |
... | ... | |
132 | 116 |
<Generator>ResXFileCodeGenerator</Generator> |
133 | 117 |
<LastGenOutput>Resources.Designer.cs</LastGenOutput> |
134 | 118 |
</EmbeddedResource> |
135 |
<None Include="packages.config" /> |
|
136 | 119 |
<None Include="Properties\Settings.settings"> |
137 | 120 |
<Generator>SettingsSingleFileGenerator</Generator> |
138 | 121 |
<LastGenOutput>Settings.Designer.cs</LastGenOutput> |
... | ... | |
148 | 131 |
<Install>false</Install> |
149 | 132 |
</BootstrapperPackage> |
150 | 133 |
</ItemGroup> |
134 |
<ItemGroup> |
|
135 |
<ProjectReference Include="..\Markus.ImageComparer\Markus.Image.csproj"> |
|
136 |
<Project>{b3b05ced-f4eb-4f9d-b458-12fcbe48d546}</Project> |
|
137 |
<Name>Markus.Image</Name> |
|
138 |
</ProjectReference> |
|
139 |
</ItemGroup> |
|
151 | 140 |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
152 |
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> |
|
153 |
<PropertyGroup> |
|
154 |
<ErrorText>이 프로젝트는 이 컴퓨터에 없는 NuGet 패키지를 참조합니다. 해당 패키지를 다운로드하려면 NuGet 패키지 복원을 사용하십시오. 자세한 내용은 http://go.microsoft.com/fwlink/?LinkID=322105를 참조하십시오. 누락된 파일은 {0}입니다.</ErrorText> |
|
155 |
</PropertyGroup> |
|
156 |
<Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.3.0.20200524\build\net\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.3.0.20200524\build\net\OpenCvSharp4.runtime.win.props'))" /> |
|
157 |
</Target> |
|
158 | 141 |
</Project> |
ImageComparer/ComparerTestWPF/MainWindow.xaml.cs | ||
---|---|---|
129 | 129 |
|
130 | 130 |
private async void btTaskUri_Click(object sender, RoutedEventArgs e) |
131 | 131 |
{ |
132 |
BitmapSource bitmapSource = null; |
|
132 | 133 |
|
133 | 134 |
using (Markus.Image.ImageCompare imageComparer = new Markus.Image.ImageCompare()) |
134 | 135 |
{ |
135 |
var result = await imageComparer.CompareReturnRectsAsync("http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000102/1.png" |
|
136 |
, "http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000101/1.png", new System.Drawing.Size(20, 20)); |
|
137 |
// bitmapSource = imageComparer.CreateWriteableBitmapFromBitmap(result); |
|
136 |
var result = await imageComparer.CompareDrawRectsAsync("http://10.11.252.3/TileSource/LPG_Tile/215/21544/9.png" |
|
137 |
, "http://10.11.252.3/TileSource/LPG_Tile/211/21107/9.png", new System.Drawing.Size(20, 20)); |
|
138 | 138 |
|
139 |
lstView.ItemsSource = result;
|
|
139 |
bitmapSource = result;
|
|
140 | 140 |
|
141 |
var result2 = await imageComparer.CompareReturnRectsAsync("http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000101/1.png" |
|
142 |
, "http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000102/1.png", new System.Drawing.Size(20, 20)); |
|
141 |
//lstView.ItemsSource = result; |
|
143 | 142 |
|
144 |
lstView2.ItemsSource = result2; |
|
143 |
//var result2 = await imageComparer.CompareReturnRectsAsync("http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000101/1.png" |
|
144 |
// , "http://192.168.0.67:5977/TileSource/000000_Tile/110001/11000102/1.png", new System.Drawing.Size(20, 20)); |
|
145 |
|
|
146 |
//lstView2.ItemsSource = result2; |
|
145 | 147 |
//TargetSource = imageComparer.CreateWriteableBitmapFromBitmap(result2); |
146 | 148 |
|
147 | 149 |
} |
150 |
|
|
151 |
ImageView imageView = new ImageView(bitmapSource); |
|
152 |
|
|
153 |
imageView.Show(); |
|
148 | 154 |
} |
149 | 155 |
} |
150 | 156 |
} |
ImageComparer/ComparerTestWPF/packages.config | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<packages> |
|
3 |
<package id="Markus.Image.ImageCompare" version="1.0.0" targetFramework="net461" /> |
|
4 |
<package id="OpenCvSharp4" version="4.3.0.20200524" targetFramework="net461" /> |
|
5 |
<package id="OpenCvSharp4.runtime.win" version="4.3.0.20200524" targetFramework="net461" /> |
|
6 |
<package id="OpenCvSharp4.Windows" version="4.3.0.20200524" targetFramework="net461" /> |
|
7 |
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" /> |
|
8 |
</packages> |
ImageComparer/Markus.ImageComparer/ImageComparer.cs | ||
---|---|---|
317 | 317 |
return result; |
318 | 318 |
} |
319 | 319 |
|
320 |
public async Task<System.Windows.Media.Imaging.BitmapSource> CompareDrawRectsAsync(string OriginalbitmapUri, string TargatBitmapUri, Size ResultRectSize) |
|
321 |
{ |
|
322 |
System.Windows.Media.Imaging.BitmapSource result = null; |
|
323 |
|
|
324 |
Bitmap Originalbitmap = null; |
|
325 |
Bitmap TargatBitmap = null; |
|
326 |
|
|
327 |
try |
|
328 |
{ |
|
329 |
|
|
330 |
Originalbitmap = LoadPicture(OriginalbitmapUri); |
|
331 |
TargatBitmap = LoadPicture(TargatBitmapUri); |
|
332 |
|
|
333 |
var bitmap = await CompareDrawRectsAsync(Originalbitmap, TargatBitmap, ResultRectSize); |
|
334 |
|
|
335 |
result = CreateBitmapSourceFromBitmap(bitmap); |
|
336 |
} |
|
337 |
catch (Exception) |
|
338 |
{ |
|
339 |
throw; |
|
340 |
} |
|
341 |
finally |
|
342 |
{ |
|
343 |
Originalbitmap.Dispose(); |
|
344 |
TargatBitmap.Dispose(); |
|
345 |
} |
|
346 |
|
|
347 |
return result; |
|
348 |
} |
|
349 |
|
|
320 | 350 |
/// <summary> |
321 | 351 |
/// 이미지를 비교 후 해당 영역을 Rect로 반환한다. |
322 | 352 |
/// </summary> |
ImageComparer/Markus.ImageComparer/ImageComparerBase.cs | ||
---|---|---|
46 | 46 |
{ |
47 | 47 |
SetStatus("Image Load", 0, CompareStatus.Loading); |
48 | 48 |
|
49 |
Originalbitmap = ChangeBitmapFormatAndSize(Originalbitmap, Originalbitmap.Size, PixelFormat.Format24bppRgb); |
|
50 |
TargatBitmap = ChangeBitmapFormatAndSize(TargatBitmap, Originalbitmap.Size, PixelFormat.Format24bppRgb); |
|
51 |
|
|
49 | 52 |
// 원본이미지의 크키와 Format24bppRgb로 타켓 이미지를 변경 |
50 | 53 |
// 크기가 틀린 경우 비교시 바이트배열 오류 발생 |
51 | 54 |
OriginalImageData = OpenCvSharp.Extensions.BitmapConverter.ToMat(Originalbitmap); |
... | ... | |
77 | 80 |
return result; |
78 | 81 |
} |
79 | 82 |
|
83 |
protected System.Drawing.Bitmap ChangeBitmapFormatAndSize(System.Drawing.Bitmap bitmap, Size newSize, PixelFormat pixelFormat) |
|
84 |
{ |
|
85 |
Bitmap result = bitmap; |
|
86 |
|
|
87 |
if (pixelFormat != bitmap.PixelFormat) |
|
88 |
{ |
|
89 |
Point originPoint = new Point(0, 0); |
|
90 |
Rectangle rect = new Rectangle(originPoint, bitmap.Size); |
|
91 |
result = bitmap.Clone(rect, pixelFormat); |
|
92 |
} |
|
93 |
|
|
94 |
if (bitmap.Size != newSize) |
|
95 |
{ |
|
96 |
result = new Bitmap(newSize.Width, newSize.Height); |
|
97 |
|
|
98 |
using (Graphics g = Graphics.FromImage(result)) |
|
99 |
{ |
|
100 |
g.DrawImage(bitmap, 0, 0, newSize.Width, newSize.Height); |
|
101 |
g.Dispose(); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
return result; |
|
106 |
} |
|
107 |
|
|
80 | 108 |
/// <summary> |
81 | 109 |
/// Image<TColor, TDepth>의 틀린 부분을 Rect로 반환 |
82 | 110 |
/// </summary> |
... | ... | |
102 | 130 |
|
103 | 131 |
OpenCvSharp.Point testpoint = new OpenCvSharp.Point(); |
104 | 132 |
|
105 |
Cv2.Threshold(data, data, 90, 255,ThresholdTypes.BinaryInv);
|
|
133 |
Cv2.Threshold(data, data, 0, 0,ThresholdTypes.BinaryInv);
|
|
106 | 134 |
|
107 | 135 |
Cv2.FindContours(data, out contours, out hierarchy,RetrievalModes.List,ContourApproximationModes.ApproxNone, testpoint); |
108 | 136 |
|
내보내기 Unified diff