Book Image

OpenNI Cookbook

By : Soroush Falahati
Book Image

OpenNI Cookbook

By: Soroush Falahati

Overview of this book

The release of Microsoft Kinect, then PrimeSense Sensor, and Asus Xtion opened new doors for developers to interact with users, re-design their application’s UI, and make them environment (context) aware. For this purpose, developers need a good framework which provides a complete application programming interface (API), and OpenNI is the first choice in this field. This book introduces the new version of OpenNI. "OpenNI Cookbook" will show you how to start developing a Natural Interaction UI for your applications or games with high level APIs and at the same time access RAW data from different sensors of different hardware supported by OpenNI using low level APIs. It also deals with expanding OpenNI by writing new modules and expanding applications using different OpenNI compatible middleware, including NITE. "OpenNI Cookbook" favors practical examples over plain theory, giving you a more hands-on experience to help you learn. OpenNI Cookbook starts with information about installing devices and retrieving RAW data from them, and then shows how to use this data in applications. You will learn how to access a device or how to read data from it and show them using OpenGL, or use middleware (especially NITE) to track and recognize users, hands, and guess the skeleton of a person in front of a device, all through examples.You also learn about more advanced aspects such as how to write a simple module or middleware for OpenNI itself. "OpenNI Cookbook" shows you how to start and experiment with both NIUI designs and OpenNI itself using examples.
Table of Contents (14 chapters)
OpenNI Cookbook
About the Author
About the Reviewers


As a step towards interacting with users through the physical world, learn how to write NIUI-based applications or motion-controlled games.

OpenNI Cookbook is here to show you how to start developing Natural Interaction UI for your applications or games with high-level APIs while, at the same time, accessing raw data from different sensors of different devices that are supported by OpenNI using low-level APIs.

What this book covers

Chapter 1, Getting Started, will teach you how to install OpenNI along with NiTE and shows you how to prepare an environment for writing an OpenNI-based application.

Chapter 2, OpenNI and C++, explains how to start programming with OpenNI, from basic steps such as creating a project in Visual Studio to initializing and accessing different devices and sensors.

Chapter 3, Using Low-level Data, is an important chapter of this book, as we are going to cover reading and handling output of basic sensors from each device.

Chapter 4, More about Low-level Outputs, shows how you can customize the frame data right from the device itself, including mirroring and cropping.

Chapter 5, NiTE and User Tracking, will start using the Natural Interaction features of NiTE. As a first step, you will learn how to detect users on the scene and their properties.

Chapter 6, NiTE and Hands Tracking, will cover topics such as recognizing and tracking hand movements.

Chapter 7, NiTE and Skeleton Tracking, will be covering the most important features of NiTE: skeleton tracking and recognizing users' skeleton joints.

What you need for this book

You need to have Visual Studio 2010 to perform the recipes given in this book. You will also need to download OpenNI 2 and NiTE from their official websites. If you are going to use Kinect, you may need to download the Kinect SDK from Microsoft's website as well.

Who this book is for

OpenNI Cookbook is a book for both starters and professionals in NIUI, for people who want to write serious applications or games, and for people who want to experience and start working with NIUI. Even OpenNI 1 and OpenNI 1.x programmers who want to move to the new versions of OpenNI can use this book as a starting point.

This book uses C++ as its primary language; so for reading and understanding you only need to have a basic knowledge of C or C++.


In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Also, we checked if the initializing process ended without any error by creating a variable of type openni::Status."

A block of code is set as follows:

  printf("OpenNI Version is %d.%d.%d.%d",

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "From the File menu, select New and then New Project."


Warnings or important notes appear in a box like this.


Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.


Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from


Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.


You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.