Skip to content

Commit d2aa6e6

Browse files
authored
Merge pull request #99 from zivid/2025-04-23-update-csharp-samples
Samples: Automatic updates to public repository
2 parents afc2790 + 2180f0b commit d2aa6e6

File tree

11 files changed

+320
-247
lines changed

11 files changed

+320
-247
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ from the camera can be used.
4545
camera.
4646
- [CaptureHDRCompleteSettings](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Camera/Basic/CaptureHDRCompleteSettings/CaptureHDRCompleteSettings.cs) - Capture point clouds, with color, from the Zivid camera
4747
with fully configured settings.
48-
- [CaptureWithSettingsFromYML](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs) - Capture images and point clouds, with or without color,
48+
- [CaptureWithSettingsFromYML](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs) - Capture images and point clouds, with and without color,
4949
from the Zivid camera with settings from YML file.
5050
- **Advanced**
5151
- [CaptureHalconViaGenICam](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Camera/Advanced/CaptureHalconViaGenICam/CaptureHalconViaGenICam.cs) - Capture and save a point cloud, with colors, using GenICam

source/Applications/Basic/Visualization/ProjectImageStartAndStop/ProjectImageStartAndStop.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,6 @@ Start the Image Projection and Stop it.
1212

1313
class Program
1414
{
15-
static Zivid.NET.ImageBGRA CreateProjectorImage(Zivid.NET.Resolution resolution, Zivid.NET.ColorBGRA color)
16-
{
17-
var pixelArray = new Zivid.NET.ColorBGRA[resolution.Height, resolution.Width];
18-
for (ulong y = 0; y < resolution.Height; y++)
19-
{
20-
for (ulong x = 0; x < resolution.Width; x++)
21-
{
22-
pixelArray[y, x] = color;
23-
}
24-
}
25-
var projectorImage = new Zivid.NET.ImageBGRA(pixelArray);
26-
return projectorImage;
27-
}
28-
2915
static int Main()
3016
{
3117
try
@@ -79,4 +65,18 @@ static int Main()
7965
}
8066
return 0;
8167
}
68+
69+
static Zivid.NET.ImageBGRA CreateProjectorImage(Zivid.NET.Resolution resolution, Zivid.NET.ColorBGRA color)
70+
{
71+
var pixelArray = new Zivid.NET.ColorBGRA[resolution.Height, resolution.Width];
72+
for (ulong y = 0; y < resolution.Height; y++)
73+
{
74+
for (ulong x = 0; x < resolution.Width; x++)
75+
{
76+
pixelArray[y, x] = color;
77+
}
78+
}
79+
var projectorImage = new Zivid.NET.ImageBGRA(pixelArray);
80+
return projectorImage;
81+
}
8282
}

source/Applications/PointCloudTutorial.md

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,16 @@ on compute device memory) and the capture and camera information.
5151

5252
### Capture
5353

54-
When you capture with Zivid, you get a frame in return.
54+
When you capture with Zivid, you get a frame in return. The point cloud
55+
is stored in the frame, and the frame is stored in the GPU memory. The
56+
capture can contain color or not, depending of the method that you call.
57+
For more information see this `table with different capture
58+
modes<capture-mode-table>`.
59+
60+
#### Capture with color
61+
62+
If you want to capture a point cloud with color, you can use the
63+
`Zivid::Camera::capture2D3D()` method.
5564

5665
([go to
5766
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/Capture/Capture.cs#L26))
@@ -60,6 +69,18 @@ source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera
6069
using (var frame = camera.Capture2D3D(settings))
6170
```
6271

72+
#### Capture without color
73+
74+
If you want to capture a point cloud without color, you can use the
75+
`Zivid::Camera::capture3D()` method.
76+
77+
([go to
78+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L86))
79+
80+
``` sourceCode cs
81+
using (var frame3D = camera.Capture3D(settings))
82+
```
83+
6384
Check
6485
[CaptureTutorial](https://github.com/zivid/zivid-csharp-samples/tree/master/source/Camera/Basic/CaptureTutorial.md)
6586
for detailed instructions on how to capture.
@@ -104,13 +125,13 @@ copying from GPU memory.
104125

105126
Note:
106127

107-
`Zivid.NET.Camera.Capture()` method returns at some moment in time after
108-
the camera completes capturing raw images. The handle from
109-
`Zivid.NET.Frame.PointCloud` is available instantly. However, the actual
110-
point cloud data becomes available only after the processing on the GPU
111-
is finished. Any calls to data-copy methods (section below) will block
112-
and wait for processing to finish before proceeding with the requested
113-
copy operation.
128+
`Zivid.NET.Camera.Capture2D3D()` and `Zivid.NET.Camera.Capture3D()`
129+
methods return at some moment in time after the camera completes
130+
capturing raw images. The handle from `Zivid.NET.Frame.PointCloud` is
131+
available instantly. However, the actual point cloud data becomes
132+
available only after the processing on the GPU is finished. Any calls to
133+
data-copy methods (section below) will block and wait for processing to
134+
finish before proceeding with the requested copy operation.
114135

115136
For detailed explanation, see [Point Cloud Capture
116137
Process](https://support.zivid.com/latest/academy/camera/point-cloud-capture-process.html).

source/Camera/Basic/CaptureTutorial.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ If we only want to capture 3D, the points cloud without color, we can do
395395
so via the `capture3D` API.
396396

397397
([go to
398-
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L71))
398+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L86))
399399

400400
``` sourceCode cs
401401
using (var frame3D = camera.Capture3D(settings))
@@ -407,7 +407,7 @@ If we only want to capture a 2D image, which is faster than 3D, we can
407407
do so via the `capture2D` API.
408408

409409
([go to
410-
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L28))
410+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L42))
411411

412412
``` sourceCode cs
413413
using (var frame2D = camera.Capture2D(settings))
@@ -464,62 +464,67 @@ using (var frame = new Zivid.NET.Frame(dataFile))
464464

465465
### Save 2D
466466

467-
We can get the 2D color image from `Frame2D`, which is part of the
468-
`Frame` object, obtained from `capture2D3D()`.
467+
From a `capture2D()` you get a `Frame2D`. There are two color spaces
468+
available for 2D images: linear RGB and sRGB. The `imageRGBA()` will
469+
return an image in the linear RGB color space. If you append `_SRGB` to
470+
the function name then the returned image will be in the sRGB color
471+
space
469472

470-
([go to source]())
473+
([go to
474+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L49))
471475

472476
``` sourceCode cs
473-
var image2D = frame.Frame2D.ImageBGRA_SRGB();
477+
var imageRGBA = frame2D.ImageRGBA();
478+
.. tab-item:: sRGB
474479
```
475480

476-
We can get 2D color image directly from the point cloud. This image will
477-
have the same resolution as the point cloud.
478-
479-
([go to source]())
481+
([go to
482+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L67))
480483

481484
``` sourceCode cs
482-
var pointCloud = frame.PointCloud;
483-
var image2DInPointCloudResolution = pointCloud.CopyImageRGBA_SRGB();
485+
var imageSRGB = frame2D.ImageRGBA_SRGB();
484486
```
485487

486-
2D captures also produce 2D color images in linear RGB and sRGB color
487-
space.
488+
Then, we can save the 2D image in linear RGB or sRGB color space.
488489

489490
([go to
490-
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/Capture/Capture.cs#L28))
491+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L50-L52))
491492

492493
``` sourceCode cs
493-
var imageRGBA = frame.Frame2D.ImageRGBA_SRGB();
494+
var imageFile = "ImageRGBA_linear.png";
495+
Console.WriteLine($"Saving 2D color image (Linear RGB) to file: {imageFile}");
496+
imageRGBA.Save(imageFile);
494497
.. tab-item:: sRGB
495498
```
496499

497500
([go to
498-
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L30))
501+
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L68-L70))
499502

500503
``` sourceCode cs
501-
var imageSRGB = frame2D.ImageSRGB();
504+
var imageFile = "ImageRGBA_sRGB.png";
505+
Console.WriteLine($"Saving 2D color image (sRGB color space) to file: {imageFile}");
506+
imageSRGB.Save(imageFile);
502507
```
503508

504-
Then, we can save the 2D image in linear RGB or sRGB color space.
509+
We can get 2D color image directly from the point cloud. This image will
510+
have the same resolution as the point cloud and it will be in the sRGB
511+
color space.
505512

506-
([go to
507-
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/Capture/Capture.cs#L29-L31))
513+
([go to source]())
508514

509515
``` sourceCode cs
510-
var imageFile = "ImageRGB.png";
511-
Console.WriteLine("Saving 2D color image (sRGB color space) to file: " + imageFile);
512-
imageRGBA.Save(imageFile);
513-
.. tab-item:: sRGB
516+
var pointCloud = frame.PointCloud;
517+
var image2DInPointCloudResolution = pointCloud.CopyImageRGBA_SRGB();
514518
```
515519

516-
([go to
517-
source](https://github.com/zivid/zivid-csharp-samples/tree/master//source/Camera/Basic/CaptureWithSettingsFromYML/CaptureWithSettingsFromYML.cs#L31-L33))
520+
We can get the 2D color image from `Frame2D`, which is part of the
521+
`Frame` object, obtained from `capture2D3D()`. This image will have the
522+
resolution given by the 2D settings inside the 2D3D settings.
523+
524+
([go to source]())
518525

519526
``` sourceCode cs
520-
var imageFile = "ImageSRGB.png";
521-
Console.WriteLine("Saving 2D color image (sRGB color space) to file: " + imageFile);
522-
imageSRGB.Save(imageFile);
527+
var image2D = frame.Frame2D.ImageBGRA_SRGB();
523528
```
524529

525530
## Multithreading
Lines changed: 86 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,85 @@
11
/*
2-
Capture images and point clouds, with or without color, from the Zivid camera with settings from YML file.
2+
Capture images and point clouds, with and without color, from the Zivid camera with settings from YML file.
3+
4+
Choose whether to get the image in the linear RGB or the sRGB color space.
35
46
The YML files for this sample can be found under the main Zivid sample instructions.
57
*/
68

79
using System;
8-
using System.Collections.Generic;
910
using Zivid.NET;
11+
using System.Collections.Generic;
1012

1113
class Program
1214
{
13-
static int Main()
15+
static int Main(string[] args)
1416
{
1517
try
1618
{
17-
var zivid = new Zivid.NET.Application();
19+
if (Array.Exists(args, arg => arg == "-h" || arg == "--help"))
20+
{
21+
ShowHelp();
22+
return 0;
23+
}
24+
25+
var userOptions = ParseOptions(args);
1826

27+
var zivid = new Zivid.NET.Application();
1928
Console.WriteLine("Connecting to camera");
2029
var camera = zivid.ConnectCamera();
2130

2231
Console.WriteLine("Loading settings from file");
23-
var settingsFile = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
24-
+ "/Zivid/Settings/" + SettingsFolder(camera) + "/Settings01.yml";
32+
if (string.IsNullOrEmpty(userOptions.SettingsPath))
33+
{
34+
userOptions.SettingsPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
35+
+ "/Zivid/Settings/" + SettingsFolder(camera) + "/Settings01.yml";
36+
}
37+
38+
string settingsFile = userOptions.SettingsPath;
2539
var settings = new Zivid.NET.Settings(settingsFile);
2640

2741
Console.WriteLine("Capturing 2D frame");
2842
using (var frame2D = camera.Capture2D(settings))
2943
{
30-
var imageSRGB = frame2D.ImageSRGB();
31-
var imageFile = "ImageSRGB.png";
32-
Console.WriteLine("Saving 2D color image (sRGB color space) to file: " + imageFile);
33-
imageSRGB.Save(imageFile);
34-
35-
// More information about linear RGB and sRGB color spaces is available at:
36-
// https://support.zivid.com/en/latest/reference-articles/color-spaces-and-output-formats.html#color-spaces
37-
// To get linear RGB image, use the following line instead:
38-
// var imageLinearRGB = frame2D.ImageRGBA();
39-
4044
var pixelRow = 100;
4145
var pixelCol = 50;
4246

43-
Console.WriteLine("Extracting 2D pixel array");
44-
var pixelArraySRGB = imageSRGB.ToArray();
45-
Console.WriteLine("Height: {0}, Width: {1}", pixelArraySRGB.GetLength(0), pixelArraySRGB.GetLength(1));
46-
Console.WriteLine("Color at pixel ({0},{1}): R:{2} G:{3} B:{4} A:{5}",
47-
pixelRow,
48-
pixelCol,
49-
pixelArraySRGB[pixelRow, pixelCol].r,
50-
pixelArraySRGB[pixelRow, pixelCol].g,
51-
pixelArraySRGB[pixelRow, pixelCol].b,
52-
pixelArraySRGB[pixelRow, pixelCol].a);
53-
54-
Console.WriteLine("Extracting 3D array of bytes");
55-
var nativeArray = imageSRGB.ToByteArray();
56-
Console.WriteLine("Height: {0}, Width: {1}, Channels: {2}",
57-
nativeArray.GetLength(0),
58-
nativeArray.GetLength(1),
59-
nativeArray.GetLength(2));
60-
Console.WriteLine("Color at pixel ({0},{1}): R:{2} G:{3} B:{4} A:{5}",
61-
pixelRow,
62-
pixelCol,
63-
nativeArray[pixelRow, pixelCol, 0],
64-
nativeArray[pixelRow, pixelCol, 1],
65-
nativeArray[pixelRow, pixelCol, 2],
66-
nativeArray[pixelRow, pixelCol, 3]);
67-
47+
if (userOptions.LinearRgb)
48+
{
49+
var imageRGBA = frame2D.ImageRGBA();
50+
var imageFile = "ImageRGBA_linear.png";
51+
Console.WriteLine($"Saving 2D color image (Linear RGB) to file: {imageFile}");
52+
imageRGBA.Save(imageFile);
53+
54+
Console.WriteLine("Extracting 2D pixel array");
55+
var pixelArrayRGBA = imageRGBA.ToArray();
56+
Console.WriteLine("Height: {0}, Width: {1}", pixelArrayRGBA.GetLength(0), pixelArrayRGBA.GetLength(1));
57+
Console.WriteLine("Color at pixel ({0},{1}): R:{2} G:{3} B:{4} A:{5}",
58+
pixelRow,
59+
pixelCol,
60+
pixelArrayRGBA[pixelRow, pixelCol].r,
61+
pixelArrayRGBA[pixelRow, pixelCol].g,
62+
pixelArrayRGBA[pixelRow, pixelCol].b,
63+
pixelArrayRGBA[pixelRow, pixelCol].a);
64+
}
65+
else
66+
{
67+
var imageSRGB = frame2D.ImageRGBA_SRGB();
68+
var imageFile = "ImageRGBA_sRGB.png";
69+
Console.WriteLine($"Saving 2D color image (sRGB color space) to file: {imageFile}");
70+
imageSRGB.Save(imageFile);
71+
72+
Console.WriteLine("Extracting 2D pixel array");
73+
var pixelArraySRGB = imageSRGB.ToArray();
74+
Console.WriteLine("Height: {0}, Width: {1}", pixelArraySRGB.GetLength(0), pixelArraySRGB.GetLength(1));
75+
Console.WriteLine("Color at pixel ({0},{1}): R:{2} G:{3} B:{4} A:{5}",
76+
pixelRow,
77+
pixelCol,
78+
pixelArraySRGB[pixelRow, pixelCol].r,
79+
pixelArraySRGB[pixelRow, pixelCol].g,
80+
pixelArraySRGB[pixelRow, pixelCol].b,
81+
pixelArraySRGB[pixelRow, pixelCol].a);
82+
}
6883
}
6984

7085
Console.WriteLine("Capturing 3D frame");
@@ -99,6 +114,26 @@ static int Main()
99114
return 0;
100115
}
101116

117+
static (string SettingsPath, bool LinearRgb) ParseOptions(string[] args)
118+
{
119+
string settingsPath = "";
120+
bool linearRgb = false;
121+
122+
foreach (var arg in args)
123+
{
124+
if (arg.StartsWith("--settings-path="))
125+
{
126+
settingsPath = arg.Substring("--settings-path=".Length);
127+
}
128+
else if (arg.Equals("--linear-rgb"))
129+
{
130+
linearRgb = true;
131+
}
132+
}
133+
134+
return (settingsPath, linearRgb);
135+
}
136+
102137
static string SettingsFolder(Zivid.NET.Camera camera)
103138
{
104139
var model = camera.Info.Model;
@@ -112,7 +147,16 @@ static string SettingsFolder(Zivid.NET.Camera camera)
112147
case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusMR130: return "zivid2Plus/R";
113148
case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusMR60: return "zivid2Plus/R";
114149
case Zivid.NET.CameraInfo.ModelOption.Zivid2PlusLR110: return "zivid2Plus/R";
115-
default: throw new System.InvalidOperationException("Unhandled enum value " + model.ToString());
150+
default: throw new InvalidOperationException("Unhandled enum value " + model.ToString());
116151
}
117152
}
153+
154+
static void ShowHelp()
155+
{
156+
Console.WriteLine("Usage: CaptureWithSettingsFromYML.exe [options]");
157+
Console.WriteLine("Options:");
158+
Console.WriteLine(" --settings-path=<path> Path to the camera settings YML file (default: based on camera model)");
159+
Console.WriteLine(" --linear-rgb Use linear RGB instead of sRGB");
160+
Console.WriteLine(" -h, --help Show this help message");
161+
}
118162
}

0 commit comments

Comments
 (0)