接上篇,上篇的例子里有用到如下的library: using namespace ntk;
http://nicolas.burrus.name/index.php/Research/KinectUseNestk
Using the nestk library
Developing your own software based on the nestk
library
Nestk
is the core library used by the demo programs within RGB Demo . It is designed to be easy to integrate into existing cmake-based software and provide access the Kinect features in no time (ok, whether it reaches its objectives or not is another story :-)
The library is built on top of Open CV and QT for the graphical parts. It includes or look for all the other libraries you need. In particular, libfreenect is included.
It is not designed to be installed as an external dependency, but as a subdirectory of your project.
Tutorial to get started
Here is a simple tutorial to get started. You can get its full code on github . Suppose you want to create a new project called mysuperdemo
. Then just put the nestk
directory from github or extract it from a release of rgbdemo:
mkdir mysuperdemo
cd mysuperdemo
git clone https://github.com/nburrus/nestk.git
Note that if your project is using git, you might want to add it as a submodule.
Then just create a C Make Lists .txt
file as follows:
cmake_minimum_required(VERSION 2.6)
PROJECT(mysuperdemo)
# Default values
SET(NESTK_USE_FREENECT 1)
SET(NESTK_USE_OPENNI 1)
ADD_SUBDIRECTORY(nestk)
## nestk/UseNestk.cmake.in defines variable to use nestk.
## It itself includes nestk/deps/cmake/UseEmbeddedNestkDeps.cmake that
## contains most of the cmake find packages commands.
INCLUDE("${nestk_BINARY_DIR}/UseEmbeddedNestk.cmake")
ADD_EXECUTABLE(mysuperdemo mysuperdemo.cpp)
TARGET_LINK_LIBRARIES(mysuperdemo nestk)
and finally enter your program in mysuperdemo.cpp
:
#include <ntk/camera/kinect_grabber.h>
#include <ntk/camera/rgbd_processor.h>
#include <ntk/utils/opencv_utils.h>
using namespace ntk;
using namespace cv;
int main()
{
KinectGrabber grabber;
grabber.initialize();
// Set camera tilt.
grabber.setTiltAngle(15);
grabber.start();
// Postprocess raw kinect data.
// Tell the processor to transform raw depth into meters using baseline-offset technique.
RGBDProcessor processor;
processor.setFilterFlag(RGBDProcessor::ComputeKinectDepthBaseline, true);
// OpenCV windows.
namedWindow("color");
namedWindow("depth");
namedWindow("depth_as_color");
// Current image. An RGBDImage stores rgb and depth data.
RGBDImage current_frame;
while (true)
{
grabber.waitForNextFrame();
grabber.copyImageTo(current_frame);
processor.processImage(current_frame);
// Show the frames per second of the grabber
int fps = grabber.frameRate();
cv::putText(current_frame.rgbRef(),
cv::format("%d fps", fps),
Point(10,20), 0, 0.5, Scalar(255,0,0,255));
// Display the color image
imshow("color", current_frame.rgb());
// Show the depth image as normalized gray scale
imshow_normalized("depth", current_frame.depth());
// Compute color encoded depth.
cv::Mat3b depth_as_color;
compute_color_encoded_depth(current_frame.depth(), depth_as_color);
imshow("depth_as_color", depth_as_color);
// Enable switching to InfraRead mode.
unsigned char c = cv::waitKey(10) & 0xff;
if (c == 'q')
exit(0);
}
return 0;
}
To compile it (in release mode with debug information), do the following:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ..
make
./mysuperdemo
Documentation
There is no documentation as such yet. You can have a look at the test programs such as tests/test-kinect-3d.cpp
and tests/test-async-grabber.cpp
. To build the test, configure the project with NESTK_BUILD_TESTS
:
cmake -DNESTK_BUILD_TESTS=1 build