Azure KinectLoading The RGB Camera With The New SDK 1.2WPF Part 2 ((LINK))
LINK ::: https://blltly.com/2twjEo
Azure KinectâLoading the RGB Camera with the new SDK 1.2âWPF â Part 2
In the previous part of this series, we learned how to set up the Azure Kinect device and initialize the RGB camera stream using the new SDK 1.2. In this part, we will see how to display the RGB camera frames in a WPF application using a WriteableBitmap.
Creating a WPF project
To create a WPF project, open Visual Studio and select File > New > Project. Choose the WPF App (.NET Framework) template and name it AzureKinectRGBDemo. Make sure the target framework is .NET Framework 4.7.2 or higher.
To use the Azure Kinect SDK in our WPF project, we need to add some references. Right-click on the References node in the Solution Explorer and select Manage NuGet Packages. Search for Microsoft.Azure.Kinect.Sensor and install the latest version (1.2.0 at the time of writing). This will also install some dependencies such as Microsoft.Azure.Kinect.BodyTracking and Microsoft.Azure.Kinect.BodyTracking.Dependencies.
Next, we need to add a reference to the WindowsBase assembly, which contains some classes for working with images and streams. Right-click on the References node again and select Add Reference. In the Assemblies tab, check WindowsBase and click OK.
Designing the UI
Now that we have added the references, we can design our UI. Open the MainWindow.xaml file and replace its content with the following XAML code:
This will create a simple window with two buttons (Start and Stop) and an image control to display the RGB camera frames.
Writing the code-behind
Now we need to write some code to handle the button clicks and display the RGB camera frames. Open the MainWindow.xaml.cs file and add the following using statements at the top:
Then add the following fields to store some variables:
private Device device; // The Azure Kinect device
private CancellationTokenSource cts; // The cancellation token source for stopping the camera loop
private WriteableBitmap bitmap; // The bitmap to display the RGB camera frames
private int width; // The width of the RGB camera resolution
private int height; // The height of the RGB camera resolution
Next, add the following method to initialize the device and start the RGB camera stream:
private void StartCamera()
// Open the default device
device = Device.Open();
// Get the calibration data
var calibration = device.GetCalibration(DeviceConfiguration.DisableAll);
// Get the width and height of the RGB camera resolution
width = calibration.ColorCameraCalibration.ResolutionWidth;
height = calibration.ColorCameraCalibration.ResolutionHeight;
// Create a new bitmap with the same size as the RGB camera resolution
bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgr32, null);
// Set the source of the image control to the aa16f39245