IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
CaptureInformation.cs
Go to the documentation of this file.
3
5
6internal static class CaptureInformation
7{
8 public static Metadata ToMetadata(Types.peak_icv_capture_information captureInfo)
9 {
10 var metadata = new Metadata();
11 MergeWithMetadata(captureInfo, metadata);
12 return metadata;
13 }
14
15 public static void MergeWithMetadata(Types.peak_icv_capture_information captureInfo, Metadata metadata)
16 {
17 metadata.SetValueByKey(MetadataKeys.DeviceTimestamp, captureInfo.relative_timestamp);
18 metadata.SetValueByKey(MetadataKeys.BinningHorizontal, captureInfo.binning_factor.x);
19 metadata.SetValueByKey(MetadataKeys.BinningVertical, captureInfo.binning_factor.y);
21 new PointU(captureInfo.region_of_interest.x, captureInfo.region_of_interest.y),
22 new Size(captureInfo.region_of_interest.width, captureInfo.region_of_interest.height)));
23 metadata.SetValueByKey(MetadataKeys.DeviceExposureTime, captureInfo.exposure_time);
24 metadata.SetValueByKey(MetadataKeys.DeviceExposureTimeSequence, new List<double>(captureInfo
25 .exposure_time_sequence));
26 metadata.SetValueByKey(MetadataKeys.DeviceGain, captureInfo.gain);
27 metadata.SetValueByKey(MetadataKeys.DeviceGainSequence, new List<double>(captureInfo.gain_sequence));
28 }
29
30 public static Types.peak_icv_capture_information FromMetadata(Metadata metadata, Size imageSize)
31 {
32 if (!metadata.HasEntryByKey(MetadataKeys.Roi))
33 {
34 metadata.SetValueByKey(MetadataKeys.Roi, new RectangleU(new PointU(0, 0), imageSize));
35 }
36
37 return FromMetadata(metadata);
38 }
39
40 public static Types.peak_icv_capture_information FromMetadata(Metadata metadata)
41 {
42 var captureInfo = new Types.peak_icv_capture_information();
43 captureInfo.binning_factor.x = 1;
44 captureInfo.binning_factor.y = 1;
45 captureInfo.relative_timestamp = 0;
46
47 if (metadata.TryGetValueByKey(MetadataKeys.BinningHorizontal, out var binningHorizontal))
48 {
49 captureInfo.binning_factor.x = binningHorizontal;
50 }
51
52 if (metadata.TryGetValueByKey(MetadataKeys.BinningVertical, out var binningVertical))
53 {
54 captureInfo.binning_factor.y = binningVertical;
55 }
56
57 if (metadata.TryGetValueByKey(MetadataKeys.DeviceTimestamp, out var timestamp))
58 {
59 captureInfo.relative_timestamp = timestamp;
60 }
61
62 if (metadata.TryGetValueByKey(MetadataKeys.Roi, out RectangleU? roi) && roi != null)
63 {
64 captureInfo.region_of_interest.x = roi.X;
65 captureInfo.region_of_interest.y = roi.Y;
66 captureInfo.region_of_interest.width = roi.Width;
67 captureInfo.region_of_interest.height = roi.Height;
68 }
69 else
70 {
71 captureInfo.region_of_interest.x = 0;
72 captureInfo.region_of_interest.y = 0;
73 captureInfo.region_of_interest.width = 0;
74 captureInfo.region_of_interest.height = 0;
75 }
76
77 if (metadata.TryGetValueByKey(MetadataKeys.DeviceExposureTime, out var exposureTime))
78 {
79 captureInfo.exposure_time = exposureTime;
80 }
81 else
82 {
83 captureInfo.exposure_time = 0;
84 }
85
86 if (metadata.TryGetValueByKey(MetadataKeys.DeviceExposureTimeSequence, out List<double>? exposureTimeSequence))
87 {
88 if (exposureTimeSequence != null && exposureTimeSequence.Count > 4)
89 {
90 throw new NotSupportedException(
91 "Exposure time sequence has to be smaller than or equal to 4.");
92 }
93
94 var paddedExposureTimeSequence = new double[4];
95 exposureTimeSequence?.CopyTo(paddedExposureTimeSequence, 0);
96
97 captureInfo.exposure_time_sequence = paddedExposureTimeSequence;
98 }
99 else
100 {
101 captureInfo.exposure_time_sequence = new double[4];
102 }
103
104 if (metadata.TryGetValueByKey(MetadataKeys.DeviceGain, out var gain))
105 {
106 captureInfo.gain = gain;
107 }
108 else
109 {
110 captureInfo.gain = 0;
111 }
112
113 if (metadata.TryGetValueByKey(MetadataKeys.DeviceGainSequence, out List<double>? gainSequence))
114 {
115 if (gainSequence != null && gainSequence.Count > 4)
116 {
117 throw new NotSupportedException(
118 "Gain sequence has to be smaller than or equal to 4.");
119 }
120
121 var paddedGainSequence = new double[4];
122 gainSequence?.CopyTo(paddedGainSequence, 0);
123
124 captureInfo.gain_sequence = paddedGainSequence;
125 }
126 else
127 {
128 captureInfo.gain_sequence = new double[4];
129 }
130
131 return captureInfo;
132 }
133}
Represents a 2D point with unsigned integer coordinates.
Definition Point.cs:154
Represents a rectangle with unsigned integer coordinates and dimensions.
Definition Rectangle.cs:213
Represents a size with integer width and height values.
Definition Size.cs:107
Strongly typed container for image acquisition metadata.
Definition Metadata.cs:233
bool TryGetValueByKey(MetadataKey key, out object? value)
Attempts to retrieve a value associated with a strongly typed metadata key.
Definition Metadata.cs:308
void SetValueByKey(MetadataKey key, object value)
Stores a value associated with a strongly typed metadata key.
Definition Metadata.cs:369
bool HasEntryByKey(MetadataKey key)
Determines whether a value exists for the specified strongly typed key.
Definition Metadata.cs:407
Provides a centralized registry of predefined MetadataKey instances.
Definition Metadata.cs:84
static readonly MetadataKeyT< double > DeviceExposureTime
Device exposure time the image was captured with.
Definition Metadata.cs:159
static readonly MetadataKeyT< List< double > > DeviceExposureTimeSequence
Device exposure time sequence the image was captured with.
Definition Metadata.cs:193
static readonly MetadataKeyT< RectangleU > Roi
Region of interest applied to the image.
Definition Metadata.cs:148
static readonly MetadataKeyT< uint > BinningVertical
Vertical pixel binning factor.
Definition Metadata.cs:135
static readonly MetadataKeyT< ulong > DeviceTimestamp
Device-provided image acquisition timestamp in nanoseconds.
Definition Metadata.cs:98
static readonly MetadataKeyT< double > DeviceGain
Device gain the image was captured with.
Definition Metadata.cs:201
static readonly MetadataKeyT< uint > BinningHorizontal
Horizontal pixel binning factor.
Definition Metadata.cs:124
static readonly MetadataKeyT< List< double > > DeviceGainSequence
Device gain sequence the image was captured with.
Definition Metadata.cs:215