Skip to content

Commit fa42e08

Browse files
authored
Merge pull request #80 from zivid/2023-12-19-update-csharp-samples
Samples: Add loading projector image with Zivid API
2 parents 4c1bcf0 + 4d9111c commit fa42e08

File tree

6 files changed

+220
-0
lines changed

6 files changed

+220
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ from the camera can be used.
8080
- [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
8181
camera, and visualize them.
8282
- [ProjectImageStartAndStop](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Applications/Basic/Visualization/ProjectImageStartAndStop/ProjectImageStartAndStop.cs) - Start the Image Projection and Stop it.
83+
- [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
84+
camera projector.
8385
- **FileFormats**
8486
- [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
8587
it, and extract individual points.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
5+
</startup>
6+
</configuration>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ReadAndProjectImage")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("ReadAndProjectImage")]
13+
[assembly: AssemblyCopyright("Copyright 2015-2023 (C) Zivid AS")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("79BE4F01-8935-49FD-BD8F-551E62FF03CA")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
Read a 2D image from file and project it using the camera projector.
3+
4+
The image for this sample can be found under the main instructions for Zivid samples.
5+
*/
6+
7+
using System;
8+
using Duration = Zivid.NET.Duration;
9+
10+
class Program
11+
{
12+
static int Main()
13+
{
14+
try
15+
{
16+
var zivid = new Zivid.NET.Application();
17+
18+
Console.WriteLine("Connecting to camera");
19+
using (var camera = zivid.ConnectCamera())
20+
{
21+
string projectorImageFileForGivenCamera = GetProjectorImageFileForCamera(camera);
22+
23+
Console.WriteLine("Reading 2D image (of resolution matching the Zivid camera projector resolution) from file: " + projectorImageFileForGivenCamera);
24+
var projectorImageForGivenCamera = new Zivid.NET.ImageBGRA(projectorImageFileForGivenCamera);
25+
26+
using (var projectedImageHandle = Zivid.NET.Experimental.Projection.Projection.ShowImage(camera, projectorImageForGivenCamera))
27+
{ // A Local Scope to handle the projected image lifetime
28+
29+
var settings2D = new Zivid.NET.Settings2D
30+
{
31+
Acquisitions = { new Zivid.NET.Settings2D.Acquisition {
32+
Aperture = 2.83, ExposureTime = Duration.FromMicroseconds(20000), Brightness = 0.0} }
33+
};
34+
35+
Console.WriteLine("Capturing a 2D image with the projected image");
36+
using (var frame2D = projectedImageHandle.Capture(settings2D))
37+
{
38+
var capturedImageFile = "CapturedImage.png";
39+
Console.WriteLine("Saving the captured image: {0}", capturedImageFile);
40+
frame2D.ImageRGBA().Save(capturedImageFile);
41+
}
42+
43+
Console.WriteLine("Press enter to stop projecting...");
44+
Console.ReadLine();
45+
46+
} // projectedImageHandle now goes out of scope, thereby stopping the projection
47+
48+
}
49+
50+
Console.WriteLine("Done");
51+
}
52+
catch (Exception ex)
53+
{
54+
Console.WriteLine("Error: " + ex.Message);
55+
return 1;
56+
}
57+
return 0;
58+
}
59+
60+
static string GetProjectorImageFileForCamera(Zivid.NET.Camera camera)
61+
{
62+
var model = camera.Info.Model;
63+
switch (model)
64+
{
65+
case Zivid.NET.CameraInfo.ModelOption.ZividTwo:
66+
case Zivid.NET.CameraInfo.ModelOption.ZividTwoL100:
67+
{
68+
return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "/Zivid/ZividLogoZivid2ProjectorResolution.png";
69+
}
70+
case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusM130:
71+
case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusM60:
72+
case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusL110:
73+
{
74+
return Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "/Zivid/ZividLogoZivid2PlusProjectorResolution.png";
75+
}
76+
default:
77+
{
78+
throw new System.InvalidOperationException("Unhandled enum value " + model.ToString());
79+
}
80+
}
81+
}
82+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{79BE4F01-8935-49FD-BD8F-551E62FF03CA}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>ReadAndProjectImage</RootNamespace>
11+
<AssemblyName>ReadAndProjectImage</AssemblyName>
12+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
17+
<DebugSymbols>true</DebugSymbols>
18+
<OutputPath>..\..\..\..\..\build\$(Configuration)\$(Platform)</OutputPath>
19+
<DefineConstants>DEBUG;TRACE</DefineConstants>
20+
<DebugType>full</DebugType>
21+
<PlatformTarget>x64</PlatformTarget>
22+
<ErrorReport>prompt</ErrorReport>
23+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
24+
<Prefer32Bit>true</Prefer32Bit>
25+
<RunCodeAnalysis>true</RunCodeAnalysis>
26+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
27+
</PropertyGroup>
28+
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
29+
<OutputPath>..\..\..\..\..\build\$(Configuration)\$(Platform)</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<Optimize>true</Optimize>
32+
<DebugType>pdbonly</DebugType>
33+
<PlatformTarget>x64</PlatformTarget>
34+
<ErrorReport>prompt</ErrorReport>
35+
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
36+
<Prefer32Bit>true</Prefer32Bit>
37+
<RunCodeAnalysis>true</RunCodeAnalysis>
38+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
39+
</PropertyGroup>
40+
<ItemGroup>
41+
<Reference Include="System" />
42+
<Reference Include="System.Core" />
43+
<Reference Include="System.Xml.Linq" />
44+
<Reference Include="System.Data.DataSetExtensions" />
45+
<Reference Include="Microsoft.CSharp" />
46+
<Reference Include="System.Data" />
47+
<Reference Include="System.Net.Http" />
48+
<Reference Include="System.Xml" />
49+
<Reference Include="ZividCoreNET" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
50+
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin\ZividCoreNET.dll</HintPath>
51+
</Reference>
52+
<Reference Include="ZividCoreNET" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
53+
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin_debug\ZividCoreNET.dll</HintPath>
54+
</Reference>
55+
<Reference Include="ZividVisualizationNET" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
56+
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin\ZividVisualizationNET.dll</HintPath>
57+
</Reference>
58+
<Reference Include="ZividVisualizationNET" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
59+
<HintPath>$(ZIVID_INSTALL_FOLDER)\bin_debug\ZividVisualizationNET.dll</HintPath>
60+
</Reference>
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Compile Include="ReadAndProjectImage.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<None Include="App.config" />
68+
</ItemGroup>
69+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
70+
<PropertyGroup>
71+
<PostBuildEvent>if $(ConfigurationName) == Debug GOTO Debug
72+
if $(ConfigurationName) == Release GOTO Release
73+
goto Error
74+
75+
:Debug
76+
xcopy "$(ZIVID_INSTALL_FOLDER)\bin_debug\*.dll" "$(TargetDir)" /Y
77+
exit /B 0
78+
79+
:Release
80+
xcopy "$(ZIVID_INSTALL_FOLDER)\bin\*.dll" "$(TargetDir)" /Y
81+
exit /B 0
82+
83+
:Error
84+
echo Unsupported config
85+
exit /B 1
86+
</PostBuildEvent>
87+
</PropertyGroup>
88+
</Project>

source/ZividNETSamples.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CaptureVis3D", "Application
4343
EndProject
4444
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectImageStartAndStop", "Applications\Basic\Visualization\ProjectImageStartAndStop\ProjectImageStartAndStop.csproj", "{629C1888-D739-48A8-AE10-AD8368EF9F8D}"
4545
EndProject
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadAndProjectImage", "Applications\Basic\Visualization\ReadAndProjectImage\ReadAndProjectImage.csproj", "{79BE4F01-8935-49FD-BD8F-551E62FF03CA}"
47+
EndProject
4648
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadIterateZDF", "Applications\Basic\FileFormats\ReadIterateZDF\ReadIterateZDF.csproj", "{C25D92EB-0C72-4A00-A8A1-7E459F1299A5}"
4749
EndProject
4850
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZDF2PLY", "Applications\Basic\FileFormats\ZDF2PLY\ZDF2PLY.csproj", "{04599908-D437-435E-AE21-2DA7A91BF174}"
@@ -147,6 +149,10 @@ Global
147149
{629C1888-D739-48A8-AE10-AD8368EF9F8D}.Debug|x64.Build.0 = Debug|x64
148150
{629C1888-D739-48A8-AE10-AD8368EF9F8D}.Release|x64.ActiveCfg = Release|x64
149151
{629C1888-D739-48A8-AE10-AD8368EF9F8D}.Release|x64.Build.0 = Release|x64
152+
{79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Debug|x64.ActiveCfg = Debug|x64
153+
{79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Debug|x64.Build.0 = Debug|x64
154+
{79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Release|x64.ActiveCfg = Release|x64
155+
{79BE4F01-8935-49FD-BD8F-551E62FF03CA}.Release|x64.Build.0 = Release|x64
150156
{C25D92EB-0C72-4A00-A8A1-7E459F1299A5}.Debug|x64.ActiveCfg = Debug|x64
151157
{C25D92EB-0C72-4A00-A8A1-7E459F1299A5}.Debug|x64.Build.0 = Debug|x64
152158
{C25D92EB-0C72-4A00-A8A1-7E459F1299A5}.Release|x64.ActiveCfg = Release|x64

0 commit comments

Comments
 (0)