Skip to content

Commit 0e99e17

Browse files
committed
returns R16 depth texture
1 parent 4ed5427 commit 0e99e17

File tree

4 files changed

+108
-104
lines changed

4 files changed

+108
-104
lines changed

src/Acquisition.cs

+5-13
Original file line numberDiff line numberDiff line change
@@ -174,25 +174,17 @@ private static byte[] ConvertDepthToRGBData(byte[] depthData)
174174
var stride = colorFrame.GetDataSize();
175175

176176
var format = colorFrame.GetFormat();
177+
178+
var memoryOwner = new UnmanagedMemoryManager<R16Pixel>(colorFrame.GetDataPtr(), (int)stride);
177179

178-
byte[] data = new byte[colorFrame.GetDataSize()];
179-
colorFrame.CopyData(ref data);
180-
data = ConvertDepthToRGBData(data);
181-
182-
GCHandle pinnedArray = GCHandle.Alloc(data, GCHandleType.Pinned);
183-
IntPtr pointer = pinnedArray.AddrOfPinnedObject();
184-
185-
var memoryOwner = new UnmanagedMemoryManager<BgraPixel>(pointer, (int)colorFrame.GetDataSize() * 2);
186-
187-
var pitch = width * sizeof(BgraPixel);
180+
var piiiitch = width * sizeof(R16Pixel);
188181
var memory = memoryOwner.Memory.AsMemory2D(0, (int)height, (int)width, 0);
189-
var videoFrame = new VideoFrame<BgraPixel>(memory);
190-
return ResourceProvider.Return(videoFrame, (memoryOwner, frames, pinnedArray),
182+
var videoFrame = new VideoFrame<R16Pixel>(memory);
183+
return ResourceProvider.Return(videoFrame, (memoryOwner, frames),
191184
static x =>
192185
{
193186
((IDisposable)x.memoryOwner).Dispose();
194187
x.frames.Dispose();
195-
x.pinnedArray.Free();
196188
});
197189
}
198190
}

src/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"vvvv gamma 5.3": {
44
"commandName": "Executable",
5-
"executablePath": "C:\\Program Files\\vvvv\\vvvv_gamma_6.7-0310-g6266ca42c1-win-x64\\vvvv.exe",
5+
"executablePath": "C:\\Program Files\\vvvv\\vvvv_gamma_7.0-0016-ga5bfd21650-win-x64\\vvvv.exe",
66
"commandLineArgs": "--package-repositories \"C:\\Users\\alex\\Documents\\libs\" --editable-packages VL.Devices.Orbbec -o \"$(RepoRootPath)\\help\\Explanation Overview.vl\""
77
}
88
}

src/R16Pixel.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#nullable enable
2+
using VL.Lib.Basics.Imaging;
3+
using VL.Lib.Basics.Video;
4+
5+
namespace VL.Devices.Orbbec
6+
{
7+
public record struct R16Pixel(ushort R) : IPixel
8+
{
9+
public PixelFormat PixelFormat => PixelFormat.R16;
10+
}
11+
}
12+
#nullable restore

src/VideoIn.cs

+90-90
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
using Microsoft.Extensions.Logging;
2-
using System.ComponentModel;
3-
using VL.Lib.Basics.Video;
4-
using VL.Model;
5-
using VL.Devices.Orbbec.Advanced;
6-
using System.Reactive.Subjects;
7-
using System.Reactive.Linq;
8-
using Orbbec;
9-
using System.Net;
10-
11-
namespace VL.Devices.Orbbec
12-
{
13-
[ProcessNode]
14-
public class VideoIn : IVideoSource2, IDisposable
15-
{
16-
private readonly ILogger _logger;
17-
private readonly BehaviorSubject<Acquisition?> _aquicitionStarted = new BehaviorSubject<Acquisition?>(null);
18-
19-
private int _changedTicket;
20-
private Advanced.DeviceInfo? _device;
21-
private Int2 _resolution;
22-
private int _fps;
23-
//private IConfiguration? _configuration;
24-
private bool _enabled;
25-
private string _IP;
26-
27-
28-
internal string Info { get; set; } = "";
29-
internal Spread<PropertyInfo> PropertyInfos { get; set; } = new SpreadBuilder<PropertyInfo>().ToSpread();
30-
31-
public VideoIn([Pin(Visibility = PinVisibility.Hidden)] NodeContext nodeContext)
32-
{
33-
_logger = nodeContext.GetLogger();
34-
}
35-
36-
[return: Pin(Name = "Output")]
37-
public VideoIn? Update(
1+
using Microsoft.Extensions.Logging;
2+
using System.ComponentModel;
3+
using VL.Lib.Basics.Video;
4+
using VL.Model;
5+
using VL.Devices.Orbbec.Advanced;
6+
using System.Reactive.Subjects;
7+
using System.Reactive.Linq;
8+
using Orbbec;
9+
using System.Net;
10+
11+
namespace VL.Devices.Orbbec
12+
{
13+
[ProcessNode]
14+
public class VideoIn : IVideoSource2, IDisposable
15+
{
16+
private readonly ILogger _logger;
17+
private readonly BehaviorSubject<Acquisition?> _aquicitionStarted = new BehaviorSubject<Acquisition?>(null);
18+
19+
private int _changedTicket;
20+
private Advanced.DeviceInfo? _device;
21+
private Int2 _resolution;
22+
private int _fps;
23+
//private IConfiguration? _configuration;
24+
private bool _enabled;
25+
private string _IP;
26+
27+
28+
internal string Info { get; set; } = "";
29+
internal Spread<PropertyInfo> PropertyInfos { get; set; } = new SpreadBuilder<PropertyInfo>().ToSpread();
30+
31+
public VideoIn([Pin(Visibility = PinVisibility.Hidden)] NodeContext nodeContext)
32+
{
33+
_logger = nodeContext.GetLogger();
34+
}
35+
36+
[return: Pin(Name = "Output")]
37+
public VideoIn? Update(
3838
OrbbecDevice? device,
39-
[DefaultValue("640, 576")] Int2 resolution,
40-
[DefaultValue("30")] int FPS,
41-
//IConfiguration configuration,
42-
[DefaultValue("true")] bool enabled,
43-
out string Info)
44-
{
45-
// By comparing the device info we can be sure that on re-connect of the device we see the change
46-
if (!Equals(device?.Tag, _device) || enabled != _enabled || resolution != _resolution || FPS != _fps)// || configuration != _configuration)
47-
{
48-
_device = device?.Tag as Advanced.DeviceInfo;
49-
_resolution = resolution;
50-
_fps = FPS;
51-
//_configuration = configuration;
52-
_enabled = enabled;
53-
_changedTicket++;
54-
}
55-
56-
Info = this.Info;
57-
58-
if (!enabled) return null;
59-
60-
return this;
61-
}
62-
63-
internal IObservable<Acquisition> AcquisitionStarted => _aquicitionStarted.Where(a => a != null && !a.IsDisposed)!;
64-
65-
IVideoPlayer? IVideoSource2.Start(VideoPlaybackContext ctx)
66-
{
67-
var device = _device;
68-
if (device is null)
69-
return null;
70-
71-
try
72-
{
73-
var result = Acquisition.Start(this, device, _logger, _resolution, _fps);//, _configuration
74-
//_aquicitionStarted.OnNext(result);
75-
return result;
76-
}
77-
catch (Exception e)
78-
{
79-
_logger.LogError(e, "Failed to start image acquisition");
80-
return null;
81-
}
82-
}
83-
84-
int IVideoSource2.ChangedTicket => _changedTicket;
85-
86-
public void Dispose()
87-
{
88-
//_ic4LibSubscription.Dispose();
89-
}
90-
}
91-
}
39+
[DefaultValue("640, 576")] Int2 resolution,
40+
[DefaultValue("30")] int FPS,
41+
//IConfiguration configuration,
42+
[DefaultValue("true")] bool enabled,
43+
out string Info)
44+
{
45+
// By comparing the device info we can be sure that on re-connect of the device we see the change
46+
if (!Equals(device?.Tag, _device) || enabled != _enabled || resolution != _resolution || FPS != _fps)// || configuration != _configuration)
47+
{
48+
_device = device?.Tag as Advanced.DeviceInfo;
49+
_resolution = resolution;
50+
_fps = FPS;
51+
//_configuration = configuration;
52+
_enabled = enabled;
53+
_changedTicket++;
54+
}
55+
56+
Info = this.Info;
57+
58+
if (!enabled) return null;
59+
60+
return this;
61+
}
62+
63+
internal IObservable<Acquisition> AcquisitionStarted => _aquicitionStarted.Where(a => a != null && !a.IsDisposed)!;
64+
65+
IVideoPlayer? IVideoSource2.Start(VideoPlaybackContext ctx)
66+
{
67+
var device = _device;
68+
if (device is null)
69+
return null;
70+
71+
try
72+
{
73+
var result = Acquisition.Start(this, device, _logger, _resolution, _fps);//, _configuration
74+
//_aquicitionStarted.OnNext(result);
75+
return result;
76+
}
77+
catch (Exception e)
78+
{
79+
_logger.LogError(e, "Failed to start image acquisition");
80+
return null;
81+
}
82+
}
83+
84+
int IVideoSource2.ChangedTicket => _changedTicket;
85+
86+
public void Dispose()
87+
{
88+
//_ic4LibSubscription.Dispose();
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)