Using the nestk library

接上篇,上篇的例子里有用到如下的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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值