Skip to content

Commit

Permalink
Merge pull request #80 from zivid/2023-12-19-update-csharp-samples
Browse files Browse the repository at this point in the history
Samples: Add loading projector image with Zivid API
  • Loading branch information
SatjaSivcev committed Dec 20, 2023
2 parents 4c1bcf0 + 4d9111c commit fa42e08
Show file tree
Hide file tree
Showing 6 changed files with 220 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -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")]
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{79BE4F01-8935-49FD-BD8F-551E62FF03CA}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ReadAndProjectImage</RootNamespace>
<AssemblyName>ReadAndProjectImage</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\..\..\..\..\build\$(Configuration)\$(Platform)</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<RunCodeAnalysis>true</RunCodeAnalysis>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\..\..\..\..\build\$(Configuration)\$(Platform)</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<RunCodeAnalysis>true</RunCodeAnalysis>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="ZividCoreNET" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin\ZividCoreNET.dll</HintPath>
</Reference>
<Reference Include="ZividCoreNET" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin_debug\ZividCoreNET.dll</HintPath>
</Reference>
<Reference Include="ZividVisualizationNET" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin\ZividVisualizationNET.dll</HintPath>
</Reference>
<Reference Include="ZividVisualizationNET" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin_debug\ZividVisualizationNET.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ReadAndProjectImage.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>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
</PostBuildEvent>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions source/ZividNETSamples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fa42e08

Please sign in to comment.