Ask Your Question
0

OpenCV + Asus Xtion sensor

asked 2014-05-17 00:44:39 -0600

chaanakya gravatar image

Dear all,

I am having trouble getting the Asus Xtion sensor to work with the OpenCV framework. I know (or at least I believe) the problem is not my laptop as I have an example program working with PCL (the Point Cloud Library). I am using Debian Sid with a custom compiled OpenCV (to ensure support for OpenNI and the Xtion sensor). The following code is what should work, but is not:

#include "opencv2/opencv.hpp"
using namespace cv;
using namespace std;

int main(int argc, char* argv[])
{
  VideoCapture capture( CAP_OPENNI_ASUS );
  if (!capture.isOpened())
  {
  exit(1);
  }
  for(;;)
  {
  Mat depthMap;
  capture >> depthMap;

  if( waitKey( 30 ) >= 0 )
    break;
  }
}

This code compiles just fine. When I run it, however, with the Xtion sensor plugged in, it gives me the following output:

CvCapture_OpenNI::CvCapture_OpenNI : Failed to run xml script: Bad Parameter sent to the device!

What exactly is going on and how do I fix it? I have tried searching on Google and haven't found anything useful except for other people with the same problem and no responses.

Thank you very much in advance.

Sincerely,

Chaanakya

edit retag flag offensive close merge delete

Comments

Does SamplesConfig.xml have anything at all to do with this not working? It seems that it should read /etc/openni/SamplesConfig.xml. However, I don't think it's doing that, since a) PCL worked (and works) just fine and b) nothing I do is actually changing the behavior of OpenCV.

chaanakya gravatar imagechaanakya ( 2014-05-18 12:11:25 -0600 )edit

Hi,

I don't know the answer, but maybe I can give you a hint. (I never used OpenNI 1.5, it's quite outdated; I prefer to use the newer OpenNI2.2 and transform the captured data to OpenCV Mat).

To get back to your question: the OpenNI capture is implemented in the modules/highgui/src/cap_openni.cpp file. There you can find a global variable called XMLConfig, right at the beginning. The CvCapture_OpenNI constructor tries to run this script, but it seems that it fails; there is a parameter in the XML text that your device doesn't understand.

workarounds: a) use OpenNI separately and transform the image to Mat; b) try to get a valid XML config file for your device; c) set the device in verbose mode (check the settings in OpenNI), maybe it gives you more hint about that bad parameter.

kbarni gravatar imagekbarni ( 2014-05-19 08:55:49 -0600 )edit

Thanks kbarni - I did change that variable and the result does work. How exactly do you do a) though? I'd like to do that if possible. Thanks!

chaanakya gravatar imagechaanakya ( 2014-05-26 23:02:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-05-27 03:38:28 -0600

kbarni gravatar image

updated 2014-05-27 03:39:09 -0600

Here is how to use OpenNI2.2 with OpenCV. The code is untested, but it should work.

To be shorter, I omitted the verifications from the code, but you should really check the result of every operation like this:

openni::Status rc;
rc=anyOpenNIOpreation();
if(rc!=openni::STATUS_OK){
    printf("Error! %d\n\n",rc);
    openni::OpenNI::shutdown();
    exit(0);
}

First you initialize OpenNI and the cameras:

openni::Device device;
openni::VideoStream depth, color,ir;

openni::OpenNI::initialize();
device.open(openni::ANY_DEVICE);

ir.create(device,openni::SENSOR_IR);
depth.create(device, openni::SENSOR_DEPTH);
color.create(device, openni::SENSOR_COLOR);

In this example I'll use the depth stream for capture. First we need the resolution:

openni::VideoMode vm=depth.getVideoMode();
int cols,rows;
cols=vm.getResolutionX();
rows=vm.getResolutionY();

Then, we capture the image:

openni::VideoFrameRef frame;
depth.start();
stream->readFrame(&frame);   
depth.stop();

Finally, you get the frame data and create a Mat variable using that data:

openni::DepthPixel* dData = (openni::DepthPixel*)frame.getData();
cv::Mat depthImage(rows, cols, CV_16UC1, dData);

For the color frame you'll have to use openni::RGB888Pixel as pixel type and CV_8UC3 as matrix type.

Hope this helps!

openni::OpenNI::shutdown();
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-05-17 00:44:39 -0600

Seen: 6,826 times

Last updated: May 27 '14