forked from IntelRealSense/librealsense
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+NetDevice object; +cs-tutorial-7-net-dev
- Loading branch information
Showing
10 changed files
with
268 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// License: Apache 2.0. See LICENSE file in root directory. | ||
// Copyright(c) 2017 Intel Corporation. All Rights Reserved. | ||
|
||
namespace Intel.RealSense | ||
{ | ||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Runtime.InteropServices; | ||
|
||
|
||
public class NetDevice : Device | ||
{ | ||
public NetDevice(string address) : base(init(address)) | ||
{ | ||
} | ||
|
||
public void AddTo(Context ctx) | ||
{ | ||
object error; | ||
NativeMethods.rs2_context_add_software_device(ctx.Handle, Handle, out error); | ||
} | ||
|
||
private static IntPtr init(string address) | ||
{ | ||
object error; | ||
var ApiVersion = NativeMethods.rs2_get_api_version(out error); | ||
var dev = NativeMethods.rs2_create_net_device(ApiVersion, address, out error); | ||
|
||
return dev; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
cmake_minimum_required( VERSION 3.8.0 ) | ||
|
||
project(cs-tutorial-7-net-dev) | ||
|
||
add_executable(${PROJECT_NAME} | ||
Program.cs | ||
Window.xaml | ||
Window.xaml.cs | ||
|
||
Properties/AssemblyInfo.cs | ||
) | ||
|
||
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_TARGET_FRAMEWORK_VERSION "v${DOTNET_VERSION_EXAMPLES}") | ||
# set_property(TARGET ${PROJECT_NAME} PROPERTY WIN32_EXECUTABLE TRUE) | ||
|
||
add_dependencies(${PROJECT_NAME} Intel.RealSense) | ||
|
||
set_property(TARGET ${PROJECT_NAME} PROPERTY VS_DOTNET_REFERENCES | ||
"System" | ||
"System.Xaml" | ||
"PresentationCore" | ||
"PresentationFramework" | ||
"WindowsBase" | ||
) | ||
|
||
set_target_properties (${PROJECT_NAME} PROPERTIES | ||
FOLDER Wrappers/csharp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Intel.RealSense | ||
{ | ||
class Program | ||
{ | ||
[STAThread] | ||
static void Main(string[] args) | ||
{ | ||
if (args.Length == 0) | ||
{ | ||
Console.WriteLine($"Please, specify network server IP address as a parameter"); | ||
return; | ||
} | ||
var w = new CaptureWindow(args[0]); | ||
w.ShowDialog(); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
wrappers/csharp/cs-tutorial-7-net-dev/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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(R) RealSense(TM) SDK C# Wrapper Tutorial-7")] | ||
[assembly: AssemblyDescription("Intel(R) RealSense(TM) SDK C# Wrapper Examples")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("Intel(R) Corporation")] | ||
[assembly: AssemblyProduct("Intel(R) RealSense(TM) SDK C# Wrapper")] | ||
[assembly: AssemblyCopyright("Copyright © 2021, Intel Corporation. All rights reserved")] | ||
[assembly: AssemblyTrademark("Intel(R) RealSense(TM)")] | ||
[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("71c85ee0-c7c2-4e2e-8020-6af818537a14")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Window x:Class="Intel.RealSense.CaptureWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:Intel.RealSense" | ||
mc:Ignorable="d" WindowStartupLocation="CenterOwner" | ||
Closing="control_Closing" | ||
Title="Intel RealSense Capture .NET Example" Height="700" Width="1200" x:Name="control"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition /> | ||
<ColumnDefinition /> | ||
</Grid.ColumnDefinitions> | ||
|
||
<TextBox x:Name="txtTimeStamp" Grid.Column="0" /> | ||
|
||
<Image x:Name="imgDepth" Grid.Column="0" /> | ||
<Image x:Name="imgColor" Grid.Column="1" /> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
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; | ||
using System.Windows.Threading; | ||
|
||
namespace Intel.RealSense | ||
{ | ||
/// <summary> | ||
/// Interaction logic for Window.xaml | ||
/// </summary> | ||
public partial class CaptureWindow : Window | ||
{ | ||
private Pipeline pipeline; | ||
private Colorizer colorizer; | ||
private CancellationTokenSource tokenSource = new CancellationTokenSource(); | ||
|
||
static Action<VideoFrame> UpdateImage(Image img) | ||
{ | ||
var wbmp = img.Source as WriteableBitmap; | ||
return new Action<VideoFrame>(frame => | ||
{ | ||
var rect = new Int32Rect(0, 0, frame.Width, frame.Height); | ||
wbmp.WritePixels(rect, frame.Data, frame.Stride * frame.Height, frame.Stride); | ||
}); | ||
} | ||
|
||
public CaptureWindow(string serverIp) | ||
{ | ||
InitializeComponent(); | ||
|
||
try | ||
{ | ||
Action<VideoFrame> updateDepth; | ||
Action<VideoFrame> updateColor; | ||
|
||
// The colorizer processing block will be used to visualize the depth frames. | ||
colorizer = new Colorizer(); | ||
|
||
|
||
using (var ctx = new Context()) | ||
{ | ||
Console.WriteLine($"Connecting to server {serverIp}..."); | ||
var dev = new NetDevice(serverIp); | ||
dev.AddTo(ctx); | ||
|
||
// Create and config the pipeline to strem color and depth frames. | ||
pipeline = new Pipeline(ctx); | ||
|
||
// show device | ||
Console.WriteLine($"Using device 0, {dev.Info[CameraInfo.Name]}" + | ||
$"\tSerial number: {dev.Info[CameraInfo.SerialNumber]}"); | ||
|
||
var pp = pipeline.Start(); | ||
|
||
SetupWindow(pp, out updateDepth, out updateColor); | ||
} | ||
|
||
Task.Factory.StartNew(() => | ||
{ | ||
while (!tokenSource.Token.IsCancellationRequested) | ||
{ | ||
// We wait for the next available FrameSet and using it as a releaser object that would track | ||
// all newly allocated .NET frames, and ensure deterministic finalization | ||
// at the end of scope. | ||
using (var frames = pipeline.WaitForFrames()) | ||
{ | ||
var colorFrame = frames.ColorFrame.DisposeWith(frames); | ||
var depthFrame = frames.DepthFrame.DisposeWith(frames); | ||
|
||
// We colorize the depth frame for visualization purposes | ||
var colorizedDepth = colorizer.Process<VideoFrame>(depthFrame).DisposeWith(frames); | ||
|
||
// Render the frames. | ||
Dispatcher.Invoke(DispatcherPriority.Render, updateDepth, colorizedDepth); | ||
Dispatcher.Invoke(DispatcherPriority.Render, updateColor, colorFrame); | ||
|
||
Dispatcher.Invoke(new Action(() => | ||
{ | ||
String depth_dev_sn = depthFrame.Sensor.Info[CameraInfo.SerialNumber]; | ||
txtTimeStamp.Text = depth_dev_sn + " : " + String.Format("{0,-20:0.00}", depthFrame.Timestamp) + "(" + depthFrame.TimestampDomain.ToString() + ")"; | ||
})); | ||
} | ||
} | ||
}, tokenSource.Token); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show(ex.Message); | ||
Application.Current.Shutdown(); | ||
} | ||
} | ||
|
||
private void control_Closing(object sender, System.ComponentModel.CancelEventArgs e) | ||
{ | ||
tokenSource.Cancel(); | ||
} | ||
|
||
private void SetupWindow(PipelineProfile pipelineProfile, out Action<VideoFrame> depth, out Action<VideoFrame> color) | ||
{ | ||
using (var p = pipelineProfile.GetStream(Stream.Depth).As<VideoStreamProfile>()) | ||
imgDepth.Source = new WriteableBitmap(p.Width, p.Height, 96d, 96d, PixelFormats.Rgb24, null); | ||
depth = UpdateImage(imgDepth); | ||
|
||
using (var p = pipelineProfile.GetStream(Stream.Color).As<VideoStreamProfile>()) | ||
imgColor.Source = new WriteableBitmap(p.Width, p.Height, 96d, 96d, PixelFormats.Rgb24, null); | ||
color = UpdateImage(imgColor); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> |