Learning to be Giant.

Let OpenCV work with Asus Xtion Pro Live under Ubuntu

|

I spent several hours make OpenCV and Xtion work together. I want to extract the depth map from Xtion with OpenCV. There is a sample program openni_capture.cpp under samples/cpp/. It makes us of VideoCapture.

My configuration is:

  1. Ubuntu 14.04 LTS
  2. OpenCV 2.4.10 (compiled with OpenNI support, check here)
  3. OpenNI 1.5.7.10 with PrimeSense Module

Linking Problems with OpenCV

The first problem I met is to compile this file. With Makefile provided by OpenCV, compiling is pretty straightforward and easy. But when I copy that file to another directory, compilation becomes a mess. I tried:

g++ `pkg-config --cflags --libs opencv` openni_capture.cpp -o openni_capture

, but it does not work at all. It prompts something like:

/tmp/ccYtGn3e.o: In function `colorizeDisparity(cv::Mat const&, cv::Mat&, double, float, float)':
openni_capture.cpp:(.text+0x105): undefined reference to `cv::Exception::Exception(int, std::string const&, std::string const&, std::string const&, int)'
openni_capture.cpp:(.text+0x111): undefined reference to `cv::error(cv::Exception const&)'
openni_capture.cpp:(.text+0x11d): undefined reference to `cv::Exception::~Exception()'
openni_capture.cpp:(.text+0x225): undefined reference to `cv::Exception::Exception(int, std::string const&, std::string const&, std::string const&, int)'
...
collect2: error: ld returned 1 exit status

It seems pretty much everything is missing in linking process. How can that happen? I checked the output of pkg-config --cflags --libs opencv, and it works fine. Then I came accross this. It turns out that libraries must be placed behind objects needing them since 11.10. So I changed the command to be:

g++ `pkg-config --cflags opencv` openni_capture.cpp `pkg-config --libs opencv` -o openni_capture

It works!

Weird Can not grab images Error

After successfully compiled the openni_capture, I cannot wait to try it. What’s weird, however, is the FPS is unbearably low and the program always hangs unexpectedly with an error message: Can not grab images. Then I came accross this. It turns out that besides CV_CAP_OPENNI, there is another option CV_CAP_OPENNI_ASUS. After changing the option to CV_CAP_OPENNI_ASUS, everything works fine.

Disclaimer: This is a personal weblog. The opinions expressed here represent my own and not those of any entity with which I have been, am now, or will be affiliated.

Comments