Skip to content

Commit 6f36757

Browse files
committed
add WriteableBitmap samples
1 parent 2987952 commit 6f36757

File tree

15 files changed

+145
-43
lines changed

15 files changed

+145
-43
lines changed

CameraOpenCV/CameraOpenCV.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@
190190
<Version>6.2.10</Version>
191191
</PackageReference>
192192
<PackageReference Include="OpenCvSharp4">
193-
<Version>4.3.0.20200701</Version>
193+
<Version>4.4.0.20200725</Version>
194194
</PackageReference>
195195
<PackageReference Include="OpenCvSharp4.runtime.uwp">
196-
<Version>4.3.0.20200701</Version>
196+
<Version>4.4.0.20200725</Version>
197197
</PackageReference>
198198
</ItemGroup>
199199
<ItemGroup />

SampleBase/SampleBase.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props')" />
3+
<Import Project="..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -85,19 +85,22 @@
8585
</PropertyGroup>
8686
<ItemGroup>
8787
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
88-
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200701\lib\net461\OpenCvSharp.dll</HintPath>
88+
<HintPath>..\packages\OpenCvSharp4.4.4.0.20200725\lib\net461\OpenCvSharp.dll</HintPath>
8989
</Reference>
9090
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
91-
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200701\lib\net461\OpenCvSharp.Blob.dll</HintPath>
91+
<HintPath>..\packages\OpenCvSharp4.4.4.0.20200725\lib\net461\OpenCvSharp.Blob.dll</HintPath>
9292
</Reference>
9393
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
94-
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200701\lib\net461\OpenCvSharp.Extensions.dll</HintPath>
94+
<HintPath>..\packages\OpenCvSharp4.4.4.0.20200725\lib\net461\OpenCvSharp.Extensions.dll</HintPath>
9595
</Reference>
9696
<Reference Include="PresentationCore" />
9797
<Reference Include="PresentationFramework" />
9898
<Reference Include="System" />
9999
<Reference Include="System.Core" />
100100
<Reference Include="System.Drawing" />
101+
<Reference Include="System.Drawing.Common, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
102+
<HintPath>..\packages\System.Drawing.Common.4.7.0\lib\net461\System.Drawing.Common.dll</HintPath>
103+
</Reference>
101104
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
102105
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
103106
</Reference>
@@ -354,7 +357,7 @@
354357
<ErrorText>このプロジェクトは、このコンピューターにはない NuGet パッケージを参照しています。これらをダウンロードするには、NuGet パッケージの復元を有効にしてください。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。不足しているファイルは {0} です。</ErrorText>
355358
</PropertyGroup>
356359
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
357-
<Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props'))" />
360+
<Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props'))" />
358361
</Target>
359362
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
360363
Other similar extension points exist, see Microsoft.Common.targets.

SampleBase/packages.config

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="OpenCvSharp4" version="4.3.0.20200701" targetFramework="net461" />
4-
<package id="OpenCvSharp4.runtime.win" version="4.3.0.20200701" targetFramework="net461" />
5-
<package id="OpenCvSharp4.Windows" version="4.3.0.20200701" targetFramework="net461" />
3+
<package id="OpenCvSharp4" version="4.4.0.20200725" targetFramework="net461" />
4+
<package id="OpenCvSharp4.runtime.win" version="4.4.0.20200725" targetFramework="net461" />
5+
<package id="OpenCvSharp4.Windows" version="4.4.0.20200725" targetFramework="net461" />
6+
<package id="System.Drawing.Common" version="4.7.0" targetFramework="net461" />
67
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
78
</packages>

SamplesCS/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ static void Main(string[] args)
3535
//new KAZESample();
3636
//new MatOperations();
3737
//new MatToBitmap();
38+
//new MatToWriteableBitmap();
3839
//new MDS();
3940
//new MSERSample();
4041
//new NormalArrayOperations();
@@ -45,7 +46,7 @@ static void Main(string[] args)
4546
//new PixelAccess();
4647
//new Pose();
4748
//new SeamlessClone();
48-
//new SiftSurfSample();
49+
new SiftSurfSample();
4950
//new SimpleBlobDetectorSample();
5051
//new SolveEquation();
5152
//new StarDetectorSample();
@@ -55,7 +56,7 @@ static void Main(string[] args)
5556
//new SVMSample();
5657
//new VideoWriterSample();
5758
//new VideoCaptureSample();
58-
new WatershedSample();
59+
//new WatershedSample();
5960
//new WindowGUISample();
6061
sample.Run();
6162
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Drawing;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using OpenCvSharp;
7+
using OpenCvSharp.WpfExtensions;
8+
using SampleBase;
9+
10+
namespace SamplesCS
11+
{
12+
/// <summary>
13+
///
14+
/// </summary>
15+
class MatToWriteableBitmap : ISample
16+
{
17+
public void Run()
18+
{
19+
ToBitmap();
20+
}
21+
22+
public void ToBitmap()
23+
{
24+
using var mat = new Mat(FilePath.Image.Lenna511, ImreadModes.Color); // width % 4 != 0
25+
26+
var wb = WriteableBitmapConverter.ToWriteableBitmap(mat);
27+
28+
var image = new System.Windows.Controls.Image();
29+
image.Source = wb;
30+
31+
var window = new System.Windows.Window();
32+
window.Content = image;
33+
34+
var app = new Application();
35+
app.Run(window);
36+
}
37+
}
38+
}

SamplesCS/Samples/SiftSurfSample.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using OpenCvSharp;
2+
using OpenCvSharp.Features2D;
23
using OpenCvSharp.XFeatures2D;
34
using SampleBase;
45

SamplesCS/SamplesCS.csproj

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props')" />
3+
<Import Project="..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props" Condition="Exists('..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -94,19 +94,25 @@
9494
</PropertyGroup>
9595
<ItemGroup>
9696
<Reference Include="OpenCvSharp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
97-
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200701\lib\net461\OpenCvSharp.dll</HintPath>
97+
<HintPath>..\packages\OpenCvSharp4.4.4.0.20200725\lib\net461\OpenCvSharp.dll</HintPath>
9898
</Reference>
9999
<Reference Include="OpenCvSharp.Blob, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
100-
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200701\lib\net461\OpenCvSharp.Blob.dll</HintPath>
100+
<HintPath>..\packages\OpenCvSharp4.4.4.0.20200725\lib\net461\OpenCvSharp.Blob.dll</HintPath>
101101
</Reference>
102102
<Reference Include="OpenCvSharp.Extensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6adad1e807fea099, processorArchitecture=MSIL">
103-
<HintPath>..\packages\OpenCvSharp4.4.3.0.20200701\lib\net461\OpenCvSharp.Extensions.dll</HintPath>
103+
<HintPath>..\packages\OpenCvSharp4.4.4.0.20200725\lib\net461\OpenCvSharp.Extensions.dll</HintPath>
104+
</Reference>
105+
<Reference Include="OpenCvSharp.WpfExtensions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
106+
<HintPath>..\packages\OpenCvSharp4.WpfExtensions.4.4.0.20200725\lib\net461\OpenCvSharp.WpfExtensions.dll</HintPath>
104107
</Reference>
105108
<Reference Include="PresentationCore" />
106109
<Reference Include="PresentationFramework" />
107110
<Reference Include="System" />
108111
<Reference Include="System.Core" />
109112
<Reference Include="System.Drawing" />
113+
<Reference Include="System.Drawing.Common, Version=4.0.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
114+
<HintPath>..\packages\System.Drawing.Common.4.7.0\lib\net461\System.Drawing.Common.dll</HintPath>
115+
</Reference>
110116
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
111117
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.1\lib\net461\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
112118
</Reference>
@@ -127,6 +133,7 @@
127133
<Compile Include="Samples\FaceDetectionDNN.cs" />
128134
<Compile Include="Samples\DrawBestMatch.cs" />
129135
<Compile Include="Samples\HandPose.cs" />
136+
<Compile Include="Samples\MatToWriteableBitmap.cs" />
130137
<Compile Include="Samples\WatershedSample.cs" />
131138
<Compile Include="Samples\InpaintSample.cs" />
132139
<Compile Include="Samples\PerspectiveTransformSample.cs" />
@@ -188,7 +195,7 @@
188195
<ErrorText>このプロジェクトは、このコンピューターにはない NuGet パッケージを参照しています。これらをダウンロードするには、NuGet パッケージの復元を有効にしてください。詳細については、http://go.microsoft.com/fwlink/?LinkID=322105 を参照してください。不足しているファイルは {0} です。</ErrorText>
189196
</PropertyGroup>
190197
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
191-
<Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.3.0.20200701\build\net\OpenCvSharp4.runtime.win.props'))" />
198+
<Error Condition="!Exists('..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCvSharp4.runtime.win.4.4.0.20200725\build\net\OpenCvSharp4.runtime.win.props'))" />
192199
</Target>
193200
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
194201
Other similar extension points exist, see Microsoft.Common.targets.

SamplesCS/packages.config

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="OpenCvSharp4" version="4.3.0.20200701" targetFramework="net461" />
4-
<package id="OpenCvSharp4.runtime.win" version="4.3.0.20200701" targetFramework="net461" />
5-
<package id="OpenCvSharp4.Windows" version="4.3.0.20200701" targetFramework="net461" />
3+
<package id="OpenCvSharp4" version="4.4.0.20200725" targetFramework="net461" />
4+
<package id="OpenCvSharp4.runtime.win" version="4.4.0.20200725" targetFramework="net461" />
5+
<package id="OpenCvSharp4.Windows" version="4.4.0.20200725" targetFramework="net461" />
6+
<package id="OpenCvSharp4.WpfExtensions" version="4.4.0.20200725" targetFramework="net461" />
7+
<package id="System.Drawing.Common" version="4.7.0" targetFramework="net461" />
68
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.1" targetFramework="net461" />
79
</packages>

SamplesCore/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
2+
using SamplesCS;
53

64
namespace SamplesCore
75
{
86
public class Program
97
{
8+
[STAThread]
109
public static void Main(string[] args)
1110
{
1211
ISample sample =
@@ -16,6 +15,7 @@ public static void Main(string[] args)
1615
//new HOGSample();
1716
//new HoughLinesSample();
1817
//new MatOperations();
18+
//new MatToWriteableBitmap();
1919
//new NormalArrayOperations();
2020
//new PhotoMethods();
2121
//new MorphologySample();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Drawing;
4+
using System.Net.Mime;
5+
using System.Windows;
6+
using System.Windows.Controls;
7+
using OpenCvSharp;
8+
using OpenCvSharp.WpfExtensions;
9+
using SamplesCore;
10+
11+
namespace SamplesCS
12+
{
13+
/// <summary>
14+
///
15+
/// </summary>
16+
class MatToWriteableBitmap : ISample
17+
{
18+
public void Run()
19+
{
20+
ToBitmap();
21+
}
22+
23+
public void ToBitmap()
24+
{
25+
using var mat = new Mat(FilePath.Image.Fruits, ImreadModes.Color); // width % 4 != 0
26+
27+
var wb = WriteableBitmapConverter.ToWriteableBitmap(mat);
28+
29+
var image = new System.Windows.Controls.Image();
30+
image.Source = wb;
31+
32+
var window = new System.Windows.Window();
33+
window.Content = image;
34+
35+
var app = new Application();
36+
app.Run(window);
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)