diff --git a/OpenCvSharpSamples.sln b/OpenCvSharpSamples.sln index 72b6f24..ae9afc6 100644 --- a/OpenCvSharpSamples.sln +++ b/OpenCvSharpSamples.sln @@ -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 @@ -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 diff --git a/SamplesCore.Windows/Data/Image/fruits.jpg b/SamplesCore.Windows/Data/Image/fruits.jpg new file mode 100644 index 0000000..a89b84a Binary files /dev/null and b/SamplesCore.Windows/Data/Image/fruits.jpg differ diff --git a/SamplesCore.Windows/FilePath.cs b/SamplesCore.Windows/FilePath.cs new file mode 100644 index 0000000..d28a939 --- /dev/null +++ b/SamplesCore.Windows/FilePath.cs @@ -0,0 +1,13 @@ +namespace SamplesCore +{ + /// + /// Paths + /// + internal static class FilePath + { + public static class Image + { + public const string Fruits = "Data/Image/fruits.jpg"; + } + } +} diff --git a/SamplesCore.Windows/ISample.cs b/SamplesCore.Windows/ISample.cs new file mode 100644 index 0000000..abd086b --- /dev/null +++ b/SamplesCore.Windows/ISample.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace SamplesCore.Windows +{ + interface ISample + { + void Run(); + } +} diff --git a/SamplesCore.Windows/Program.cs b/SamplesCore.Windows/Program.cs new file mode 100644 index 0000000..4110fdf --- /dev/null +++ b/SamplesCore.Windows/Program.cs @@ -0,0 +1,16 @@ +using System; + +namespace SamplesCore.Windows +{ + class Program + { + [STAThread] + static void Main(string[] args) + { + ISample sample = + new MatToWriteableBitmap(); + + sample.Run(); + } + } +} diff --git a/SamplesCore/Samples/MatToWriteableBitmap.cs b/SamplesCore.Windows/Samples/MatToWriteableBitmap.cs similarity index 94% rename from SamplesCore/Samples/MatToWriteableBitmap.cs rename to SamplesCore.Windows/Samples/MatToWriteableBitmap.cs index 8e0d6fb..ba7c68f 100644 --- a/SamplesCore/Samples/MatToWriteableBitmap.cs +++ b/SamplesCore.Windows/Samples/MatToWriteableBitmap.cs @@ -1,9 +1,8 @@ using System.Windows; using OpenCvSharp; using OpenCvSharp.WpfExtensions; -using SamplesCore; -namespace SamplesCS +namespace SamplesCore.Windows { /// /// diff --git a/SamplesCore.Windows/SamplesCore.Windows.csproj b/SamplesCore.Windows/SamplesCore.Windows.csproj new file mode 100644 index 0000000..d35bbd2 --- /dev/null +++ b/SamplesCore.Windows/SamplesCore.Windows.csproj @@ -0,0 +1,21 @@ + + + + WinExe + net5.0-windows + true + true + + + + + + + + + + PreserveNewest + + + + diff --git a/SamplesCore/Program.cs b/SamplesCore/Program.cs index 0221303..5b14902 100644 --- a/SamplesCore/Program.cs +++ b/SamplesCore/Program.cs @@ -1,5 +1,4 @@ using System; -using SamplesCS; namespace SamplesCore { @@ -12,6 +11,7 @@ public static void Main(string[] args) //new CaffeSample(); //new ClaheSample(); //new ConnectedComponentsSample(); + //new CameraCaptureSample(); new DnnSuperresSample(); //new HOGSample(); //new HoughLinesSample(); diff --git a/SamplesCore/Samples/CameraCaptureSample.cs b/SamplesCore/Samples/CameraCaptureSample.cs new file mode 100644 index 0000000..f8f190d --- /dev/null +++ b/SamplesCore/Samples/CameraCaptureSample.cs @@ -0,0 +1,41 @@ +using System; +using OpenCvSharp; + +namespace SamplesCore +{ + /// + /// + /// + 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; + } + } + } + } +} \ No newline at end of file diff --git a/SamplesCore/Samples/VideoCaptureSample.cs b/SamplesCore/Samples/VideoCaptureSample.cs index b47fd57..feb06d2 100644 --- a/SamplesCore/Samples/VideoCaptureSample.cs +++ b/SamplesCore/Samples/VideoCaptureSample.cs @@ -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); } } } diff --git a/SamplesCore/SamplesCore.csproj b/SamplesCore/SamplesCore.csproj index d5547f8..1f810c3 100644 --- a/SamplesCore/SamplesCore.csproj +++ b/SamplesCore/SamplesCore.csproj @@ -1,11 +1,10 @@ - + netcoreapp3.1 true SamplesCore Exe - true @@ -32,8 +31,8 @@ + - @@ -73,6 +72,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest