Kinect – Getting Started – Setting Up OpenCV

Just before the New Year, I finally got the Kinect sensor 🙂
Here he is, handsome:

along with the sensor, there was already a power supply and an adapter cable to a regular USB (Kinect Modification Kit):

I’m not sure if this is a standard equipment, because before people had to assemble such an adapter on one’s ownusing the following cable pinout:

Software installation

Windows

The procedure for installing software to revive the sensor:
one. download and install the library OpenNI
http://www.openni.org/Downloads/OpenNIModules.aspx
2. download and install PrimeSensor Module for OpenNI
https://github.com/avin2/SensorKinect

(we take the master archive and run from the Bin directory
SensorKinect091-Bin-Win32-v5.1.0.25.msi or SensorKinect091-Bin-Win64-v5.1.0.25.msi – three new devices will appear in the system)

Installation must be done in the default directories!

You can already check the operation of the sensor 🙂
Go to the installation directory of the OpenNI library

C:\Program Files\OpenNI\Samples\Bin\Release\

run the example SimpleViewer.net.exe

The green LED on the sensor turns on, and the IR illuminator lights up red (in the photo – purple).

spotlight close-up:

If the sensor is pointed at the floor and photographed in the dark:

The depth picture appears on the PC screen:

You can immediately evaluate the boundaries of object detection by the depth sensor.
The minimum distance is about 40 centimeters – if you bring your hand closer, then it turns black (i.e. the distance is unknown)

Hardware-wise, Kinect has a practical range of 0.5 to 3 meters.
The point cloud has a resolution in X, Y – 640×480, and the depth is encoded in 11 bits (from 0 to 2047). In practice, (when using the driver libfreenect) the depth range is from 350 to 1045, representing 0.5 to 3 meters.
The data range is not linear, and for objects that are too close or too far (or in the “shadow”), the sensor returns a value of 2047 (shown in black)

Anniversary of Kinect

Kinect and OpenCV

Now let’s try to rebuild OpenCV to support working with the Kinect sensor.

Using a graphic utility cmake-gui.

one) Run cmake-gui
2) specify the directory where OpenCV was unpacked.
3) create a directory to store the generated project files
4) specify the directory created in the previous step
five) click Configure, in the window that appears, select the version of our compiler

(for example, Visual Studio 9 2008) and click Finish (the studio must be closed)
6) specify the necessary options for the OpenCV library:

to support the Kinect sensor, check the box next to the option WITH_OPENNI.
And also set the paths to the header and library files of the OpenNI library, and for the PrimeSensor Module, the path to the executable files:

OpenNI:
	Linux & MacOSX:
		Libs into: /usr/lib
		Includes into: /usr/include/ni
	Windows:
		Libs into: c:/Program Files/OpenNI/Lib
		Includes into: c:/Program Files/OpenNI/Include

PrimeSensor Module:
	Linux & MacOSX:
		Bins into: /usr/bin
	Windows:
		Bins into: c:/Program Files/Prime Sense/Sensor/Bin

Nuance:
I don’t know what the trick is, but my PrimeSensor Module is installed by default in the directory c:/Program Files/PrimeSense (no space between Prime and Sense) – CMake cursed at this and I solved the issue by manually creating the necessary directory c:/Program Files/Prime Sense

and copying files there from the directory where PrimeSensor Module was installed for me.

OPENNI_PRIME_SENSOR_MODULE_BIN_DIR

C:/Program Files/PrimeSense/SensorKinect/Bin
->
c:/Program Files/Prime Sense/Sensor/Bin

7) press the Generate button and we get a bunch of project files in the directory created at the 2nd step. We launch ALL_BUILD.vcproj and start building the library.
(some modules are not built right away (build errors are generated), but if you start the build again, they will already build without errors).

Attention: I don’t know what I did wrong, but for some reason OpenCV was still built without Kinect support.
I solved the problem by manually editing the configuration header file:
added to the end c:\opencv\cvconfig.h

line

#define HAVE_OPENNI

and rebuilt the library again

8) It remains either to specify the path with the freshly built dlls and lib files in the IDE settings, or copy them to the already registered c:\opencv\build directory, which stores the original version of the library (see Installing OpenCV 2.3.1).

nine) We are trying to assemble a regular example of working with a Kinect sensor –

C:\opencv\samples\cpp\kinect_maps.cpp

run the received kinect_maps.exe

>kinect_maps.exe

This program demonstrates usage of Kinect sensor.
The user gets some of the supported output images.

All supported output map types:
1.) Data given from depth generator
   OPENNI_DEPTH_MAP            - depth values in mm (CV_16UC1)
   OPENNI_POINT_CLOUD_MAP      - XYZ in meters (CV_32FC3)
   OPENNI_DISPARITY_MAP        - disparity in pixels (CV_8UC1)
   OPENNI_DISPARITY_MAP_32F    - disparity in pixels (CV_32FC1)
   OPENNI_VALID_DEPTH_MASK     - mask of valid pixels (not ocluded, not shaded e
tc.) (CV_8UC1)
2.) Data given from RGB image generator
   OPENNI_BGR_IMAGE            - color image (CV_8UC3)
   OPENNI_GRAY_IMAGE           - gray image (CV_8UC1)

Kinect opening ...
done.

Depth generator output mode:
FRAME_WIDTH    640
FRAME_HEIGHT   480
FRAME_MAX_DEPTH    10000 mm
FPS    30

Image generator output mode:
FRAME_WIDTH    640
FRAME_HEIGHT   480
FPS    30

and see two pictures:

– a regular picture from an RGB camera and a disparity map.

Run kinect_maps.exe with parameter

-m 11111

and see another picture with a depth map:

The beauty!

Next: Working with Kinect on ROS

Links
Making a Kinect power adapter from improvised means
OpenCV HIGHGUI – Using Kinect sensor
http://www.openni.org
https://github.com/OpenNI/OpenNI
https://github.com/PrimeSense/Sensor
https://github.com/avin2/SensorKinect
http://openkinect.org/wiki/Getting_Started
https://github.com/OpenKinect/libfreenect

Kinect – Getting Started – Setting Up OpenCV

Leave a Reply

Your email address will not be published.

Scroll to top