From 6a65da799ef0798cf85c2db6429c294823b2e8f8 Mon Sep 17 00:00:00 2001 From: "yuhang.li@cadgit.com" Date: Wed, 23 May 2018 14:09:14 +0800 Subject: [PATCH] =?UTF-8?q?socket=20=E5=90=91ispy=E5=8F=91=E9=80=81?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 321 ++++++- .../.nuget/Intel.RealSense.targets | 16 + Intel.RealSense/Context.cs | 96 +++ Intel.RealSense/Device.cs | 211 +++++ Intel.RealSense/Frame.cs | 324 +++++++ Intel.RealSense/FrameQueue.cs | 102 +++ Intel.RealSense/FrameSet.cs | 185 ++++ Intel.RealSense/Helpers.cs | 131 +++ Intel.RealSense/Intel.RealSense.2015.csproj | 153 ++++ Intel.RealSense/Intel.RealSense.csproj | 97 +++ Intel.RealSense/NativeMethods.cs | 795 ++++++++++++++++++ Intel.RealSense/Pipeline.cs | 321 +++++++ Intel.RealSense/Processing.cs | 336 ++++++++ Intel.RealSense/Properties/AssemblyInfo.cs | 36 + Intel.RealSense/Sensor.cs | 399 +++++++++ Intel.RealSense/StreamProfile.cs | 215 +++++ Intel.RealSense/Types.cs | 275 ++++++ Sources/Video/RealSenseNetworkStream.cs | 110 ++- cs-tutorial-2-capture/Program.cs | 16 + cs-tutorial-2-capture/SocketServer.cs | 121 +++ cs-tutorial-2-capture/Window.xaml | 19 + cs-tutorial-2-capture/Window.xaml.cs | 126 +++ cs-tutorial-2-capture/app.config | 3 + .../cs-tutorial-2-capture.csproj | 129 +++ iSpy64.sln | 124 +++ 25 files changed, 4617 insertions(+), 44 deletions(-) create mode 100644 Intel.RealSense/.nuget/Intel.RealSense.targets create mode 100644 Intel.RealSense/Context.cs create mode 100644 Intel.RealSense/Device.cs create mode 100644 Intel.RealSense/Frame.cs create mode 100644 Intel.RealSense/FrameQueue.cs create mode 100644 Intel.RealSense/FrameSet.cs create mode 100644 Intel.RealSense/Helpers.cs create mode 100644 Intel.RealSense/Intel.RealSense.2015.csproj create mode 100644 Intel.RealSense/Intel.RealSense.csproj create mode 100644 Intel.RealSense/NativeMethods.cs create mode 100644 Intel.RealSense/Pipeline.cs create mode 100644 Intel.RealSense/Processing.cs create mode 100644 Intel.RealSense/Properties/AssemblyInfo.cs create mode 100644 Intel.RealSense/Sensor.cs create mode 100644 Intel.RealSense/StreamProfile.cs create mode 100644 Intel.RealSense/Types.cs create mode 100644 cs-tutorial-2-capture/Program.cs create mode 100644 cs-tutorial-2-capture/SocketServer.cs create mode 100644 cs-tutorial-2-capture/Window.xaml create mode 100644 cs-tutorial-2-capture/Window.xaml.cs create mode 100644 cs-tutorial-2-capture/app.config create mode 100644 cs-tutorial-2-capture/cs-tutorial-2-capture.csproj diff --git a/.gitignore b/.gitignore index 88fa7e1..0ff048c 100644 --- a/.gitignore +++ b/.gitignore @@ -47,4 +47,323 @@ ipch/ # Windows thumbnail cache files Thumbs.db ehthumbs.db -ehthumbs_vista.db \ No newline at end of file +ehthumbs_vista.db +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# TypeScript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + diff --git a/Intel.RealSense/.nuget/Intel.RealSense.targets b/Intel.RealSense/.nuget/Intel.RealSense.targets new file mode 100644 index 0000000..fc98403 --- /dev/null +++ b/Intel.RealSense/.nuget/Intel.RealSense.targets @@ -0,0 +1,16 @@ + + + + + %(FileName)%(Extension) + PreserveNewest + + + + + + %(FileName)%(Extension) + PreserveNewest + + + \ No newline at end of file diff --git a/Intel.RealSense/Context.cs b/Intel.RealSense/Context.cs new file mode 100644 index 0000000..6dd1313 --- /dev/null +++ b/Intel.RealSense/Context.cs @@ -0,0 +1,96 @@ +using System; +using System.Runtime.InteropServices; + +namespace Intel.RealSense +{ + public class Context : IDisposable + { + internal HandleRef m_instance; + + public readonly int api_version; + public string Version + { + get + { + if (api_version / 10000 == 0) return api_version.ToString(); + return (api_version / 10000) + "." + (api_version % 10000) / 100 + "." + (api_version % 100); + } + } + + /// + /// default librealsense context class + /// + public Context() + { + object error; + api_version = NativeMethods.rs2_get_api_version(out error); + m_instance = new HandleRef(this, NativeMethods.rs2_create_context(api_version, out error)); + } + + + /// + /// create a static snapshot of all connected devices at the time of the call + /// + /// + public DeviceList QueryDevices() + { + object error; + var ptr = NativeMethods.rs2_query_devices(m_instance.Handle, out error); + return new DeviceList(ptr); + } + + /// + /// create a static snapshot of all connected devices at the time of the call + /// + public DeviceList Devices + { + get + { + return QueryDevices(); + } + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + if (m_instance.Handle != IntPtr.Zero) + { + NativeMethods.rs2_delete_context(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~Context() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + } + + +} diff --git a/Intel.RealSense/Device.cs b/Intel.RealSense/Device.cs new file mode 100644 index 0000000..331c93c --- /dev/null +++ b/Intel.RealSense/Device.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace Intel.RealSense +{ + public class DeviceList : IDisposable, IEnumerable + { + IntPtr m_instance; + + public DeviceList(IntPtr ptr) + { + m_instance = ptr; + } + + + public IEnumerator GetEnumerator() + { + object error; + + int deviceCount = NativeMethods.rs2_get_device_count(m_instance, out error); + for (int i = 0; i < deviceCount; i++) + { + var ptr = NativeMethods.rs2_create_device(m_instance, i, out error); + yield return new Device(ptr); + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get + { + object error; + int deviceCount = NativeMethods.rs2_get_device_count(m_instance, out error); + return deviceCount; + } + } + + public Device this[int index] + { + get + { + object error; + var ptr = NativeMethods.rs2_create_device(m_instance, index, out error); + return new Device(ptr); + } + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + NativeMethods.rs2_delete_device_list(m_instance); + m_instance = IntPtr.Zero; + + disposedValue = true; + } + } + + //TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~DeviceList() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + } + + public class Device + { + public IntPtr m_instance; + + internal Device(IntPtr dev) + { + //if (dev == IntPtr.Zero) + // throw new ArgumentNullException(); + m_instance = dev; + } + + public class CameraInfos + { + IntPtr m_device; + public CameraInfos(IntPtr device) { m_device = device; } + + public string this[CameraInfo info] + { + get + { + object err; + if (NativeMethods.rs2_supports_device_info(m_device, info, out err) > 0) + return Marshal.PtrToStringAnsi(NativeMethods.rs2_get_device_info(m_device, info, out err)); + return null; + } + } + } + + CameraInfos m_info; + + public CameraInfos Info + { + get + { + if (m_info == null) + m_info = new CameraInfos(m_instance); + return m_info; + } + } + + /// + /// create a static snapshot of all connected devices at the time of the call + /// + /// + public SensorList QuerySensors() + { + object error; + var ptr = NativeMethods.rs2_query_sensors(m_instance, out error); + return new SensorList(ptr); + } + + /// + /// create a static snapshot of all connected devices at the time of the call + /// + public SensorList Sensors + { + get + { + return QuerySensors(); + } + } + } + + public class AdvancedDevice : Device + { + internal AdvancedDevice(IntPtr dev) : base(dev) + { + + } + + public static AdvancedDevice FromDevice(Device dev) + { + object error; + if (NativeMethods.rs2_is_device_extendable_to(dev.m_instance, Extension.AdvancedMode, out error) == 0) + { + throw new ArgumentException("Device does not support AdvancedMode"); + } + + return new AdvancedDevice(dev.m_instance); + } + + public bool AdvancedModeEnabled + { + get + { + int enabled = 0; + object error; + NativeMethods.rs2_is_enabled(m_instance, out enabled, out error); + + return enabled == 1 ? true : false; + } + set + { + object error; + NativeMethods.rs2_toggle_advanced_mode(m_instance, value ? 1 : 0, out error); + } + } + + public string JsonConfiguration + { + get + { + object error; + IntPtr buffer = NativeMethods.rs2_serialize_json(m_instance, out error); + int size = NativeMethods.rs2_get_raw_data_size(buffer, out error); + IntPtr data = NativeMethods.rs2_get_raw_data(buffer, out error); + + return Marshal.PtrToStringAnsi(data, size); + } + set + { + object error; + NativeMethods.rs2_load_json(m_instance, value, (uint)value.ToCharArray().Length, out error); + } + } + } + +} diff --git a/Intel.RealSense/Frame.cs b/Intel.RealSense/Frame.cs new file mode 100644 index 0000000..725f12c --- /dev/null +++ b/Intel.RealSense/Frame.cs @@ -0,0 +1,324 @@ +using System; +using System.Runtime.InteropServices; + +namespace Intel.RealSense +{ + public class Frame : IDisposable + { + internal HandleRef m_instance; + + public Frame(IntPtr ptr) + { + m_instance = new HandleRef(this, ptr); + NativeMethods.rs2_keep_frame(m_instance.Handle); + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~Frame() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + if (m_instance.Handle != IntPtr.Zero) + NativeMethods.rs2_release_frame(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + + public Frame Clone() + { + object error; + NativeMethods.rs2_frame_add_ref(m_instance.Handle, out error); + return new Frame(m_instance.Handle); + } + + public IntPtr Data + { + get + { + object error; + return NativeMethods.rs2_get_frame_data(m_instance.Handle, out error); + } + } + + public StreamProfile Profile + { + get + { + object error; + return new StreamProfile(NativeMethods.rs2_get_frame_stream_profile(m_instance.Handle, out error)); + } + } + + public ulong Number + { + get + { + object error; + var frameNumber = NativeMethods.rs2_get_frame_number(m_instance.Handle, out error); + return frameNumber; + } + } + + public double Timestamp + { + get + { + object error; + var timestamp = NativeMethods.rs2_get_frame_timestamp(m_instance.Handle, out error); + return timestamp; + } + } + + + public TimestampDomain TimestampDomain + { + get + { + object error; + var timestampDomain = NativeMethods.rs2_get_frame_timestamp_domain(m_instance.Handle, out error); + return timestampDomain; + } + } + } + + public class VideoFrame : Frame + { + public VideoFrame(IntPtr ptr) : base(ptr) + { + } + + public int Width + { + get + { + object error; + var w = NativeMethods.rs2_get_frame_width(m_instance.Handle, out error); + return w; + } + } + + public int Height + { + get + { + object error; + var h = NativeMethods.rs2_get_frame_height(m_instance.Handle, out error); + return h; + } + } + + public int Stride + { + get + { + object error; + var stride = NativeMethods.rs2_get_frame_stride_in_bytes(m_instance.Handle, out error); + return stride; + } + } + + public int BitsPerPixel + { + get + { + object error; + var bpp = NativeMethods.rs2_get_frame_bits_per_pixel(m_instance.Handle, out error); + return bpp; + } + } + + /// + /// Copy frame data to managed typed array + /// + /// + /// + //public void CopyTo(out T[] array) + public void CopyTo(T[] array) + { + if (array == null) + throw new ArgumentNullException("array"); + var handle = GCHandle.Alloc(array, GCHandleType.Pinned); + try + { + //System.Diagnostics.Debug.Assert((array.Length * Marshal.SizeOf(typeof(T))) == (Stride * Height)); + NativeMethods.memcpy(handle.AddrOfPinnedObject(), Data, Stride * Height); + } + finally + { + handle.Free(); + } + } + } + + public class DepthFrame : VideoFrame + { + public DepthFrame(IntPtr ptr) : base(ptr) + { + } + + public float GetDistance(int x, int y) + { + object error; + return NativeMethods.rs2_depth_frame_get_distance(m_instance.Handle, x, y, out error); + } + } + + + public class Points : Frame + { + [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)] + public struct Vertex + { + public float x; + public float y; + public float z; + } + public struct TextureCoordinate + { + public float u; + public float v; + } + public Points(IntPtr ptr) : base(ptr) + { + } + + public int Count + { + get + { + object error; + var h = NativeMethods.rs2_get_frame_points_count(m_instance.Handle, out error); + return h; + } + } + + private IntPtr VertexData + { + get + { + object error; + return NativeMethods.rs2_get_frame_vertices(m_instance.Handle, out error); + } + } + + /// + /// Copy frame data to Vertex array + /// + /// + public void CopyTo(Vertex[] array) + { + if (array == null) + throw new ArgumentNullException("array"); + var handle = GCHandle.Alloc(array, GCHandleType.Pinned); + try + { + NativeMethods.memcpy(handle.AddrOfPinnedObject(), VertexData, Count * Marshal.SizeOf(typeof(Vertex))); + } + finally + { + handle.Free(); + } + } + + private IntPtr TextureData + { + get + { + object error; + return NativeMethods.rs2_get_frame_texture_coordinates(m_instance.Handle, out error); + } + } + /// + /// Copy frame data to TextureCoordinate array + /// + /// + public void CopyTo(TextureCoordinate[] textureArray) + { + if (textureArray == null) + throw new ArgumentNullException("textureArray"); + + var handle = GCHandle.Alloc(textureArray, GCHandleType.Pinned); + try + { + var size = Count * Marshal.SizeOf(typeof(TextureCoordinate)); + NativeMethods.memcpy(handle.AddrOfPinnedObject(), TextureData, size); + } + finally + { + handle.Free(); + } + } + } + + + + class FrameMarshaler : ICustomMarshaler + { + private static FrameMarshaler Instance; + + public static ICustomMarshaler GetInstance(string s) + { + if (Instance == null) + { + Instance = new FrameMarshaler(); + } + return Instance; + } + + public void CleanUpManagedData(object ManagedObj) + { + } + + public void CleanUpNativeData(IntPtr pNativeData) + { + } + + public int GetNativeDataSize() + { + //return IntPtr.Size; + return -1; + } + + public IntPtr MarshalManagedToNative(object ManagedObj) + { + throw new NotImplementedException(); + } + + public object MarshalNativeToManaged(IntPtr pNativeData) + { + return new Frame(pNativeData); + } + } +} diff --git a/Intel.RealSense/FrameQueue.cs b/Intel.RealSense/FrameQueue.cs new file mode 100644 index 0000000..2581186 --- /dev/null +++ b/Intel.RealSense/FrameQueue.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; + +namespace Intel.RealSense +{ + public class FrameQueue : IDisposable, IEnumerable + { + internal HandleRef m_instance; + + public FrameQueue(int capacity = 10) + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_frame_queue(capacity, out error)); + } + + public bool PollForFrame(out Frame frame, FramesReleaser releaser = null) + { + object error; + if (NativeMethods.rs2_poll_for_frame(m_instance.Handle, out frame, out error) > 0) + { + frame = FramesReleaser.ScopedReturn(releaser, FrameSet.CreateFrame(frame.m_instance.Handle)); + return true; + } + return false; + } + + public Frame WaitForFrame(FramesReleaser releaser = null) + { + object error; + var ptr = NativeMethods.rs2_wait_for_frame(m_instance.Handle, 5000, out error); + return FramesReleaser.ScopedReturn(releaser, FrameSet.CreateFrame(ptr)); + } + + public FrameSet WaitForFrames(FramesReleaser releaser = null) + { + object error; + var ptr = NativeMethods.rs2_wait_for_frame(m_instance.Handle, 5000, out error); + return FramesReleaser.ScopedReturn(releaser, new FrameSet(ptr)); + } + + public void Enqueue(Frame f) + { + object error; + NativeMethods.rs2_frame_add_ref(f.m_instance.Handle, out error); + NativeMethods.rs2_enqueue_frame(f.m_instance.Handle, m_instance.Handle); + } + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + NativeMethods.rs2_delete_frame_queue(m_instance.Handle); + + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~FrameQueue() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + + public IEnumerator GetEnumerator() + { + Frame frame; + while (PollForFrame(out frame)) + { + yield return frame; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + #endregion + } +} diff --git a/Intel.RealSense/FrameSet.cs b/Intel.RealSense/FrameSet.cs new file mode 100644 index 0000000..bfebc45 --- /dev/null +++ b/Intel.RealSense/FrameSet.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Linq; + +namespace Intel.RealSense +{ + public class FrameSet : IDisposable, IEnumerable + { + internal HandleRef m_instance; + + public Frame AsFrame() + { + object error; + NativeMethods.rs2_frame_add_ref(m_instance.Handle, out error); + return CreateFrame(m_instance.Handle); + } + + public static FrameSet FromFrame(Frame composite, FramesReleaser releaser = null) + { + object error; + if (NativeMethods.rs2_is_frame_extendable_to(composite.m_instance.Handle, + Extension.CompositeFrame, out error) > 0) + { + NativeMethods.rs2_frame_add_ref(composite.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, new FrameSet(composite.m_instance.Handle)); + } + throw new Exception("The frame is a not composite frame"); + } + + internal static Frame CreateFrame(IntPtr ptr) + { + object error; + if (NativeMethods.rs2_is_frame_extendable_to(ptr, Extension.Points, out error) > 0) + return new Points(ptr); + else if (NativeMethods.rs2_is_frame_extendable_to(ptr, Extension.DepthFrame, out error) > 0) + return new DepthFrame(ptr); + else if (NativeMethods.rs2_is_frame_extendable_to(ptr, Extension.VideoFrame, out error) > 0) + return new VideoFrame(ptr); + else + return new Frame(ptr); + } + + public DepthFrame DepthFrame + { + get + { + return this.FirstOrDefault(x => x.Profile.Stream == Stream.Depth) as DepthFrame; + } + } + + public VideoFrame ColorFrame + { + get + { + return this.FirstOrDefault(x => x.Profile.Stream == Stream.Color) as VideoFrame; + } + } + + public IEnumerator GetEnumerator() + { + object error; + + int deviceCount = NativeMethods.rs2_embedded_frames_count(m_instance.Handle, out error); + for (int i = 0; i < deviceCount; i++) + { + var ptr = NativeMethods.rs2_extract_frame(m_instance.Handle, i, out error); + yield return CreateFrame(ptr); + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get + { + object error; + int deviceCount = NativeMethods.rs2_embedded_frames_count(m_instance.Handle, out error); + return deviceCount; + } + } + + public Frame this[int index] + { + get + { + object error; + var ptr = NativeMethods.rs2_extract_frame(m_instance.Handle, index, out error); + return CreateFrame(ptr); + } + } + + internal FrameSet(IntPtr ptr) + { + m_instance = new HandleRef(this, ptr); + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~FrameSet() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + if (m_instance.Handle != IntPtr.Zero) + NativeMethods.rs2_release_frame(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + + } + + + class FrameSetMarshaler : ICustomMarshaler + { + private static FrameSetMarshaler Instance; + + public static ICustomMarshaler GetInstance(string s) + { + if (Instance == null) + { + Instance = new FrameSetMarshaler(); + } + return Instance; + } + + public void CleanUpManagedData(object ManagedObj) + { + } + + public void CleanUpNativeData(IntPtr pNativeData) + { + } + + public int GetNativeDataSize() + { + return -1; + } + + public IntPtr MarshalManagedToNative(object ManagedObj) + { + throw new NotImplementedException(); + } + + public object MarshalNativeToManaged(IntPtr pNativeData) + { + return new FrameSet(pNativeData); + } + } +} diff --git a/Intel.RealSense/Helpers.cs b/Intel.RealSense/Helpers.cs new file mode 100644 index 0000000..374c2fe --- /dev/null +++ b/Intel.RealSense/Helpers.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Runtime.InteropServices; + +namespace Intel.RealSense +{ + public class FramesReleaser : IDisposable + { + public FramesReleaser() { } + + public void AddFrameToRelease(T f) where T : IDisposable + { + if (!m_objects.Contains(f)) + m_objects.Add(f); + } + + // Add an object to a releaser (if one is provided) and return the object + public static T ScopedReturn(FramesReleaser releaser, T obj) where T : IDisposable + { + if (releaser != null) releaser.AddFrameToRelease(obj); + return obj; + } + + private HashSet m_objects = new HashSet(); + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + foreach (var o in m_objects) + o.Dispose(); + disposedValue = true; + } + } + + ~FramesReleaser() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + } + + public static class Helpers + { + /// + /// Custom marshaler for throwing exceptions on errors codes. + /// + public class ErrorMarshaler : ICustomMarshaler + { + + //private static ErrorMarshaler Instance = new ErrorMarshaler(); + private static ErrorMarshaler Instance; + + public static ICustomMarshaler GetInstance(string s) + { + if (Instance == null) + { + Instance = new ErrorMarshaler(); + } + return Instance; + } + + + public void CleanUpManagedData(object ManagedObj) + { + } + + public void CleanUpNativeData(IntPtr pNativeData) + { + //!TODO: maybe rs_free_error here? + NativeMethods.rs2_free_error(pNativeData); + } + + public int GetNativeDataSize() + { + return IntPtr.Size; + } + + public IntPtr MarshalManagedToNative(object ManagedObj) + { + return IntPtr.Zero; + } + + //[DebuggerHidden] + //[DebuggerStepThrough] + //[DebuggerNonUserCode] + public object MarshalNativeToManaged(IntPtr pNativeData) + { + if (pNativeData == IntPtr.Zero) + return null; + + string function = Marshal.PtrToStringAnsi(NativeMethods.rs2_get_failed_function(pNativeData)); + string args = Marshal.PtrToStringAnsi(NativeMethods.rs2_get_failed_args(pNativeData)); + string message = Marshal.PtrToStringAnsi(NativeMethods.rs2_get_error_message(pNativeData)); + + //Debug.LogError("rs_error was raised when calling " + function + "(" + args + ")" + ""); + //Debug.LogError("Message: " + message + ""); + + //NativeMethods.rs_free_error(pNativeData); + + var f = String.Format("{0}({1})", function, args); + //StackTrace stackTrace = new StackTrace(1, true); + //Debug.Log(stackTrace.GetFrame(0).GetFileName()); + + //!TODO: custom exception type? + var e = new Exception(message + Environment.NewLine + f); + + //!TODO: maybe throw only in debug? would need to change all methods to return error\null + throw e; + //ThrowIfDebug(e); + //return e; + } + + [DebuggerHidden] + [DebuggerStepThrough] + [DebuggerNonUserCode] + [Conditional("DEBUG")] + void ThrowIfDebug(Exception e) + { + throw e; + } + } + } +} \ No newline at end of file diff --git a/Intel.RealSense/Intel.RealSense.2015.csproj b/Intel.RealSense/Intel.RealSense.2015.csproj new file mode 100644 index 0000000..c9c34d3 --- /dev/null +++ b/Intel.RealSense/Intel.RealSense.2015.csproj @@ -0,0 +1,153 @@ + + + + + Debug + AnyCPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86} + Library + Properties + Intel.RealSense + Intel.RealSense + v4.5.2 + 512 + + + + + true + bin\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + 4 + false + false + false + + + bin\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + 4 + false + + + true + bin\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + false + false + + + bin\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + false + + + false + + + false + + + + + + + + + + + + + + + + + + + + + + $(Platform) + x86 + x64 + C:\Program Files (x86)\Intel RealSense SDK 2.0\bin + + + + + ..\..\..\build\$(Configuration)\realsense2.dll + + + + + + $(LibPathx86) + $(LibPathx64) + + + + + + + + + + + x86 + x64 + $(BuildPath) + $(BuildPath) + $(InstallPath)\x86\realsense2.dll + $(InstallPath)\x64\realsense2.dll + $(BuildPathx86) + $(BuildPathx64) + + + + + + + + + + + + + + -1 + ..\..\..\build + + + + + + + + + + + \ No newline at end of file diff --git a/Intel.RealSense/Intel.RealSense.csproj b/Intel.RealSense/Intel.RealSense.csproj new file mode 100644 index 0000000..bb06aad --- /dev/null +++ b/Intel.RealSense/Intel.RealSense.csproj @@ -0,0 +1,97 @@ + + + + netstandard2.0;net35;net461 + Intel.RealSense + true + Intel + Intel + Intel.RealSense + Copyright © 2017 Intel Corporation + .NET Wrapper for Intel RealSense SDK 2.0 + https://github.com/IntelRealSense/librealsense + https://github.com/IntelRealSense/librealsense/blob/master/doc/img/realsense.png + https://github.com/IntelRealSense/librealsense + 3d;vision;robotics;depth;realsense;perception + https://github.com/IntelRealSense/librealsense/blob/master/LICENSE + Debug;Release + AnyCPU;x86;x64 + + + + + + + + + $(Platform) + x86 + x64 + C:\Program Files (x86)\Intel RealSense SDK 2.0\bin + + + ..\..\..\build\$(Configuration)\realsense2.dll + + + + + + + + + + $(LibPathx86) + $(LibPathx64) + + + + + + + + + + + + + + + + + + + x86 + x64 + $(BuildPath) + $(BuildPath) + $(InstallPath)\x86\realsense2.dll + $(InstallPath)\x64\realsense2.dll + $(BuildPathx86) + $(BuildPathx64) + + + + + + + + + + + + + + + -1 + ..\..\..\build + + + + + + + + + + + diff --git a/Intel.RealSense/NativeMethods.cs b/Intel.RealSense/NativeMethods.cs new file mode 100644 index 0000000..41e571e --- /dev/null +++ b/Intel.RealSense/NativeMethods.cs @@ -0,0 +1,795 @@ +using System; +using System.Runtime.InteropServices; +using System.Security; + +namespace Intel.RealSense +{ + //[System.Security.SuppressUnmanagedCodeSecurity] + internal static class NativeMethods + { + const string dllName = "realsense2"; + + [DllImport("msvcrt.dll", EntryPoint = "memcpy", CallingConvention = CallingConvention.Cdecl, SetLastError = false)] + internal static extern IntPtr memcpy(IntPtr dest, IntPtr src, int count); + + #region rs_record_playback + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_record_device(IntPtr device, [MarshalAs(UnmanagedType.LPStr)] string file, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_record_device_pause(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_record_device_resume(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_playback_device([MarshalAs(UnmanagedType.LPStr)] string file, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_playback_device_get_file_path(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern ulong rs2_playback_get_duration(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_seek(IntPtr device, long time, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern ulong rs2_playback_get_position(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_device_resume(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_device_pause(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_device_set_real_time(IntPtr device, int real_time, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_playback_device_is_real_time(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_device_set_status_changed_callback(IntPtr device, IntPtr callback, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern PlaybackStatus rs2_playback_device_get_current_status(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_device_set_playback_speed(IntPtr device, float speed, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_playback_device_stop(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_processing + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_colorizer([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_sync_processing_block([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_pointcloud([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_processing_block_fptr([MarshalAs(UnmanagedType.FunctionPtr)] frame_processor_callback on_frame, IntPtr user, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_start_processing_fptr(IntPtr block, [MarshalAs(UnmanagedType.FunctionPtr)] frame_callback on_frame, IntPtr user, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_start_processing_queue(IntPtr block, IntPtr queue, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_process_frame(IntPtr block, IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_processing_block(IntPtr block); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_frame_queue(int capacity, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_frame_queue(IntPtr queue); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_wait_for_frame(IntPtr queue, uint timeout_ms, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_poll_for_frame(IntPtr queue, + [Out, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FrameMarshaler))] out Frame output_frame, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_enqueue_frame(IntPtr frame, IntPtr queue); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_align(Stream align_to, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_decimation_filter_block([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_temporal_filter_block([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_spatial_filter_block([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_disparity_transform_block(byte transform_to_disparity, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_hole_filling_filter_block([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_option + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_is_option_read_only(IntPtr options, Option option, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern float rs2_get_option(IntPtr options, Option option, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_option(IntPtr options, Option option, float value, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_supports_option(IntPtr options, Option option, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_option_range(IntPtr sensor, Option option, out float min, out float max, out float step, out float def, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_option_description(IntPtr options, Option option, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_option_value_description(IntPtr options, Option option, float value, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_frame + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern long rs2_get_frame_metadata(IntPtr frame, FrameMetadataValue frame_metadata, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_supports_frame_metadata(IntPtr frame, FrameMetadataValue frame_metadata, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern TimestampDomain rs2_get_frame_timestamp_domain(IntPtr frameset, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern double rs2_get_frame_timestamp(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern ulong rs2_get_frame_number(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_frame_data(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_frame_width(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_frame_height(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_frame_stride_in_bytes(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_frame_bits_per_pixel(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_frame_add_ref(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_release_frame(IntPtr frame); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_keep_frame(IntPtr frame); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_frame_vertices(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_frame_texture_coordinates(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_frame_points_count(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_frame_stream_profile(IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_is_frame_extendable_to(IntPtr frame, Extension extension_type, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_allocate_synthetic_video_frame(IntPtr source, IntPtr new_stream, IntPtr original, int new_bpp, int new_width, int new_height, int new_stride, Extension frame_type, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_allocate_composite_frame(IntPtr source, [In]IntPtr[] frames, int count, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_extract_frame(IntPtr composite, int index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_embedded_frames_count(IntPtr composite, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_synthetic_frame_ready(IntPtr source, IntPtr frame, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_sensor + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_sensor_list(IntPtr info_list); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_sensors_count(IntPtr info_list, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_sensor(IntPtr sensor); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_sensor(IntPtr list, int index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_device_from_sensor(IntPtr sensor, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_sensor_info(IntPtr sensor, CameraInfo info, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_supports_sensor_info(IntPtr sensor, CameraInfo info, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_is_sensor_extendable_to(IntPtr sensor, Extension extension, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern float rs2_get_depth_scale(IntPtr sensor, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_region_of_interest(IntPtr sensor, int min_x, int min_y, int max_x, int max_y, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_region_of_interest(IntPtr sensor, out int min_x, out int min_y, out int max_x, out int max_y, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_open(IntPtr device, IntPtr profile, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_open_multiple(IntPtr device, [In]IntPtr[] profiles, int count, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_close(IntPtr sensor, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_start(IntPtr sensor, [MarshalAs(UnmanagedType.FunctionPtr)] frame_callback on_frame, IntPtr user, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_start_queue(IntPtr sensor, IntPtr queue, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_stop(IntPtr sensor, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_notifications_callback(IntPtr sensor, [MarshalAs(UnmanagedType.FunctionPtr)] frame_callback on_notification, IntPtr user, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_notification_description(IntPtr notification, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern double rs2_get_notification_timestamp(IntPtr notification, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern LogSeverity rs2_get_notification_severity(IntPtr notification, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern NotificationCategory rs2_get_notification_category(IntPtr notification, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_stream_profiles(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_stream_profile(IntPtr list, int index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_stream_profile_data(IntPtr mode, out Stream stream, out Format format, out int index, out int unique_id, out int framerate, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_stream_profile_data(IntPtr mode, Stream stream, int index, Format format, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_clone_stream_profile(IntPtr mode, Stream stream, int index, Format format, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_stream_profile(IntPtr mode); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_stream_profile_is(IntPtr mode, Extension type, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_video_stream_resolution(IntPtr from, out int width, out int height, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_is_stream_profile_default(IntPtr profile, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_stream_profiles_count(IntPtr list, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_stream_profiles_list(IntPtr list); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_extrinsics(IntPtr from, IntPtr to, out Extrinsics extrin, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_video_stream_intrinsics(IntPtr from, out Intrinsics intrinsics, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_device + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_device_count(IntPtr info_list, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_device_list(IntPtr info_list); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_device_list_contains(IntPtr info_list, IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_device(IntPtr info_list, int index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_device(IntPtr device); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_device_info(IntPtr device, CameraInfo info, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_supports_device_info(IntPtr device, CameraInfo info, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_hardware_reset(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_send_and_receive_raw_data(IntPtr device, IntPtr raw_data_to_send, uint size_of_raw_data_to_send, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_motion_intrinsics(IntPtr device, Stream stream, IntPtr intrinsics, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_is_device_extendable_to(IntPtr device, Extension extension, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_query_sensors(IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_context + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_context(int api_version, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_context(IntPtr context); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_devices_changed_callback(IntPtr context, [MarshalAs(UnmanagedType.FunctionPtr)] frame_callback callback, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_context_add_device(IntPtr ctx, [MarshalAs(UnmanagedType.LPStr)] string file, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_context_remove_device(IntPtr ctx, [MarshalAs(UnmanagedType.LPStr)] string file, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_query_devices(IntPtr context, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_device_hub(IntPtr context, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_device_hub(IntPtr hub); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_device_hub_wait_for_device(IntPtr ctx, IntPtr hub, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_device_hub_is_device_connected(IntPtr hub, IntPtr device, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_types + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern ExceptionType rs2_get_librealsense_exception_type([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + #endregion + #region rs + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_raw_data_size(IntPtr buffer, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_raw_data(IntPtr buffer); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_raw_data(IntPtr buffer, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_get_api_version([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_log_to_console(LogSeverity min_severity, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_log_to_file(LogSeverity min_severity, [MarshalAs(UnmanagedType.LPStr)] string file_path, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_log(LogSeverity severity, [MarshalAs(UnmanagedType.LPStr)] string message, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern float rs2_depth_frame_get_distance(IntPtr frame_ref, int x, int y, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern double rs2_get_time([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_advanced_mode + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_toggle_advanced_mode(IntPtr dev, int enable, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_is_enabled(IntPtr dev, out int enabled, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_depth_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_depth_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_rsm(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_rsm(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_rau_support_vector_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_rau_support_vector_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_color_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_color_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_rau_thresholds_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_rau_thresholds_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_slo_color_thresholds_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_slo_color_thresholds_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_slo_penalty_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_slo_penalty_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_hdad(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_hdad(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_color_correction(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_color_correction(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_depth_table(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_depth_table(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_ae_control(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_ae_control(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_set_census(IntPtr dev, IntPtr group, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_get_census(IntPtr dev, IntPtr group, int mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_load_json(IntPtr dev, [MarshalAs(UnmanagedType.LPStr)] string json_content, uint content_size, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_serialize_json(IntPtr dev, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_internal + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_recording_context(int api_version, [MarshalAs(UnmanagedType.LPStr)] string filename, [MarshalAs(UnmanagedType.LPStr)] string section, RecordingMode mode, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_mock_context(int api_version, [MarshalAs(UnmanagedType.LPStr)] string filename, [MarshalAs(UnmanagedType.LPStr)] string section, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + #region rs_pipeline + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_pipeline(IntPtr ctx, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_pipeline_stop(IntPtr pipe, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_pipeline_wait_for_frames(IntPtr pipe, uint timeout_ms, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_pipeline_poll_for_frames(IntPtr pipe, + [Out, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FrameSetMarshaler))] out FrameSet output_frame, + [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_pipeline(IntPtr pipe); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_pipeline_start(IntPtr pipe, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_pipeline_start_with_config(IntPtr pipe, IntPtr config, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_pipeline_get_active_profile(IntPtr pipe, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_pipeline_profile_get_device(IntPtr profile, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_pipeline_profile_get_streams(IntPtr profile, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_pipeline_profile(IntPtr profile); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_create_config([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_delete_config(IntPtr config); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_enable_stream(IntPtr config, Stream stream, int index, int width, int height, Format format, int framerate, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_enable_all_stream(IntPtr config, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_enable_device(IntPtr config, [MarshalAs(UnmanagedType.LPStr)] string serial, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_enable_device_from_file(IntPtr config, [MarshalAs(UnmanagedType.LPStr)] string file, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_enable_record_to_file(IntPtr config, [MarshalAs(UnmanagedType.LPStr)] string file, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_disable_stream(IntPtr config, int stream, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_disable_indexed_stream(IntPtr config, Stream stream, int index, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern void rs2_config_disable_all_streams(IntPtr config, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_config_resolve(IntPtr config, IntPtr pipe, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern int rs2_config_can_resolve(IntPtr config, IntPtr pipe, [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(Helpers.ErrorMarshaler))] out object error); + + + #endregion + + #region Error Handling + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_failed_function(IntPtr error); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_failed_args(IntPtr error); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_get_error_message(IntPtr error); + + [DllImport(dllName, CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr rs2_free_error(IntPtr error); + #endregion + + } +} \ No newline at end of file diff --git a/Intel.RealSense/Pipeline.cs b/Intel.RealSense/Pipeline.cs new file mode 100644 index 0000000..70b3484 --- /dev/null +++ b/Intel.RealSense/Pipeline.cs @@ -0,0 +1,321 @@ +using System; +using System.Runtime.InteropServices; +using System.Linq; + +namespace Intel.RealSense +{ + public class Pipeline : IDisposable + { + internal HandleRef m_instance; + + public Pipeline(Context ctx) + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_pipeline(ctx.m_instance.Handle, out error)); + } + + public Pipeline() + { + var ctx = new Context(); + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_pipeline(ctx.m_instance.Handle, out error)); + } + + public PipelineProfile Start() + { + object error; + var res = NativeMethods.rs2_pipeline_start(m_instance.Handle, out error); + var prof = new PipelineProfile(res); + return prof; + } + + public PipelineProfile Start(Config cfg) + { + object error; + var res = NativeMethods.rs2_pipeline_start_with_config(m_instance.Handle, cfg.m_instance.Handle, out error); + var prof = new PipelineProfile(res); + return prof; + } + + public void Stop() + { + object error; + NativeMethods.rs2_pipeline_stop(m_instance.Handle, out error); + } + + public FrameSet WaitForFrames(uint timeout_ms =5000, FramesReleaser releaser = null) + { + object error; + var ptr = NativeMethods.rs2_pipeline_wait_for_frames(m_instance.Handle, timeout_ms, out error); + return FramesReleaser.ScopedReturn(releaser, new FrameSet(ptr)); + } + + public bool PollForFrames(out FrameSet result, FramesReleaser releaser = null) + { + object error; + FrameSet fs; + if (NativeMethods.rs2_pipeline_poll_for_frames(m_instance.Handle, out fs, out error) > 0) + { + result = FramesReleaser.ScopedReturn(releaser, fs); + return true; + } + result = null; + return false; + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~Pipeline() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + if (m_instance.Handle != IntPtr.Zero) + NativeMethods.rs2_delete_pipeline(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + } + + public class PipelineProfile : IDisposable + { + HandleRef m_instance; + + public PipelineProfile(IntPtr p) + { + m_instance = new HandleRef(this, p); + } + + public Device Device + { + get + { + object error; + var ptr = NativeMethods.rs2_pipeline_profile_get_device(m_instance.Handle, out error); + return new Device(ptr); + } + } + + public StreamProfileList Streams + { + get + { + object error; + var ptr = NativeMethods.rs2_pipeline_profile_get_streams(m_instance.Handle, out error); + return new StreamProfileList(ptr); + } + } + + public StreamProfile GetStream(Stream s, int index = -1) + { + return Streams.First(x => x.Stream == s && (index != -1 ? x.Index == index : true)); + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~PipelineProfile() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + if (m_instance.Handle != IntPtr.Zero) + NativeMethods.rs2_delete_pipeline_profile(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + } + + public class Config : IDisposable + { + internal HandleRef m_instance; + + public Config() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_config(out error)); + } + + public void EnableStream(Stream s, int index = -1) + { + object error; + NativeMethods.rs2_config_enable_stream(m_instance.Handle, s, index, 0, 0, Format.Any, 0, out error); + } + + public void EnableStream(Stream stream_type, int stream_index, int width, int height, Format format = Format.Any, int framerate = 0) + { + object error; + NativeMethods.rs2_config_enable_stream(m_instance.Handle, stream_type, stream_index, width, height, format, framerate, out error); + } + + public void EnableStream(Stream stream_type, int width, int height, Format format = Format.Any, int framerate = 0) + { + object error; + NativeMethods.rs2_config_enable_stream(m_instance.Handle, stream_type, -1, width, height, format, framerate, out error); + } + + public void EnableStream(Stream stream_type, Format format, int framerate = 0) + { + object error; + NativeMethods.rs2_config_enable_stream(m_instance.Handle, stream_type, -1, 0, 0, format, framerate, out error); + } + + public void EnableStream(Stream stream_type, int stream_index, Format format, int framerate = 0) + { + object error; + NativeMethods.rs2_config_enable_stream(m_instance.Handle, stream_type, stream_index, 0, 0, format, framerate, out error); + } + + public void EnableAllStreams() + { + object error; + NativeMethods.rs2_config_enable_all_stream(m_instance.Handle, out error); + } + + public void EnableDevice(string serial) + { + object error; + NativeMethods.rs2_config_enable_device(m_instance.Handle, serial, out error); + } + + public void EnableDeviceFromFile(string filename) + { + object error; + NativeMethods.rs2_config_enable_device_from_file(m_instance.Handle, filename, out error); + } + + public void EnableRecordToFile(string filename) + { + object error; + NativeMethods.rs2_config_enable_record_to_file(m_instance.Handle, filename, out error); + } + + public void DisableStream(Stream s, int index = -1) + { + object error; + NativeMethods.rs2_config_disable_indexed_stream(m_instance.Handle, s, index, out error); + } + + public void DisableAllStreams() + { + object error; + NativeMethods.rs2_config_disable_all_streams(m_instance.Handle, out error); + } + + public bool CanResolve(Pipeline pipe) + { + object error; + var res = NativeMethods.rs2_config_can_resolve(m_instance.Handle, pipe.m_instance.Handle, out error); + return res > 0; + } + + public PipelineProfile Resolve(Pipeline pipe) + { + object error; + var res = NativeMethods.rs2_config_resolve(m_instance.Handle, pipe.m_instance.Handle, out error); + return new PipelineProfile(res); + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~Config() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + if (m_instance.Handle != IntPtr.Zero) + NativeMethods.rs2_delete_config(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + } +} diff --git a/Intel.RealSense/Processing.cs b/Intel.RealSense/Processing.cs new file mode 100644 index 0000000..2f286a4 --- /dev/null +++ b/Intel.RealSense/Processing.cs @@ -0,0 +1,336 @@ +using System; +using System.Runtime.InteropServices; +using System.Linq; + +namespace Intel.RealSense +{ + public class ProcessingBlock : IDisposable + { + internal HandleRef m_instance; + + Sensor.SensorOptions m_options; + public Sensor.SensorOptions Options + { + get + { + return m_options = m_options ?? new Sensor.SensorOptions(m_instance.Handle); + } + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~ProcessingBlock() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + if (m_instance.Handle != IntPtr.Zero) + NativeMethods.rs2_delete_processing_block(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + } + + public class Colorizer : ProcessingBlock + { + public Colorizer() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_colorizer(out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public VideoFrame Colorize(VideoFrame original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame); + } + + FrameQueue queue; + } + + public class Align : ProcessingBlock + { + public Align(Stream align_to) + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_align(align_to, out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public FrameSet Process(FrameSet original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrames() as FrameSet); + } + + FrameQueue queue; + } + + public class DisparityTransform : ProcessingBlock + { + public DisparityTransform(bool transform_to_disparity = true) + { + object error; + byte transform_direction = transform_to_disparity ? (byte)1 : (byte)0; + m_instance = new HandleRef(this, NativeMethods.rs2_create_disparity_transform_block(transform_direction, out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame); + } + + FrameQueue queue; + } + + public class DecimationFilter : ProcessingBlock + { + public DecimationFilter() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_decimation_filter_block(out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame); + } + + FrameQueue queue; + } + + public class SpatialFilter : ProcessingBlock + { + public SpatialFilter() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_spatial_filter_block(out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame); + } + + FrameQueue queue; + } + + public class TemporalFilter : ProcessingBlock + { + public TemporalFilter() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_temporal_filter_block(out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public VideoFrame ApplyFilter(VideoFrame original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as VideoFrame); + } + + FrameQueue queue; + } + + public class HoleFillingFilter : ProcessingBlock + { + public HoleFillingFilter() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_hole_filling_filter_block(out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public VideoFrame ApplyFilter(VideoFrame original) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return queue.WaitForFrame() as VideoFrame; + } + + FrameQueue queue; + } + + public class PointCloud : ProcessingBlock + { + FrameQueue queue; + + public PointCloud() + { + object error; + m_instance = new HandleRef(this, NativeMethods.rs2_create_pointcloud(out error)); + queue = new FrameQueue(); + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + } + + public Points Calculate(Frame original, FramesReleaser releaser = null) + { + object error; + NativeMethods.rs2_frame_add_ref(original.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, original.m_instance.Handle, out error); + return FramesReleaser.ScopedReturn(releaser, queue.WaitForFrame() as Points); + } + + public void MapTexture(VideoFrame texture) + { + object error; + Options[Option.TextureSource].Value = Convert.ToSingle(texture.Profile.UniqueID); + NativeMethods.rs2_frame_add_ref(texture.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, texture.m_instance.Handle, out error); + } + } + + public class FrameSource + { + internal HandleRef m_instance; + + internal FrameSource(HandleRef instance) + { + m_instance = instance; + } + + public FrameSet AllocateCompositeFrame(FramesReleaser releaser, params Frame[] frames) + { + object error; + var frame_refs = frames.Select(x => x.m_instance.Handle).ToArray(); + foreach (var fref in frame_refs) NativeMethods.rs2_frame_add_ref(fref, out error); + var frame_ref = NativeMethods.rs2_allocate_composite_frame(m_instance.Handle, frame_refs, frames.Count(), out error); + return FramesReleaser.ScopedReturn(releaser, new FrameSet(frame_ref)); + } + + public FrameSet AllocateCompositeFrame(params Frame[] frames) + { + return AllocateCompositeFrame(null, frames); + } + + public void FrameReady(Frame f) + { + object error; + NativeMethods.rs2_frame_add_ref(f.m_instance.Handle, out error); + NativeMethods.rs2_synthetic_frame_ready(m_instance.Handle, f.m_instance.Handle, out error); + } + + public void FramesReady(FrameSet fs) + { + using (var f = fs.AsFrame()) + FrameReady(f); + } + } + + public class CustomProcessingBlock : ProcessingBlock + { + public delegate void FrameProcessorCallback(Frame frame, FrameSource source); + + public CustomProcessingBlock(FrameProcessorCallback cb) + { + object error; + frame_processor_callback cb2 = (IntPtr f, IntPtr src, IntPtr u) => + { + using (var frame = new Frame(f)) + cb(frame, new FrameSource(new HandleRef(this, src))); + }; + m_proc_callback = cb2; + m_instance = new HandleRef(this, NativeMethods.rs2_create_processing_block_fptr(cb2, IntPtr.Zero, out error)); + } + + public void ProcessFrame(Frame f) + { + object error; + NativeMethods.rs2_frame_add_ref(f.m_instance.Handle, out error); + NativeMethods.rs2_process_frame(m_instance.Handle, f.m_instance.Handle, out error); + } + + public void ProcessFrames(FrameSet fs) + { + using (var f = fs.AsFrame()) + ProcessFrame(f); + } + + public void Start(FrameQueue queue) + { + object error; + NativeMethods.rs2_start_processing_queue(m_instance.Handle, queue.m_instance.Handle, out error); + + m_callback = null; + m_queue = queue; + } + + //public delegate void FrameCallback(Frame frame, T user_data); + public delegate void FrameCallback(Frame frame); + + public void Start(FrameCallback cb) + { + object error; + frame_callback cb2 = (IntPtr f, IntPtr u) => + { + using (var frame = new Frame(f)) + cb(frame); + }; + NativeMethods.rs2_start_processing_fptr(m_instance.Handle, cb2, IntPtr.Zero, out error); + m_callback = cb2; + m_queue = null; + } + + private frame_callback m_callback = null; + private frame_processor_callback m_proc_callback = null; + private FrameQueue m_queue = null; + } +} \ No newline at end of file diff --git a/Intel.RealSense/Properties/AssemblyInfo.cs b/Intel.RealSense/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ab1f498 --- /dev/null +++ b/Intel.RealSense/Properties/AssemblyInfo.cs @@ -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("Intel.RealSense")] +[assembly: AssemblyDescription(".NET Wrapper for Intel RealSense SDK 2.0")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Intel")] +[assembly: AssemblyProduct("Intel.RealSense")] +[assembly: AssemblyCopyright("Copyright 2017")] +[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("e488694f-f2fa-45ad-b1b8-8d4fabe34e86")] + +// 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")] \ No newline at end of file diff --git a/Intel.RealSense/Sensor.cs b/Intel.RealSense/Sensor.cs new file mode 100644 index 0000000..4161b7b --- /dev/null +++ b/Intel.RealSense/Sensor.cs @@ -0,0 +1,399 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Linq; + +namespace Intel.RealSense +{ + public class SensorList : IDisposable, IEnumerable + { + IntPtr m_instance; + + public SensorList(IntPtr ptr) + { + m_instance = ptr; + } + + + public IEnumerator GetEnumerator() + { + object error; + + int sensorCount = NativeMethods.rs2_get_sensors_count(m_instance, out error); + for (int i = 0; i < sensorCount; i++) + { + var ptr = NativeMethods.rs2_create_sensor(m_instance, i, out error); + yield return new Sensor(ptr); + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get + { + object error; + int deviceCount = NativeMethods.rs2_get_sensors_count(m_instance, out error); + return deviceCount; + } + } + + public Sensor this[int index] + { + get + { + object error; + var ptr = NativeMethods.rs2_create_sensor(m_instance, index, out error); + return new Sensor(ptr); + } + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + NativeMethods.rs2_delete_sensor_list(m_instance); + m_instance = IntPtr.Zero; + + disposedValue = true; + } + } + + //TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~SensorList() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + } + + public class Sensor + { + public IntPtr m_instance; + + internal Sensor(IntPtr sensor) + { + //if (sensor == IntPtr.Zero) + // throw new ArgumentNullException(); + m_instance = sensor; + } + + public class CameraInfos + { + IntPtr m_sensor; + public CameraInfos(IntPtr sensor) { m_sensor = sensor; } + + public string this[CameraInfo info] + { + get + { + object err; + if (NativeMethods.rs2_supports_sensor_info(m_sensor, info, out err) > 0) + return Marshal.PtrToStringAnsi(NativeMethods.rs2_get_sensor_info(m_sensor, info, out err)); + return null; + } + } + } + + CameraInfos m_info; + + public CameraInfos Info + { + get + { + if (m_info == null) + m_info = new CameraInfos(m_instance); + return m_info; + } + } + + + public class CameraOption + { + IntPtr m_sensor; + Option option; + + private readonly float min; + private readonly float max; + private readonly float step; + private readonly float @default; + + public CameraOption(IntPtr sensor, Option option) + { + m_sensor = sensor; + this.option = option; + + if (Supported) + { + object error; + NativeMethods.rs2_get_option_range(m_sensor, option, out min, out max, out step, out @default, out error); + } + } + + public bool Supported + { + get + { + try + { + object error; + return NativeMethods.rs2_supports_option(m_sensor, option, out error) > 0; + } + catch (Exception) + { + return false; + } + } + } + + public Option Key + { + get + { + return option; + } + } + + public float Value + { + get + { + object error; + return NativeMethods.rs2_get_option(m_sensor, option, out error); + } + set + { + object error; + NativeMethods.rs2_set_option(m_sensor, option, value, out error); + } + } + + public string ValueDescription + { + get + { + object error; + var str = NativeMethods.rs2_get_option_value_description(m_sensor, option, Value, out error); + return Marshal.PtrToStringAnsi(str); + } + } + + public float Min + { + get + { + return min; + } + } + + public float Max + { + get + { + return max; + } + } + + public float Step + { + get + { + return step; + } + } + + public float Default + { + get + { + return @default; + } + } + + public bool ReadOnly + { + get + { + object error; + return NativeMethods.rs2_is_option_read_only(m_sensor, option, out error) != 0; + } + } + } + + public class SensorOptions : IEnumerable + { + IntPtr m_sensor; + public SensorOptions(IntPtr sensor) + { + m_sensor = sensor; + } + + public CameraOption this[Option option] + { + get + { + return new CameraOption(m_sensor, option); + } + } + public string OptionValueDescription(Option option, float value) + { + object error; + var desc = NativeMethods.rs2_get_option_value_description(m_sensor, option, value, out error); + if(desc != null) + { + return Marshal.PtrToStringAnsi(desc); + } + return null; + } + public IEnumerator GetEnumerator() + { + var values = Enum.GetValues(typeof(Option)) as Option[]; + foreach (var v in values) + { + if (this[v].Supported) + yield return this[v]; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + } + SensorOptions m_options; + public SensorOptions Options + { + get + { + return m_options = m_options ?? new SensorOptions(m_instance); + } + } + + /// + /// open subdevice for exclusive access, by commiting to a configuration + /// + /// + public void Open(StreamProfile profile) + { + object error; + NativeMethods.rs2_open(m_instance, profile.m_instance.Handle, out error); + + } + + /// + /// open subdevice for exclusive access, by commiting to composite configuration, specifying one or more stream profiles + /// this method should be used for interdendent streams, such as depth and infrared, that have to be configured together + /// + /// + public void Open(params StreamProfile[] profiles) + { + object error; + IntPtr[] handles = new IntPtr[profiles.Length]; + for (int i = 0; i < profiles.Length; i++) + handles[i] = profiles[i].m_instance.Handle; + NativeMethods.rs2_open_multiple(m_instance, handles, profiles.Length, out error); + } + + public void Start(FrameQueue queue) + { + object error; + NativeMethods.rs2_start_queue(m_instance, queue.m_instance.Handle, out error); + m_queue = queue; + m_callback = null; + } + + //public delegate void FrameCallback(Frame frame, T user_data); + public delegate void FrameCallback(Frame frame); + + public void Start(FrameCallback cb) + { + object error; + frame_callback cb2 = (IntPtr f, IntPtr u) => + { + using (var frame = new Frame(f)) + cb(frame); + }; + m_callback = cb2; + m_queue = null; + NativeMethods.rs2_start(m_instance, cb2, IntPtr.Zero, out error); + } + + public void Stop() + { + object error; + NativeMethods.rs2_stop(m_instance, out error); + m_callback = null; + m_queue = null; + } + + /// + /// close subdevice for exclusive access this method should be used for releasing device resource + /// + public void Close() + { + object error; + NativeMethods.rs2_close(m_instance, out error); + } + + /// + /// retrieve mapping between the units of the depth image and meters + /// + /// depth in meters corresponding to a depth value of 1 + public float DepthScale + { + get + { + object error; + return NativeMethods.rs2_get_depth_scale(m_instance, out error); + } + } + + + public StreamProfileList StreamProfiles + { + get + { + object error; + return new StreamProfileList(NativeMethods.rs2_get_stream_profiles(m_instance, out error)); + } + } + + + public IEnumerable VideoStreamProfiles + { + get + { + return StreamProfiles.Where(p => p is VideoStreamProfile).Select(p => p as VideoStreamProfile); + } + } + + private frame_callback m_callback; + private FrameQueue m_queue; + } + +} diff --git a/Intel.RealSense/StreamProfile.cs b/Intel.RealSense/StreamProfile.cs new file mode 100644 index 0000000..fa50635 --- /dev/null +++ b/Intel.RealSense/StreamProfile.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; + +namespace Intel.RealSense +{ + public class StreamProfileList : IDisposable, IEnumerable + { + IntPtr m_instance; + + public StreamProfileList(IntPtr ptr) + { + m_instance = ptr; + } + + + public IEnumerator GetEnumerator() + { + object error; + + int deviceCount = NativeMethods.rs2_get_stream_profiles_count(m_instance, out error); + for (int i = 0; i < deviceCount; i++) + { + var ptr = NativeMethods.rs2_get_stream_profile(m_instance, i, out error); + + if (NativeMethods.rs2_stream_profile_is(ptr, Extension.VideoProfile, out error) > 0) + yield return new VideoStreamProfile(ptr); + else + yield return new StreamProfile(ptr); + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public int Count + { + get + { + object error; + int deviceCount = NativeMethods.rs2_get_stream_profiles_count(m_instance, out error); + return deviceCount; + } + } + + public StreamProfile this[int index] + { + get + { + object error; + var ptr = NativeMethods.rs2_get_stream_profile(m_instance, index, out error); + if (NativeMethods.rs2_stream_profile_is(ptr, Extension.VideoProfile, out error) > 0) + return new VideoStreamProfile(ptr); + else + return new StreamProfile(ptr); + } + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + NativeMethods.rs2_delete_stream_profiles_list(m_instance); + m_instance = IntPtr.Zero; + + disposedValue = true; + } + } + + //TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~StreamProfileList() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + } + + public class StreamProfile : IDisposable + { + internal HandleRef m_instance; + + public StreamProfile(IntPtr ptr) + { + //if (ptr == IntPtr.Zero) + // throw new ArgumentNullException("ptr"); + m_instance = new HandleRef(this, ptr); + + object e; + Stream stream; + Format fmt; + int fps; + int idx; + int uid; + + NativeMethods.rs2_get_stream_profile_data(m_instance.Handle, out stream, out fmt, out idx, out uid, out fps, out e); + + Stream = stream; + Format = fmt; + Framerate = fps; + Index = idx; + UniqueID = uid; + } + + public Stream Stream { get; private set; } + public Format Format { get; private set; } + + public int Framerate { get; private set; } + + public int Index { get; private set; } + + public int UniqueID { get; private set; } + + public Extrinsics GetExtrinsicsTo(StreamProfile other) + { + object error; + Extrinsics extrinsics; + NativeMethods.rs2_get_extrinsics(m_instance.Handle, other.m_instance.Handle, out extrinsics, out error); + return extrinsics; + } + + #region IDisposable Support + private bool disposedValue = false; // To detect redundant calls + + protected virtual void Dispose(bool disposing) + { + if (!disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects). + } + + // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. + // TODO: set large fields to null. + Release(); + disposedValue = true; + } + } + + // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources. + ~StreamProfile() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(false); + } + + // This code added to correctly implement the disposable pattern. + public void Dispose() + { + // Do not change this code. Put cleanup code in Dispose(bool disposing) above. + Dispose(true); + // TODO: uncomment the following line if the finalizer is overridden above. + GC.SuppressFinalize(this); + } + #endregion + + public void Release() + { + //if(m_instance.Handle != IntPtr.Zero) + //NativeMethods.rs2_delete_str(m_instance.Handle); + m_instance = new HandleRef(this, IntPtr.Zero); + } + } + + public class VideoStreamProfile : StreamProfile + { + public VideoStreamProfile(IntPtr ptr) : base(ptr) + { + int width; + int height; + + object error; + NativeMethods.rs2_get_video_stream_resolution(ptr, out width, out height, out error); + + Width = width; + Height = height; + } + + public Intrinsics GetIntrinsics() + { + object error; + Intrinsics intrinsics; + NativeMethods.rs2_get_video_stream_intrinsics(m_instance.Handle, out intrinsics, out error); + return intrinsics; + } + + public int Width { get; private set; } + + public int Height { get; private set; } + + } +} diff --git a/Intel.RealSense/Types.cs b/Intel.RealSense/Types.cs new file mode 100644 index 0000000..2837b75 --- /dev/null +++ b/Intel.RealSense/Types.cs @@ -0,0 +1,275 @@ +using System; +using System.Runtime.InteropServices; + +namespace Intel.RealSense +{ + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void frame_callback(IntPtr frame, IntPtr user_data); + //public delegate void frame_callback([Out, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FrameMarshaler))] out Frame frame, IntPtr user_data); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void frame_processor_callback(IntPtr frame, IntPtr user, IntPtr user_data); + + public enum NotificationCategory + { + FramesTimeout = 0, + FrameCorrupted = 1, + HardwareError = 2, + UnknownError = 3, + } + + public enum ExceptionType + { + Unknown = 0, + CameraDisconnected = 1, + Backend = 2, + InvalidValue = 3, + WrongApiCallSequence = 4, + NotImplemented = 5, + DeviceInRecoveryMode = 6, + Io = 7, + } + + public enum Distortion + { + None = 0, + ModifiedBrownConrady = 1, + InverseBrownConrady = 2, + Ftheta = 3, + BrownConrady = 4, + } + + public enum LogSeverity + { + Debug = 0, + Info = 1, + Warn = 2, + Error = 3, + Fatal = 4, + None = 5, + } + + public enum Extension + { + Unknown = 0, + Debug = 1, + Info = 2, + Motion = 3, + Options = 4, + Video = 5, + Roi = 6, + DepthSensor = 7, + VideoFrame = 8, + MotionFrame = 9, + CompositeFrame = 10, + Points = 11, + DepthFrame = 12, + AdvancedMode = 13, + Record = 14, + VideoProfile = 15, + Playback = 16, + } + + public enum CameraInfo + { + Name = 0, + SerialNumber = 1, + FirmwareVersion = 2, + PhysicalPort = 3, + DebugOpCode = 4, + AdvancedMode = 5, + ProductId = 6, + CameraLocked = 7, + } + + public enum Stream + { + Any = 0, + Depth = 1, + Color = 2, + Infrared = 3, + Fisheye = 4, + Gyro = 5, + Accel = 6, + Gpio = 7, + Pose = 8, + Confidence = 9, + } + + public enum Format + { + Any = 0, + Z16 = 1, + Disparity16 = 2, + Xyz32f = 3, + Yuyv = 4, + Rgb8 = 5, + Bgr8 = 6, + Rgba8 = 7, + Bgra8 = 8, + Y8 = 9, + Y16 = 10, + Raw10 = 11, + Raw16 = 12, + Raw8 = 13, + Uyvy = 14, + MotionRaw = 15, + MotionXyz32f = 16, + GpioRaw = 17, + } + + public enum TimestampDomain + { + HardwareClock = 0, + SystemTime = 1, + } + + public enum FrameMetadataValue + { + Rs2FrameMetadataFrameCounter = 0, + Rs2FrameMetadataFrameTimestamp = 1, + Rs2FrameMetadataSensorTimestamp = 2, + Rs2FrameMetadataActualExposure = 3, + Rs2FrameMetadataGainLevel = 4, + Rs2FrameMetadataAutoExposure = 5, + Rs2FrameMetadataWhiteBalance = 6, + Rs2FrameMetadataTimeOfArrival = 7, + Rs2FrameMetadataBackendTimestamp= 8, + Rs2FrameMetadataActualFps = 9, + Rs2FrameMetadataCount = 10, + } + + public enum Option + { + BacklightCompensation = 0, + Brightness = 1, + Contrast = 2, + Exposure = 3, + Gain = 4, + Gamma = 5, + Hue = 6, + Saturation = 7, + Sharpness = 8, + WhiteBalance = 9, + EnableAutoExposure = 10, + EnableAutoWhiteBalance = 11, + VisualPreset = 12, + LaserPower = 13, + Accuracy = 14, + MotionRange = 15, + FilterOption = 16, + ConfidenceThreshold = 17, + EmitterEnabled = 18, + FramesQueueSize = 19, + TotalFrameDrops = 20, + AutoExposureMode = 21, + PowerLineFrequency = 22, + AsicTemperature = 23, + ErrorPollingEnabled = 24, + ProjectorTemperature = 25, + OutputTriggerEnabled = 26, + MotionModuleTemperature = 27, + DepthUnits = 28, + EnableMotionCorrection = 29, + AutoExposurePriority = 30, + ColorScheme = 31, + HistogramEqualizationEnabled = 32, + MinDistance = 33, + MaxDistance = 34, + TextureSource = 35, + FilterMagnitude = 36, + FilterSmoothAlpha = 37, + FilterSmoothDelta = 38, + HolesFill = 39, + StereoBaseline = 40, + AutoExposureConvergeStep = 41, + } + + public enum Sr300VisualPreset + { + ShortRange = 0, + LongRange = 1, + BackgroundSegmentation = 2, + GestureRecognition = 3, + ObjectScanning = 4, + FaceAnalytics = 5, + FaceLogin = 6, + GrCursor = 7, + Default = 8, + MidRange = 9, + IrOnly = 10, + } + + public enum Rs400VisualPreset + { + Custom = 0, + ShortRange = 1, + Hand = 2, + HighAccuracy = 3, + HighDensity = 4, + MediumDensity = 5, + } + + public enum PlaybackStatus + { + Unknown = 0, + Playing = 1, + Paused = 2, + Stopped = 3, + } + + public enum RecordingMode + { + BlankFrames = 0, + Compressed = 1, + BestQuality = 2, + } + + + /// + /// Video stream intrinsics + /// + [System.Serializable] + [StructLayout(LayoutKind.Sequential)] + public struct Intrinsics + { + public int width; /** Width of the image in pixels */ + public int height; /** Height of the image in pixels */ + public float ppx; /** Horizontal coordinate of the principal point of the image, as a pixel offset from the left edge */ + public float ppy; /** Vertical coordinate of the principal point of the image, as a pixel offset from the top edge */ + public float fx; /** Focal length of the image plane, as a multiple of pixel width */ + public float fy; /** Focal length of the image plane, as a multiple of pixel height */ + public Distortion model; /** Distortion model of the image */ + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)] + public float[] coeffs; /** Distortion coefficients */ + + public override string ToString() + { + return String.Format("(width:{0}, height:{1}, ppx:{2}, ppy:{3}, fx:{4}, fy:{5}, model:{6}, coeffs:[{7}])", + width, + height, + ppx, + ppy, + fx, + fy, + model, + String.Join(", ", Array.ConvertAll(coeffs, Convert.ToString)) + ); + } + } + + /// + /// Cross-stream extrinsics: encode the topology describing how the different devices are connected. + /// + [System.Serializable] + [StructLayout(LayoutKind.Sequential)] + public struct Extrinsics + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 9)] + public float[] rotation; // Column-major 3x3 rotation matrix + + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] + public float[] translation; // Three-element translation vector, in meters + } +} diff --git a/Sources/Video/RealSenseNetworkStream.cs b/Sources/Video/RealSenseNetworkStream.cs index 68318b2..8e4d27c 100644 --- a/Sources/Video/RealSenseNetworkStream.cs +++ b/Sources/Video/RealSenseNetworkStream.cs @@ -10,6 +10,7 @@ using iSpyApplication.Sources.Audio; using iSpyApplication.Utilities; using NAudio.Wave; using NAudio.Wave.SampleProviders; +using System.IO.Compression; namespace iSpyApplication.Sources.Video { @@ -26,6 +27,8 @@ namespace iSpyApplication.Sources.Video public event NewFrameEventHandler NewFrame; public event PlayingFinishedEventHandler PlayingFinished; private bool _disposed; + Info message = new Info(); + byte[] headBuffer = new byte[4]; public string Source { @@ -113,57 +116,78 @@ namespace iSpyApplication.Sources.Video private void WorkerThread() { _abort = new ManualResetEvent(false); - byte[] buffer1 = new byte[1024 * 1024 * 1024]; - var stream = new MemoryStream(buffer1); - var reader = new BinaryReader(stream); - Info message = new Info(); while (true) { - int size = newclient.Receive(buffer1, 4, 0); - stream.Position = 0; - size = reader.ReadInt32(); - int msgSize = 0; - do + int size = newclient.Receive(headBuffer, 4, 0); + using (var headStream = new MemoryStream(headBuffer)) { - msgSize += newclient.Receive(buffer1, msgSize, size - msgSize, SocketFlags.None); - } while (msgSize < size); - stream.Position = 0; - stream.SetLength(msgSize); - message.width = reader.ReadInt32(); - message.height = reader.ReadInt32(); - if (message.colorframe == null) - message.colorframe = new byte[message.width * message.height * 3]; - reader.Read(message.colorframe, 0, message.colorframe.Length); - //message.depthframe = reader.ReadBytes(message.width * message.height * 2); - //int peopleCount = reader.ReadInt32(); - //if (peopleCount > 0) - //{ - // message.people = new float[peopleCount * 2]; - // for (int i = 0; i < peopleCount * 2; ++i) - // message.people[i] = reader.ReadSingle(); - //} - using (Bitmap img = new Bitmap(message.width, message.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) + using (var headReader = new BinaryReader(headStream)) + { + headStream.Position = 0; + size = headReader.ReadInt32(); + byte[] zipStreamBuffer = new byte[size]; + int msgSize = 0; + do + { + msgSize += newclient.Receive(zipStreamBuffer, msgSize, size - msgSize, SocketFlags.None); + } while (msgSize < size); + + using (var stream = new MemoryStream(zipStreamBuffer)) + { + using (var reader = new BinaryReader(stream)) + { + stream.Position = 0; + if (stream.Length != 0) + { + Decompress(stream); + } + using (Bitmap img = new Bitmap(message.width, message.height, System.Drawing.Imaging.PixelFormat.Format24bppRgb)) + { + var data = img.LockBits(new Rectangle(0, 0, message.width, message.height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); + System.Runtime.InteropServices.Marshal.Copy(message.colorframe, 0, data.Scan0, message.colorframe.Length); + img.UnlockBits(data); + var dae = new NewFrameEventArgs(img); + NewFrame.Invoke(this, dae); + } + } + } + } + } + } + + + } + + public void Decompress(MemoryStream compressStream) + { + compressStream.Position = 0; + using (var zipStream = new GZipStream(compressStream, System.IO.Compression.CompressionMode.Decompress)) + { + using (var resultStream = new MemoryStream()) { - var data = img.LockBits(new Rectangle(0, 0, message.width, message.height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); - System.Runtime.InteropServices.Marshal.Copy(message.colorframe, 0, data.Scan0, message.colorframe.Length); - img.UnlockBits(data); - var dae = new NewFrameEventArgs(img); - NewFrame.Invoke(this, dae); + zipStream.CopyTo(resultStream); + + using (var reader = new BinaryReader(resultStream)) + { + resultStream.Position = 0; + message.width = reader.ReadInt32(); + message.height = reader.ReadInt32(); + if (message.colorframe == null) + message.colorframe = new byte[message.width * message.height * 3]; + reader.Read(message.colorframe, 0, message.colorframe.Length); + //message.depthframe = reader.ReadBytes(message.width * message.height * 2); + //int peopleCount = reader.ReadInt32(); + //if (peopleCount > 0) + //{ + // message.people = new float[peopleCount * 2]; + // for (int i = 0; i < peopleCount * 2; ++i) + // message.people[i] = reader.ReadSingle(); + //} + } } } - PlayingFinished?.Invoke(this, new PlayingFinishedEventArgs(_res)); - _abort.Close(); } - //private void WorkerThread() - //{ - // while (true) - // { - // Bitmap img = new Bitmap(@"D:\123.jpg"); - // var dae = new NewFrameEventArgs(img); - // NewFrame.Invoke(this, dae); - // } - //} protected virtual void Dispose(bool disposing) { if (_disposed) diff --git a/cs-tutorial-2-capture/Program.cs b/cs-tutorial-2-capture/Program.cs new file mode 100644 index 0000000..2357f31 --- /dev/null +++ b/cs-tutorial-2-capture/Program.cs @@ -0,0 +1,16 @@ +using System; +using System.Linq; + +namespace Intel.RealSense +{ + class Program + { + [STAThread] + static void Main(string[] args) + { + SocketServer.Connect(); + var w = new CaptureWindow(); + w.ShowDialog(); + } + } +} diff --git a/cs-tutorial-2-capture/SocketServer.cs b/cs-tutorial-2-capture/SocketServer.cs new file mode 100644 index 0000000..8876ac6 --- /dev/null +++ b/cs-tutorial-2-capture/SocketServer.cs @@ -0,0 +1,121 @@ +using System.Collections; +using System.Collections.Generic; +using System.Net.Sockets; +using System.Net; +using System; +using System.IO; +using System.Runtime.Serialization.Json; +using System.Text; +using System.IO.Compression; +using System.Threading; + +namespace Intel.RealSense +{ + + public class SocketServer + { + + static List socketList = new List(); + static Socket client; + + public static void Connect() + { + Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); + IPAddress ip = new IPAddress(new byte[] { 192, 168, 0, 168 });//169, 254, 202, 67 + int port = 6000; + EndPoint point = new IPEndPoint(ip, port);//封装保存IP和端口号 + + server.Bind(point);//把IP和端口号保存到服务端socket对象 + server.Listen(10);//监听服务端 + server.BeginAccept(new AsyncCallback(AcceptClient), server); + } + // Use this for initialization + static void AcceptClient(IAsyncResult ar) + { + Socket myserver = ar.AsyncState as Socket; + client = myserver.EndAccept(ar);//保存异步连接的客户端 + socketList.Add(client); + Thread t = new Thread(ReceiveMsg); + t.Start(client); + } + + public static void SendMsg(Info info) + { + if (client != null) + { + using (MemoryStream contentStream = new MemoryStream()) + { + using (BinaryWriter contentWriter = new BinaryWriter(contentStream)) + { + contentStream.Position = 0; + contentWriter.Write(info.width); + contentWriter.Write(info.height); + contentWriter.Write(info.colorframe); + contentWriter.Write(info.depthframe); + + using (MemoryStream compressedStream = new MemoryStream()) + { + using (System.IO.Compression.GZipStream zipStream = new System.IO.Compression.GZipStream(compressedStream, System.IO.Compression.CompressionMode.Compress, true)) + { + zipStream.Write(contentStream.GetBuffer(), 0, (int)contentStream.Length); + } + + using (MemoryStream stream = new MemoryStream()) + { + using (BinaryWriter writer = new BinaryWriter(stream)) + { + stream.Position = 0; + byte[] buffer = compressedStream.GetBuffer(); + writer.Write(buffer.Length); + writer.Write(buffer); + byte[] streamBuffer = stream.GetBuffer(); + client.BeginSend(streamBuffer, 0, streamBuffer.Length, SocketFlags.None, null, null); + } + + } + } + } + } + + Thread.Sleep(50); + } + } + + static void ReceiveMsg(Object socket) + { + Socket mySocket = socket as Socket; + while (true) + { + byte[] buffer = new byte[1024]; + int length = 0; + try + { + length = mySocket.Receive(buffer); + } + catch (Exception e) + { + Console.WriteLine("Exception:" + e.Message);//显示异常信息 + IPEndPoint point = mySocket.RemoteEndPoint as IPEndPoint; + string ipp = point.Address.ToString(); + Console.WriteLine(ipp + "退出回话"); + socketList.Remove(mySocket); + // sendAllMsg(ipp + "有人退出回话"); + break; + } + + string resMsg = Encoding.UTF8.GetString(buffer, 0, length); + + //resMsg = mySocket.RemoteEndPoint.ToString() + ":" + resMsg; + IPEndPoint po = mySocket.RemoteEndPoint as IPEndPoint; + string ip = po.Address.ToString(); + resMsg = ip + ":" + resMsg; + Console.WriteLine(resMsg); + //sendAllMsg(resMsg); + + + + } + + } + } +} diff --git a/cs-tutorial-2-capture/Window.xaml b/cs-tutorial-2-capture/Window.xaml new file mode 100644 index 0000000..c8d3d06 --- /dev/null +++ b/cs-tutorial-2-capture/Window.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + diff --git a/cs-tutorial-2-capture/Window.xaml.cs b/cs-tutorial-2-capture/Window.xaml.cs new file mode 100644 index 0000000..79faa52 --- /dev/null +++ b/cs-tutorial-2-capture/Window.xaml.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Intel.RealSense +{ + /// + /// Interaction logic for Window.xaml + /// + public partial class CaptureWindow : Window + { + private Pipeline pipeline; + private Colorizer colorizer; + private CancellationTokenSource tokenSource = new CancellationTokenSource(); + Info info = new Info(); + + private void UploadImage(Image img, VideoFrame frame) + { + Dispatcher.Invoke(new Action(() => + { + if (frame.Width == 0) return; + + var bytes = new byte[frame.Stride * frame.Height]; + frame.CopyTo(bytes); + + var bs = BitmapSource.Create(frame.Width, frame.Height, + 300, 300, + PixelFormats.Rgb24, + null, + bytes, + frame.Stride); + + var imgSrc = bs as ImageSource; + + img.Source = imgSrc; + })); + } + + public CaptureWindow() + { + try + { + pipeline = new Pipeline(); + + var cfg = new Config(); + cfg.EnableStream(Stream.Depth, 640, 480, Format.Z16, 30); + cfg.EnableStream(Stream.Color, 640, 480, Format.Rgb8, 30); + + pipeline.Start(cfg); + + var token = tokenSource.Token; + + var t = Task.Factory.StartNew(() => + { + while (!token.IsCancellationRequested) + { + var frames = pipeline.WaitForFrames(); + + var depth_frame = frames.DepthFrame; + var color_frame = frames.ColorFrame; + + if (info.colorframe == null) + info.colorframe = new byte[color_frame.Stride * color_frame.Height]; + if (info.depthframe == null) + info.depthframe = new byte[depth_frame.Stride * depth_frame.Height]; + color_frame.CopyTo(info.colorframe); + depth_frame.CopyTo(info.depthframe); + info.width = color_frame.Width; + info.height = color_frame.Height; + + SocketServer.SendMsg(info); + //UploadImage(imgDepth, colorized_depth); + //UploadImage(imgColor, color_frame); + foreach (var item in frames) + { + item.Dispose(); + } + + + // It is important to pre-emptively dispose of native resources + // to avoid creating bottleneck at finalization stage after GC + // (Also see FrameReleaser helper object in next tutorial) + frames.Dispose(); + depth_frame.Dispose(); + color_frame.Dispose(); + } + }, token); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + Application.Current.Shutdown(); + } + + InitializeComponent(); + } + + private void control_Closing(object sender, System.ComponentModel.CancelEventArgs e) + { + tokenSource.Cancel(); + } + } + + public class Info + { + //public string msg { get; set; } + public int width; + public int height; + public byte[] colorframe { get; set; } + public byte[] depthframe { get; set; } + + public float[] people { get; set; } + } +} diff --git a/cs-tutorial-2-capture/app.config b/cs-tutorial-2-capture/app.config new file mode 100644 index 0000000..ff99501 --- /dev/null +++ b/cs-tutorial-2-capture/app.config @@ -0,0 +1,3 @@ + + + diff --git a/cs-tutorial-2-capture/cs-tutorial-2-capture.csproj b/cs-tutorial-2-capture/cs-tutorial-2-capture.csproj new file mode 100644 index 0000000..bb78490 --- /dev/null +++ b/cs-tutorial-2-capture/cs-tutorial-2-capture.csproj @@ -0,0 +1,129 @@ + + + + + Debug + AnyCPU + {4E200124-E140-40A7-83B1-625E4817198C} + WinExe + Properties + Intel.RealSense + cs-tutorial-2-capture + v4.5.2 + 512 + true + + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + true + . + TRACE + prompt + 4 + false + + + true + ..\bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + 4 + false + true + + + ..\bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + 4 + + + true + ..\bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + false + + + ..\bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + Intel.RealSense.Program + ..\Intel.RealSense\bin\$(Configuration) + $(LibDirectory)\net35 + + + + False + $(LibDirectory)\Intel.RealSense.dll + + + PreserveNewest + + + + + + + + + + + + + + Window.xaml + + + + + + + + + + + Designer + MSBuild:Compile + + + + + \ No newline at end of file diff --git a/iSpy64.sln b/iSpy64.sln index 8281c65..93f7cde 100644 --- a/iSpy64.sln +++ b/iSpy64.sln @@ -19,6 +19,10 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "Bootstrap64", "Wix\Bootstra EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WixCA", "Wix\WixCA\WixCA.csproj", "{27624167-C034-4349-B30F-CD18934D8737}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "cs-tutorial-2-capture", "cs-tutorial-2-capture\cs-tutorial-2-capture.csproj", "{4E200124-E140-40A7-83B1-625E4817198C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Intel.RealSense.2015", "Intel.RealSense\Intel.RealSense.2015.csproj", "{E488694F-F2FA-45AD-B1B8-8D4FABE34E86}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution ARM|Any CPU = ARM|Any CPU @@ -273,6 +277,126 @@ Global {27624167-C034-4349-B30F-CD18934D8737}.SingleImage|x64.Build.0 = Release|x86 {27624167-C034-4349-B30F-CD18934D8737}.SingleImage|x86.ActiveCfg = Release|x86 {27624167-C034-4349-B30F-CD18934D8737}.SingleImage|x86.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|Any CPU.ActiveCfg = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|Any CPU.Build.0 = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|Mixed Platforms.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|Mixed Platforms.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|Win32.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|Win32.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|x64.ActiveCfg = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|x64.Build.0 = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|x86.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.ARM|x86.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|Any CPU.Build.0 = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|Mixed Platforms.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|Mixed Platforms.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|Win32.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|Win32.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|x64.ActiveCfg = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|x64.Build.0 = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|x86.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.CD_ROM|x86.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|Win32.ActiveCfg = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|Win32.Build.0 = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|x64.ActiveCfg = Debug|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|x64.Build.0 = Debug|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|x86.ActiveCfg = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Debug|x86.Build.0 = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|Any CPU.Build.0 = Debug|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|Mixed Platforms.ActiveCfg = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|Mixed Platforms.Build.0 = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|Win32.ActiveCfg = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|Win32.Build.0 = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|x64.ActiveCfg = Debug|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|x64.Build.0 = Debug|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|x86.ActiveCfg = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.DVD-5|x86.Build.0 = Debug|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.Release|Any CPU.Build.0 = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|Mixed Platforms.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|Win32.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|Win32.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|x64.ActiveCfg = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|x64.Build.0 = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|x86.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.Release|x86.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|Any CPU.Build.0 = Release|Any CPU + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|Mixed Platforms.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|Mixed Platforms.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|Win32.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|Win32.Build.0 = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|x64.ActiveCfg = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|x64.Build.0 = Release|x64 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|x86.ActiveCfg = Release|x86 + {4E200124-E140-40A7-83B1-625E4817198C}.SingleImage|x86.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|Any CPU.ActiveCfg = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|Any CPU.Build.0 = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|Mixed Platforms.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|Mixed Platforms.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|Win32.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|Win32.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|x64.ActiveCfg = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|x64.Build.0 = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|x86.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.ARM|x86.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|Any CPU.Build.0 = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|Mixed Platforms.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|Mixed Platforms.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|Win32.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|Win32.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|x64.ActiveCfg = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|x64.Build.0 = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|x86.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.CD_ROM|x86.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|Win32.ActiveCfg = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|Win32.Build.0 = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|x64.ActiveCfg = Debug|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|x64.Build.0 = Debug|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|x86.ActiveCfg = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Debug|x86.Build.0 = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|Any CPU.Build.0 = Debug|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|Mixed Platforms.ActiveCfg = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|Mixed Platforms.Build.0 = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|Win32.ActiveCfg = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|Win32.Build.0 = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|x64.ActiveCfg = Debug|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|x64.Build.0 = Debug|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|x86.ActiveCfg = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.DVD-5|x86.Build.0 = Debug|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|Any CPU.Build.0 = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|Mixed Platforms.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|Win32.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|Win32.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|x64.ActiveCfg = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|x64.Build.0 = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|x86.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.Release|x86.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|Any CPU.Build.0 = Release|Any CPU + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|Mixed Platforms.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|Mixed Platforms.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|Win32.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|Win32.Build.0 = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|x64.ActiveCfg = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|x64.Build.0 = Release|x64 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|x86.ActiveCfg = Release|x86 + {E488694F-F2FA-45AD-B1B8-8D4FABE34E86}.SingleImage|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE -- Gitee