-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from zivid/2023-12-19-update-csharp-samples
Samples: Add loading projector image with Zivid API
- Loading branch information
Showing
6 changed files
with
220 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
source/Applications/Basic/Visualization/ReadAndProjectImage/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
36 changes: 36 additions & 0 deletions
36
source/Applications/Basic/Visualization/ReadAndProjectImage/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")] |
82 changes: 82 additions & 0 deletions
82
source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
source/Applications/Basic/Visualization/ReadAndProjectImage/ReadAndProjectImage.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters