diff --git a/README.md b/README.md index 61db619..5c87809 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,8 @@ from the camera can be used. - [CaptureVis3D](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Applications/Basic/Visualization/CaptureVis3D/CaptureVis3D.cs) - Capture point clouds, with color, from the Zivid camera, and visualize them. - [ProjectImageStartAndStop](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Applications/Basic/Visualization/ProjectImageStartAndStop/ProjectImageStartAndStop.cs) - Start the Image Projection and Stop it. + - [ReadAndProjectImage](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.cs) - Read a 2D image from file and project it using the + camera projector. - **FileFormats** - [ReadIterateZDF](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Applications/Basic/FileFormats/ReadIterateZDF/ReadIterateZDF.cs) - Read point cloud data from a ZDF file, iterate through it, and extract individual points. diff --git a/source/Applications/Basic/Visualization/ReadAndProjectImage/App.config b/source/Applications/Basic/Visualization/ReadAndProjectImage/App.config new file mode 100644 index 0000000..8227adb --- /dev/null +++ b/source/Applications/Basic/Visualization/ReadAndProjectImage/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/source/Applications/Basic/Visualization/ReadAndProjectImage/Properties/AssemblyInfo.cs b/source/Applications/Basic/Visualization/ReadAndProjectImage/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..5d2e720 --- /dev/null +++ b/source/Applications/Basic/Visualization/ReadAndProjectImage/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ReadAndProjectImage")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("ReadAndProjectImage")] +[assembly: AssemblyCopyright("Copyright 2015-2023 (C) Zivid AS")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("79BE4F01-8935-49FD-BD8F-551E62FF03CA")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.cs b/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.cs new file mode 100644 index 0000000..b6143ba --- /dev/null +++ b/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.cs @@ -0,0 +1,82 @@ +/* +Read a 2D image from file and project it using the camera projector. + +The image for this sample can be found under the main instructions for Zivid samples. +*/ + +using System; +using Duration = Zivid.NET.Duration; + +class Program +{ + static int Main() + { + try + { + var zivid = new Zivid.NET.Application(); + + Console.WriteLine("Connecting to camera"); + using (var camera = zivid.ConnectCamera()) + { + string projectorImageFileForGivenCamera = GetProjectorImageFileForCamera(camera); + + Console.WriteLine("Reading 2D image (of resolution matching the Zivid camera projector resolution) from file: " + projectorImageFileForGivenCamera); + var projectorImageForGivenCamera = new Zivid.NET.ImageBGRA(projectorImageFileForGivenCamera); + + using (var projectedImageHandle = Zivid.NET.Experimental.Projection.Projection.ShowImage(camera, projectorImageForGivenCamera)) + { // A Local Scope to handle the projected image lifetime + + var settings2D = new Zivid.NET.Settings2D + { + Acquisitions = { new Zivid.NET.Settings2D.Acquisition { + Aperture = 2.83, ExposureTime = Duration.FromMicroseconds(20000), Brightness = 0.0} } + }; + + Console.WriteLine("Capturing a 2D image with the projected image"); + using (var frame2D = projectedImageHandle.Capture(settings2D)) + { + var capturedImageFile = "CapturedImage.png"; + Console.WriteLine("Saving the captured image: {0}", capturedImageFile); + frame2D.ImageRGBA().Save(capturedImageFile); + } + + Console.WriteLine("Press enter to stop projecting..."); + Console.ReadLine(); + + } // projectedImageHandle now goes out of scope, thereby stopping the projection + + } + + Console.WriteLine("Done"); + } + catch (Exception ex) + { + Console.WriteLine("Error: " + ex.Message); + return 1; + } + return 0; + } + + static string GetProjectorImageFileForCamera(Zivid.NET.Camera camera) + { + var model = camera.Info.Model; + switch (model) + { + case Zivid.NET.CameraInfo.ModelOption.ZividTwo: + case Zivid.NET.CameraInfo.ModelOption.ZividTwoL100: + { + return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "/Zivid/ZividLogoZivid2ProjectorResolution.png"; + } + case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusM130: + case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusM60: + case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusL110: + { + return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "/Zivid/ZividLogoZivid2PlusProjectorResolution.png"; + } + default: + { + throw new System.InvalidOperationException("Unhandled enum value " + model.ToString()); + } + } + } +} diff --git a/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.csproj b/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.csproj new file mode 100644 index 0000000..b9192ff --- /dev/null +++ b/source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.csproj @@ -0,0 +1,88 @@ + + + + + Debug + AnyCPU + {79BE4F01-8935-49FD-BD8F-551E62FF03CA} + Exe + Properties + ReadAndProjectImage + ReadAndProjectImage + v4.5.2 + 512 + true + + + true + ..\..\..\..\..\build\$(Configuration)\$(Platform) + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + true + true + + + ..\..\..\..\..\build\$(Configuration)\$(Platform) + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + true + true + + + + + + + + + + + + $(ZIVID_INSTALL_FOLDER)\bin\ZividCoreNET.dll + + + $(ZIVID_INSTALL_FOLDER)\bin_debug\ZividCoreNET.dll + + + $(ZIVID_INSTALL_FOLDER)\bin\ZividVisualizationNET.dll + + + $(ZIVID_INSTALL_FOLDER)\bin_debug\ZividVisualizationNET.dll + + + + + + + + + + + + if $(ConfigurationName) == Debug GOTO Debug +if $(ConfigurationName) == Release GOTO Release +goto Error + +:Debug +xcopy "$(ZIVID_INSTALL_FOLDER)\bin_debug\*.dll" "$(TargetDir)" /Y +exit /B 0 + +:Release +xcopy "$(ZIVID_INSTALL_FOLDER)\bin\*.dll" "$(TargetDir)" /Y +exit /B 0 + +:Error +echo Unsupported config +exit /B 1 + + + \ No newline at end of file diff --git a/source/ZividNETSamples.sln b/source/ZividNETSamples.sln index 19c09e1..50eb9bf 100644 --- a/source/ZividNETSamples.sln +++ b/source/ZividNETSamples.sln @@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaptureVis3D", "Application EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectImageStartAndStop", "Applications\Basic\Visualization\ProjectImageStartAndStop\ProjectImageStartAndStop.csproj", "{629C1888-D739-48A8-AE10-AD8368EF9F8D}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadAndProjectImage", "Applications\Basic\Visualization\ReadAndProjectImage\ReadAndProjectImage.csproj", "{79BE4F01-8935-49FD-BD8F-551E62FF03CA}" +EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadIterateZDF", "Applications\Basic\FileFormats\ReadIterateZDF\ReadIterateZDF.csproj", "{C25D92EB-0C72-4A00-A8A1-7E459F1299A5}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZDF2PLY", "Applications\Basic\FileFormats\ZDF2PLY\ZDF2PLY.csproj", "{04599908-D437-435E-AE21-2DA7A91BF174}" @@ -147,6 +149,10 @@ Global {629C1888-D739-48A8-AE10-AD8368EF9F8D}.Debug|x64.Build.0 = Debug|x64 {629C1888-D739-48A8-AE10-AD8368EF9F8D}.Release|x64.ActiveCfg = Release|x64 {629C1888-D739-48A8-AE10-AD8368EF9F8D}.Release|x64.Build.0 = Release|x64 + {79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Debug|x64.ActiveCfg = Debug|x64 + {79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Debug|x64.Build.0 = Debug|x64 + {79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Release|x64.ActiveCfg = Release|x64 + {79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Release|x64.Build.0 = Release|x64 {C25D92EB-0C72-4A00-A8A1-7E459F1299A5}.Debug|x64.ActiveCfg = Debug|x64 {C25D92EB-0C72-4A00-A8A1-7E459F1299A5}.Debug|x64.Build.0 = Debug|x64 {C25D92EB-0C72-4A00-A8A1-7E459F1299A5}.Release|x64.ActiveCfg = Release|x64