c++ - 如何在程序运行时检测kinect何时断开/拔出?

标签 c++ visual-c++ kinect

我正在使用官方 Kinect SDK 1.5 示例之一,我正在尝试了解如何添加检查以检测 Kinect 何时断开连接。目前,该应用程序只会卡住,因此必须有一种方法来防止这种情况发生。

这是来自 SDK 示例的主要消息循环:

// Main message loop
while (WM_QUIT != msg.message)
{
    hEvents[0] = m_hNextDepthFrameEvent;

    // Check to see if we have either a message (by passing in QS_ALLINPUT)
    // Or a Kinect event (hEvents)
    // Update() will check for Kinect events individually, in case more than one are signalled
    DWORD dwEvent = MsgWaitForMultipleObjects(eventCount, hEvents, FALSE, INFINITE, QS_ALLINPUT);

    // Check if this is an event we're waiting on and not a timeout or message
    if (WAIT_OBJECT_0 == dwEvent)
    {
        Update();
    }

    // does not work.
    bool bla = m_pNuiSensor->NuiStatus();
    if (NULL == m_pNuiSensor)
    {
            cout << 1 << endl;
    }

    if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
    {
        // If a dialog message will be taken care of by the dialog proc
        if ((hWndApp != NULL) && IsDialogMessageW(hWndApp, &msg))
        {
            continue;
        }

        TranslateMessage(&msg);
        DispatchMessageW(&msg);
    }
}

return static_cast<int>(msg.wParam);

我添加了以下内容:

    // does not work, bla will always be the same value.
    bool bla = m_pNuiSensor->NuiStatus();
    if (NULL == m_pNuiSensor)
    {
            cout << 1 << endl;
    }

因为我假设 NuiStatus 可能是一种检测断开连接的方法。不幸的是它不会工作。检查m_pNuiSensor是否为NULL也是如此。

那么检测正在运行的应用程序断开连接的方法是什么?

EDIT1:我应该使用 NuiSetDeviceStatusCallback 吗?

最佳答案

documentation它说 NuiStatus 返回 HRESULT 而不是 bool,所以它不应该是

HRESULT bla = m_pNuiSensor->NuiStatus();
if (bla == E_NUI_NOTCONNECTED)
{
        cout << 1 << endl;
}

代替?

关于c++ - 如何在程序运行时检测kinect何时断开/拔出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12691222/

相关文章:

c++ - openFrameworks 和 Kinect : Improve human contour

c++ - 类中数据大小的整数模板参数

c++ - 如何推断以引用为参数的函数的返回类型

c++ - Visual Studios 2008 中 C++ 开发中的链接错误

c# - C# 中的 Windows .NET 程序与 C++ 中的 Linux 程序之间的 TCP

C#快速像素渲染

c++ - 如何通过 C++ 访问硬盘驱动器的文件系统和扇区?

C++ 从 bool 到字符串的隐式转换

c++ - vc++ 应用程序按序号调用 vc++ dll

c++ - std::function 绑定(bind)到成员函数