Skip to content

Commit

Permalink
add SamplesCore.Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shimat committed Jan 22, 2021
1 parent b9ff2e8 commit fe3e879
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 19 deletions.
22 changes: 22 additions & 0 deletions OpenCvSharpSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CameraOpenCV", "CameraOpenC
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoCaptureForm", "VideoCaptureForm\VideoCaptureForm.csproj", "{9DCC89F3-9D9F-4813-A4A3-36F8457E7F85}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesCore.Windows", "SamplesCore.Windows\SamplesCore.Windows.csproj", "{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -157,6 +159,26 @@ Global
{9DCC89F3-9D9F-4813-A4A3-36F8457E7F85}.Release|x64.Build.0 = Release|Any CPU
{9DCC89F3-9D9F-4813-A4A3-36F8457E7F85}.Release|x86.ActiveCfg = Release|Any CPU
{9DCC89F3-9D9F-4813-A4A3-36F8457E7F85}.Release|x86.Build.0 = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|ARM.ActiveCfg = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|ARM.Build.0 = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|ARM64.Build.0 = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|x64.ActiveCfg = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|x64.Build.0 = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|x86.ActiveCfg = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Debug|x86.Build.0 = Debug|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|Any CPU.Build.0 = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|ARM.ActiveCfg = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|ARM.Build.0 = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|ARM64.ActiveCfg = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|ARM64.Build.0 = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|x64.ActiveCfg = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|x64.Build.0 = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|x86.ActiveCfg = Release|Any CPU
{41A0CB46-CEC7-4DB2-B2F5-C538D29DC11D}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
Binary file added SamplesCore.Windows/Data/Image/fruits.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions SamplesCore.Windows/FilePath.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SamplesCore
{
/// <summary>
/// Paths
/// </summary>
internal static class FilePath
{
public static class Image
{
public const string Fruits = "Data/Image/fruits.jpg";
}
}
}
12 changes: 12 additions & 0 deletions SamplesCore.Windows/ISample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SamplesCore.Windows
{
interface ISample
{
void Run();
}
}
16 changes: 16 additions & 0 deletions SamplesCore.Windows/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace SamplesCore.Windows
{
class Program
{
[STAThread]
static void Main(string[] args)
{
ISample sample =
new MatToWriteableBitmap();

sample.Run();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System.Windows;
using OpenCvSharp;
using OpenCvSharp.WpfExtensions;
using SamplesCore;

namespace SamplesCS
namespace SamplesCore.Windows
{
/// <summary>
///
Expand Down
21 changes: 21 additions & 0 deletions SamplesCore.Windows/SamplesCore.Windows.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net5.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.1.20201229" />
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.5.1.20201229" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Image\fruits.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion SamplesCore/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using SamplesCS;

namespace SamplesCore
{
Expand All @@ -12,6 +11,7 @@ public static void Main(string[] args)
//new CaffeSample();
//new ClaheSample();
//new ConnectedComponentsSample();
//new CameraCaptureSample();
new DnnSuperresSample();
//new HOGSample();
//new HoughLinesSample();
Expand Down
41 changes: 41 additions & 0 deletions SamplesCore/Samples/CameraCaptureSample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using OpenCvSharp;

namespace SamplesCore
{
/// <summary>
///
/// </summary>
class CameraCaptureSample : ISample
{
public void Run()
{
using var capture = new VideoCapture(0, VideoCaptureAPIs.DSHOW);
if (!capture.IsOpened())
return;

capture.FrameWidth = 1920;
capture.FrameHeight = 1280;
capture.AutoFocus = true;

const int sleepTime = 10;

using var window = new Window("capture");
var image = new Mat();

while (true)
{
capture.Read(image);
if (image.Empty())
break;

window.ShowImage(image);
int c = Cv2.WaitKey(sleepTime);
if (c >= 0)
{
break;
}
}
}
}
}
26 changes: 13 additions & 13 deletions SamplesCore/Samples/VideoCaptureSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ public void Run()
{
// Opens MP4 file (ffmpeg is probably needed)
using var capture = new VideoCapture(FilePath.Movie.Bach);
if (!capture.IsOpened())
return;

int sleepTime = (int)Math.Round(1000 / capture.Fps);

using (var window = new Window("capture"))
{
// Frame image buffer
var image = new Mat();
using var window = new Window("capture");
// Frame image buffer
var image = new Mat();

// When the movie playback reaches end, Mat.data becomes NULL.
while (true)
{
capture.Read(image); // same as cvQueryFrame
if(image.Empty())
break;
// When the movie playback reaches end, Mat.data becomes NULL.
while (true)
{
capture.Read(image); // same as cvQueryFrame
if(image.Empty())
break;

window.ShowImage(image);
Cv2.WaitKey(sleepTime);
}
window.ShowImage(image);
Cv2.WaitKey(sleepTime);
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions SamplesCore/SamplesCore.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>SamplesCore</AssemblyName>
<OutputType>Exe</OutputType>
<UseWPF>true</UseWPF>
<!--
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
-->
Expand All @@ -32,8 +31,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="OpenCvSharp4" Version="4.5.1.20201229" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.5.1.20201229" />
<PackageReference Include="OpenCvSharp4.WpfExtensions" Version="4.5.1.20201229" />
</ItemGroup>

<ItemGroup>
Expand Down Expand Up @@ -73,6 +72,9 @@
<None Update="Data\Movie\bach.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\Movie\video.mp4">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\Text\bvlc_googlenet.prototxt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down

0 comments on commit fe3e879

Please sign in to comment.