Intel RealSense R200 Camera - Code Samples

Original author: Bryan Brown
  • Transfer


For programmers who recently started working with Intel RealSense technology, we prepared a post with three simple examples demonstrating the capabilities of the R200 camera. Examples included:
  • Record and view raw streams
  • Depth Focus
  • Face tracking


Record and view raw streams of the R200 camera


In this available for download code demonstrates the basics recording and playback of untreated R200 camera streams on C # / XAML using Intel® RealSense ™ SDK for * the Windows . Visual Studio * solution consists of four simple projects (each size is no more than 200 lines of code).
  • ColorStream - displays the color stream from the RGB camera.
  • DepthStream - Depth stream display.
  • IRStreams - display of the right and left streams of an infrared camera.
  • AllStreams - display of everything listed in one window (see. Fig. 1).


Figure 1. Sample code for all threads

Software development environment


This code sample was created in Windows® 10 RTM using Microsoft Visual Studio Community 2015. The Visual C # - Windows - Classic Desktop project template was used for this sample .
The SDK and DCM versions used in this project.
  • Intel® RealSense ™ SDK v6.0.21.6598
  • Intel® RealSense ™ Depth Camera Manager R200 v2.0.3.39488

Hardware Description


For this work, we used the Intel® RealSense ™ Developer Kit (R200) , which includes a camera, a USB3 cable and a magnetic mount for installing the camera on a laptop (Fig. 2).


Figure 2. Intel® RealSense ™ Developer Kit (R200)

The following hardware requirements apply to the R200 code sample:
  • 4th Generation (or later) Intel® Core ™ Processor.
  • 150 MB of free hard disk space.
  • RAM 4 GB.
  • Intel® RealSense ™ Camera (R200).
  • Available USB3 port for R200 camera (or dedicated connection for integrated camera).

Important! To support the data stream transmitted by the camera, a USB3 interface is required. This interface must be connected to a dedicated USB3 port on the client system (without using a splitter).

Code Description


The solution in Visual Studio consists of four WPF projects developed in C #. These projects use the explicit path to libpxcclr.cs.dll (managed DLL):

C: \ Program Files (x86) \ Intel \ RSSDK \ bin \ x64

Remember to change this path if the SDK is installed on another system on your system folder.
Since we are launching the 64-bit version of the DLL, go to the menu ProjectPropertiesPlatform target and make sure that the value “x64” is selected there.
To build and run a specific project, right-click the project name (for example, AllStreams) in the Solution Explorer and select Set as StartUp Project(Assign as project to be launched) in the menu.

All projects within CameraStreams have a similar structure.

Configure the Session and SenseManager interface.

Run a workflow called Update , which processes the AcquireFrame - ReleaseFrame loop .

The following actions occur in the AcquireFrame - ReleaseFrame loop .
  • Getting image data.
  • Call the Render method to update the user interface.
  • Release of resources.
  • Frame release.

The following actions occur in the Render method .
  • Call the ConvertBitmap method to convert each raster frame to the BitmapImage type, which is required to display each frame in the WPF Image control.
  • Updating the user interface by delegating work to the dispatcher associated with the user interface thread.

The ShutDown method is called whenever a Window_Closing or btnExit_Click event occurs . The following actions occur in the ShutDown method .
  • Stopping the Update method.
  • Removing objects.


Depth Focus


В этом примере кода C#/XAML демонстрируются основы работы с модулем Enhanced Photography (EP) в Intel® RealSense™ SDK для Windows* для изменения фокусировки изображения после его съемки. Этот образец кода выполняет следующие действия.
  • Отображение цветового потока RGB камеры R200 в элементе управления Image (слева).
  • Съемка кадра и отображение его во втором элементе управления Image (справа).
  • Изменение фокусировки и диафрагмы с помощью ползунка.
  • Сохранение измененного изображения в виде стандартного JPG-файла (Snapshot.jpg).


Figure 3. An example of changing depth focusing (focusing on a flower)


Figure 4. Saved image file

As described in the SDK manual (in the RSSDK_DIR \ doc \ PDF \ sdkmanuals.pdf file ), the Enhanced Photography (EP) module extends the traditional photo processing capabilities and video through the use of three-dimensional information (in particular, depth data) recorded along with photos and videos. The function of changing the depth of field changes the focus and depth of field of the frame after shooting it. (Note that this algorithm only works with the R200 camera.)

Hardware Description


We used the Intel® RealSense ™ Developer Kit (R200) ​​for this work. The camera was mounted on a laptop using the magnetic mount included in the kit (Fig. 5).


Figure 5. Camera attached to a magnetic mount

Assembly notes


This project uses the System.Drawing.Imaging namespace . The link to it is specified manually: in the new project, right-click References in the Solution Explorer and select Add Reference ... to open the link manager window. Then select Assemblies, Framework and find System.Drawing in the list. Check the box and click OK.

This project uses the explicit path to libpxcclr.cs.dll (managed DLL): C: \ Program Files (x86) \ Intel \ RSSDK \ bin \ x64 . Remember to change this path if the SDK on your system is installed in a different folder.

Since the project refers to a 64-bit version of the DLL, make sure that the “x64” parameter is specified in the ProjectPropertiesPlatform target section (Project → Properties → Target Platform).

The project includes a post-build event command to verify that the unmanaged DLL (libpxccpp2c.dll) is copied to the target output folder:
if "$(Platform)" == "x86" (copy /y "$(RSSDK_DIR)\bin\win32\libpxccpp2c.dll" "$(TargetDir)" ) else ( copy /y
"$(RSSDK_DIR)\bin\x64\libpxccpp2c.dll" "$(TargetDir)" )


Face tracking


In this example, the code C # / XAML demonstrates the basics of tracking algorithm persons Intel® RealSense ™ SDK for Windows * for detecting and tracking human faces in real time by the camera R200. This sample code performs the following actions.
  • Displays the RGB color stream of the R200 in the Image control.
  • An overlay of a rectangular control that tracks the location of the user's face (depending on where the user is in the camera’s field of view).
  • Displays the number of faces detected by the R200.
  • Displays the height and width of the tracked face.
  • Displays the two-dimensional coordinates (X and Y) of the tracked face.
  • Indication of the depth of the face, i.e. the distance from the R200 camera to the face.
  • Support and display alert tracking, event handler subscription.


Figure 6. Sample face tracking code

Hardware Description


We used the Intel® RealSense ™ Developer Kit (R200) ​​for this work. The camera was mounted on a standard tripod using the optional magnetic mount ** (Fig. 7).


Figure 7. A camera attached to a magnetic mount (may not be supplied with all kits)

Assembly notes


See the previous example.

Code Description


The sample code has the following structure.

Configure the Session and SenseManager interface, as well as the face recognition module.
Run a workflow called Update , which processes the AcquireFrame - ReleaseFrame loop .
The following actions occur in the AcquireFrame - ReleaseFrame loop .
  • Getting image data.
  • Obtaining face recognition module data.
  • Call the Render method to update the user interface.
  • Release of resources.
  • Frame release.

The following actions occur in the Render method .
  • Call the ConvertBitmap method to convert each raster frame to the BitmapImage type, which is required to display each frame in the WPF Image control.
  • Updating the user interface by delegating work to the dispatcher associated with the user interface thread.

The ShutDown method is called whenever a Window_Closing or btnExit_Click event occurs . The following actions occur in the ShutDown method .
  • Stopping the Update method .
  • Removing objects.

Also popular now: