0

Our project is (http://www.play4health.com/p4h_eng/) using Ogre 3D over Ubuntu 11.04. Except for core services all is based in a plugin architecture taking advantage of Ogre 3d plugin facilities.

In our plugin architecture plugins can be:

  • Videogames
  • Interaction methods

Users configure their session creating tuples (videogame, interaction method). The flow is a session is: * User load his session. * User click of one of the tuples for the session and play to videogame with a specific interaction method. * Repeat it until end all activities of the session.

Plugin are loaded/unloaded dynamically by demand.

One of this interaction methods is hand tracking using openni. What is the problem? * Fist time that openni plugin is loading all work perfectly. * Next time that plugin openni has to be loaded system is able to detect gestures but not do hand tracking. Note that all plugin are executed in the same process. Right now only solution is to reboot platform.

This is the code for init and release OpenNI in our plugin

  bool IPKinectPlugin::onInitialise()
  {
    mHandPointer.mId = "KinectHandPointer";
    mHandPointer.mHasAbsolute = true;
    mHandPointer.mHasRelative = false;

    XnStatus nRetVal = XN_STATUS_OK;

    nRetVal = gContext.InitFromXmlFile(String(this->getPluginInfo()-
  >getResPath() + "SamplesConfig.xml").c_str());
    CHECK_RC(nRetVal, bContext, "InitFromXml");

  #if SHOW_DEPTH
    nRetVal = gContext.FindExistingNode(XN_NODE_TYPE_DEPTH,gDepthGenerator);
    bDepthGenerator = (nRetVal != XN_STATUS_OK);
    if (bDepthGenerator)
    {
    nRetVal = gDepthGenerator.Create(gContext);
    CHECK_RC(nRetVal, bDepthGenerator, "Find Depth generator");
    }
  #endif


    nRetVal = gContext.FindExistingNode(XN_NODE_TYPE_USER, gUserGenerator);
    bUserGenerator = (nRetVal != XN_STATUS_OK);
    if (/*bUserGenerator*/false)
    {
    nRetVal = gUserGenerator.Create(gContext);
    CHECK_RC(nRetVal, bUserGenerator, "Find user generator");
    }

    nRetVal = gContext.FindExistingNode(XN_NODE_TYPE_GESTURE, gGestureGenerator);
    bGestureGenerator = (nRetVal != XN_STATUS_OK);
    if (bGestureGenerator)
    {
    nRetVal = gGestureGenerator.Create(gContext);
    CHECK_RC(nRetVal, bGestureGenerator, "Find gesture generator");

    XnCallbackHandle hGestureCallbacks;
    gGestureGenerator.RegisterGestureCallbacks(gestureRecognized, gestureProcess, 0,
        hGestureCallbacks);
    }

    nRetVal = gContext.FindExistingNode(XN_NODE_TYPE_HANDS,gHandsGenerator);
    bHandsGenerator = (nRetVal != XN_STATUS_OK);
    if (bHandsGenerator)
    {
    nRetVal = gHandsGenerator.Create(gContext);
    CHECK_RC(nRetVal, bHandsGenerator, "Find hands generator");

    XnCallbackHandle hHandsCallbacks;
    gHandsGenerator.RegisterHandCallbacks(handsNew, handsMove,handsLost, 0, hHandsCallbacks);
    }

    nRetVal = gContext.FindExistingNode(XN_NODE_TYPE_DEVICE, gDevice);
    bDevice = (nRetVal != XN_STATUS_OK);

    gContext.RegisterToErrorStateChange(onErrorStateChanged, NULL, hDummyCallbackHandle);

    //Preparo la textura para la webcam
    if (bGenerateRGBTexture)
    mWebcamTexture = KinectTools::createDepthTexture("KinectWebCamTexture", sPluginName);

    return true;
  }
  //-----------------------------------------------------------------------------

  bool IPKinectPlugin::onShutdown()
  {
    if (bContext)
    {
    if (bHandsGenerator)
    {
        gHandsGenerator.StopTrackingAll();
    }
    if (bGestureGenerator)
    {
        gGestureGenerator.RemoveGesture(GESTURE_TO_USE);
        gGestureGenerator.RemoveGesture(GESTURE_TO_START);
    }
    gContext.StopGeneratingAll();
    gContext.Shutdown();
    }

    return true;
  }

Any idea about this issue? Any wrong with this code?

4

1 回答 1

0

也许您在此期间已经找到了解决方案...

我通常使用 Java Wrapper,但我认为与我的代码不同的是,我在创建生成器(Depth、Hands 等)之后调用了 contect.startGeneratingAll()。当我在启动时多次执行此操作时,我也遇到了问题。另一个区别是我在关机时使用了 context.release。

我的程序通常是:

  • 初始化配置(许可证、节点、设置)
  • 创建生成器
  • 开始生成所有
  • 运行你的代码...
  • 停止生成所有
  • 上下文发布

来自 OpenNI 文档

XN_C_API 无效 XN_C_DECL xnShutdown (XnContext * pContext)

关闭 OpenNI 上下文,销毁其所有节点。调用此方法后,请勿调用此上下文的任何函数或任何相关节点。注意:这个函数会破坏上下文和它持有的所有节点,所以应该非常小心地使用。通常你应该只调用 xnContextRelease()

于 2012-07-23T05:26:17.177 回答