ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

OpenNI: "Save calibration to file failed: This operation is invalid!"

asked 2011-07-20 06:48:29 -0500

daaango gravatar image

updated 2016-10-24 09:02:38 -0500

ngrennan gravatar image

Hi everyone,

I've been trying to use the SaveCalibrationDataToFile function in OpenNI but so far, it hasn't been going so well. When I try to call it, it returns a

Save calibration to file failed: This operation is invalid!

Here's the few lines of code:

  if (g_UserGenerator.GetSkeletonCap().IsCalibrated(nId)){
      XnStatus nRetVal = g_UserGenerator.GetSkeletonCap().SaveCalibrationDataToFile(nId, calib.bin);
      if (nRetVal != XN_STATUS_OK)
          printf("Save calibration to file failed: %s\n", xnGetStatusString(nRetVal));

I also downloaded someone else's calibration file and tried to load it, but it yielded the same "operation is invalid" message. Anyone have any clues?


Update: I tried installing ROS and OpenNI via source in order to use the newest version, but it still displays the horrid and vague "invalid" message.

Update2: I installed the latest unstable version of OpenNI and SaveCalibrationDataToFile works! For anyone who wants to do that, will prove to be very useful

edit retag flag offensive close merge delete


I'm having the same issue, and the only thing I can think of is that this might be a OpenNI version issue. The only people I've heard that has been able to make it work used a more recent version of OpenNI. Hopefully when a newer version is released it will be fixed.
Miguel Prada gravatar image Miguel Prada  ( 2011-08-01 19:02:02 -0500 )edit
I was hoping it would maybe be a usage error on my part or something, but I guess deep down I had an inclination that it had something to do with openni... Hopefully someone who deals with OpenNI integration in ROS will stumble upon this thread and provide some insight!
daaango gravatar image daaango  ( 2011-08-02 06:26:33 -0500 )edit
It's nice to know this works with newer versions of openni :) you should answer the question yourself so that some admin can mark it as answered.
Miguel Prada gravatar image Miguel Prada  ( 2011-08-06 02:23:30 -0500 )edit
I installed the latest unstable version, but when I use the Sample-NiUserTracker, it does not automatically save the calibration. Is there a different program that I need to run to use it? Also, do I need to create a file on my own, or does it automatically create one?
qdocehf gravatar image qdocehf  ( 2011-08-08 06:38:32 -0500 )edit
From daaango's update, it seems as though this feature is already in the latest unstable version of OpenNI. All I want to know is what commands I need to use to get this to work.
qdocehf gravatar image qdocehf  ( 2011-08-08 07:03:32 -0500 )edit
To get it to save calibration, all you have to do is paste "g_UserGenerator.GetSkeletonCap().IsCalibrated(aUserIDs[i])" into the XN_CALLBACK_TYPE UserCalibration_CalibrationStart function, specifically after "g_UserGenerator.GetSkeletonCap().StartTracking(nId)" which is around line 130.
daaango gravatar image daaango  ( 2011-08-08 07:04:21 -0500 )edit
g_UserGenerator.GetSkeletonCap().SaveCalibrationDataToFile(aUserIDs[i], XN_CALIBRATION_FILE_NAME);
JoeRomano gravatar image JoeRomano  ( 2011-08-08 07:04:29 -0500 )edit
Do you mean "UserCalibration_CalibrationEnd" or "UserCalibration_CalibrationComplete"? "UserCalibration_CalibrationStart" does not have this line.
qdocehf gravatar image qdocehf  ( 2011-08-08 07:31:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

answered 2011-08-08 06:56:38 -0500

daaango gravatar image

updated 2011-08-09 07:33:00 -0500

Looks like it has to do with the ROS version of OpenNI, as saving to file works when using the unstable version of OpenNI. Refer to the original post for a link to instructions on how to do that.

Special thanks to Miguel Prada and Asomerville!

edit: For those who wish to test this for themselves (specifically qdocehf cough cough), after installing OpenNI navigate to the folder OpenNI/Samples/NiUserTracker/ and copy the following files to a new directory: SceneDrawer.cpp SceneDrawer.h main.cpp

Open up main.cpp and after line 146, paste

g_UserGenerator.GetSkeletonCap().SaveCalibrationDataToFile(nId, "calibration.bin")

and then compile the file with g++:

g++ -o NiUserTracker SceneDrawer.cpp main.cpp -I/usr/include/ni/ -l'OpenNI' -l'glut'

This will simply save the calibration of any user who performs the psi pose (continuously overwriting the .bin file). This is meant to just be a quick demo to make sure saving calibration data to file works. There is already a function on line 167 that is supposed to save calibration when the s key is pushed, but I must be using it wrong because I didn't get it working and don't really care for it enough to figure it out.

edit2: For testing loading calibration files, around line 90 of main.cpp, just paste in the following code:

g_UserGenerator.GetSkeletonCap().LoadCalibrationDataFromFile(nId, "calibration.bin");

This will simply load up a calibration file as soon as a new user detected, so you'll want to fiddle around some more with code to make sure a calibration file is available, make sure its not requesting calibration after loading, etc...

edit flag offensive delete link more


What about LoadCalibrationFromFile? The only place that I can find where it is called is when you push the 'L' key, but can it be done automatically? P.S. Sorry about asking so many questions.
qdocehf gravatar image qdocehf  ( 2011-08-08 07:51:58 -0500 )edit
check the post! I added a second edit
daaango gravatar image daaango  ( 2011-08-08 08:15:39 -0500 )edit
Thanks. By the way, the main method in main.cpp uses UserCalibration_CalibrationComplete, not UserCalibration_CalibrationEnd. The safest thing to do would probably be to just paste the line into both methods.
qdocehf gravatar image qdocehf  ( 2011-08-09 01:49:01 -0500 )edit
you're right, sorry about that. I deleted UserCalibration_CalibrationEnd completely from my version as its not called anywhere in the program.
daaango gravatar image daaango  ( 2011-08-09 07:33:39 -0500 )edit

answered 2011-08-08 06:55:10 -0500

JoeRomano gravatar image

updated 2011-08-08 07:08:08 -0500

Here is an example of the function you should find inside of recent unstable NiUserTracker demo code. It creates the UserCalibration.bin file:

#define XN_CALIBRATION_FILE_NAME "UserCalibration.bin"

void SaveCalibration()
    XnUserID aUserIDs[20] = {0};
    XnUInt16 nUsers = 20;
    g_UserGenerator.GetUsers(aUserIDs, nUsers);
    for (int i = 0; i < nUsers; ++i)
        // Find a user who is already calibrated
        if (g_UserGenerator.GetSkeletonCap().IsCalibrated(aUserIDs[i]))
            // Save user's calibration to file
            g_UserGenerator.GetSkeletonCap().SaveCalibrationDataToFile(aUserIDs[i], XN_CALIBRATION_FILE_NAME);
            printf("saved data\n");
edit flag offensive delete link more


From daaango's update, it seems as though this feature is already in the latest unstable version of OpenNI. Do you know which commands I need to use to get this to work?
qdocehf gravatar image qdocehf  ( 2011-08-08 07:04:39 -0500 )edit

Question Tools

1 follower


Asked: 2011-07-20 06:48:29 -0500

Seen: 1,913 times

Last updated: Aug 09 '11