Kinect sdk 适用于Windows V2的Kinect
在我的项目中,我需要检测多个手势,我创建了一个包含两个连续手势的.gbd文件。当.gbd文件有一个手势时,我可以检测到连续手势。当有两个手势时,我无法读懂任何一个手势。有人知道原因吗?在这里我张贴我的代码。我使用了sdk中的Body basics示例,并分别添加了必要的函数以避免内存泄漏 //用于初始化数据库、vgb帧源和vgb帧读取器的单独函数 void CBodyBasics::InitializeVGB() { HRESULT-hrKinect sdk 适用于Windows V2的Kinect,kinect-sdk,Kinect Sdk,在我的项目中,我需要检测多个手势,我创建了一个包含两个连续手势的.gbd文件。当.gbd文件有一个手势时,我可以检测到连续手势。当有两个手势时,我无法读懂任何一个手势。有人知道原因吗?在这里我张贴我的代码。我使用了sdk中的Body basics示例,并分别添加了必要的函数以避免内存泄漏 //用于初始化数据库、vgb帧源和vgb帧读取器的单独函数 void CBodyBasics::InitializeVGB() { HRESULT-hr for (int i = 0; i < t_bod
for (int i = 0; i < t_bodyCount; i++)
{
hr = m_pVGBFrameReader[i]->CalculateAndAcquireLatestFrame(&m_pVGBFrame);
if (SUCCEEDED(hr) && m_pVGBFrame != nullptr)
{
OutputDebugString(L"vgb frame\n");
BOOLEAN bGestureTracked = false;
hr = m_pVGBFrame->get_IsTrackingIdValid(&bGestureTracked);
if (SUCCEEDED(hr) && bGestureTracked)
{
OutputDebugString(L"valid gesture id and gesture tracked\n");
GestureType gesturetype;
m_pgesturelist[i]->get_GestureType(&gesturetype);
switch (gesturetype)
{
case GestureType::GestureType_Discrete:
hr = m_pVGBFrame->get_DiscreteGestureResult(m_pgesturelist[i], &m_pDiscreteResult);
if (SUCCEEDED(hr) && m_pDiscreteResult != nullptr)
{
OutputDebugString(L"discrete result\n");
BOOLEAN bDetected = false;
hr = m_pDiscreteResult->get_Detected(&bDetected);
if (SUCCEEDED(hr) && bDetected)
{
OutputDebugString(L"gesture detected\n");
StringCchPrintf(smessage, _countof(smessage), L"gesture detected %d\n", bDetected);
OutputDebugString(smessage);
float confidence = 0.0f;
hr = m_pDiscreteResult->get_Confidence(&confidence);
if (SUCCEEDED(hr) && confidence != 0.0f)
{
OutputDebugString(L"confidence is detected \t");
//if (confidence > 0.3f)
//{
StringCchPrintf(smessage, _countof(smessage), L"confidence value is %f\n", confidence);
OutputDebugString(smessage);
//}
}
else
{
OutputDebugString(L"no confidence\n");
}
}
else
{
OutputDebugString(L"gesture not detected\n");
}
}
else
{
OutputDebugString(L"no discrete result\n");
}
case GestureType::GestureType_Continuous:
hr = m_pVGBFrame->get_ContinuousGestureResult(m_pgesturelist[i], &m_pContinousResult);
if (SUCCEEDED(hr) && m_pContinousResult != nullptr)
{
OutputDebugString(L"continuous gesture\n");
WCHAR gesturename[100];
hr = m_pgesturelist[i]->get_Name(100, gesturename);
//if (gesturename == L"SwipeLeft")
//{
float progress = 0.0f;
OutputDebugString(L"get progress of continuous gesture \t");
hr = m_pContinousResult->get_Progress(&progress);
if (SUCCEEDED(hr) && progress != 0.0f)
{
StringCchPrintf(smessage, _countof(smessage), L"progress value is %f\n", progress);
OutputDebugString(smessage);
}
//}
}
else
{
OutputDebugString(L"no continuous gesture\n");
}
default:
break;
}
}
else
{
OutputDebugString(L"invalid gesture id\n");
}
}
else
{
OutputDebugString(L"no frame\n");
}
}
std::wstring sDbFile=L“continuoussignities.gbd”
hr=CreateVisualGestureBuilderDatabaseInstanceFromFile(sDbFile.c_str(),&m_pGestureDatabase)
{
HRESULT-hr
for (int i = 0; i < t_bodyCount; i++)
{
hr = m_pVGBFrameReader[i]->CalculateAndAcquireLatestFrame(&m_pVGBFrame);
if (SUCCEEDED(hr) && m_pVGBFrame != nullptr)
{
OutputDebugString(L"vgb frame\n");
BOOLEAN bGestureTracked = false;
hr = m_pVGBFrame->get_IsTrackingIdValid(&bGestureTracked);
if (SUCCEEDED(hr) && bGestureTracked)
{
OutputDebugString(L"valid gesture id and gesture tracked\n");
GestureType gesturetype;
m_pgesturelist[i]->get_GestureType(&gesturetype);
switch (gesturetype)
{
case GestureType::GestureType_Discrete:
hr = m_pVGBFrame->get_DiscreteGestureResult(m_pgesturelist[i], &m_pDiscreteResult);
if (SUCCEEDED(hr) && m_pDiscreteResult != nullptr)
{
OutputDebugString(L"discrete result\n");
BOOLEAN bDetected = false;
hr = m_pDiscreteResult->get_Detected(&bDetected);
if (SUCCEEDED(hr) && bDetected)
{
OutputDebugString(L"gesture detected\n");
StringCchPrintf(smessage, _countof(smessage), L"gesture detected %d\n", bDetected);
OutputDebugString(smessage);
float confidence = 0.0f;
hr = m_pDiscreteResult->get_Confidence(&confidence);
if (SUCCEEDED(hr) && confidence != 0.0f)
{
OutputDebugString(L"confidence is detected \t");
//if (confidence > 0.3f)
//{
StringCchPrintf(smessage, _countof(smessage), L"confidence value is %f\n", confidence);
OutputDebugString(smessage);
//}
}
else
{
OutputDebugString(L"no confidence\n");
}
}
else
{
OutputDebugString(L"gesture not detected\n");
}
}
else
{
OutputDebugString(L"no discrete result\n");
}
case GestureType::GestureType_Continuous:
hr = m_pVGBFrame->get_ContinuousGestureResult(m_pgesturelist[i], &m_pContinousResult);
if (SUCCEEDED(hr) && m_pContinousResult != nullptr)
{
OutputDebugString(L"continuous gesture\n");
WCHAR gesturename[100];
hr = m_pgesturelist[i]->get_Name(100, gesturename);
//if (gesturename == L"SwipeLeft")
//{
float progress = 0.0f;
OutputDebugString(L"get progress of continuous gesture \t");
hr = m_pContinousResult->get_Progress(&progress);
if (SUCCEEDED(hr) && progress != 0.0f)
{
StringCchPrintf(smessage, _countof(smessage), L"progress value is %f\n", progress);
OutputDebugString(smessage);
}
//}
}
else
{
OutputDebugString(L"no continuous gesture\n");
}
default:
break;
}
}
else
{
OutputDebugString(L"invalid gesture id\n");
}
}
else
{
OutputDebugString(L"no frame\n");
}
}
for(int i=0;iCalculateAndAcquireLatestFrame(&m_pVGBFrame);
如果(成功(hr)&&m_pVGBFrame!=nullptr)
{
OutputDebugString(L“vgb帧\n”);
布尔bTestureTracked=false;
hr=m_pVGBFrame->get_IsTrackingIdValid(&b测试跟踪);
if(成功(hr)和B测试跟踪(&B)
{
OutputDebugString(L“有效手势id和手势跟踪\n”);
手势类型手势类型;
m_pgesturelist[i]->get_GestureType(&GestureType);
开关(手势类型)
{
案例GestureType::GestureType\u离散:
hr=m_pVGBFrame->get_discretetestureresult(m_pgesturelist[i],&m_pDiscreteResult);
如果(成功(hr)&&m_pDiscreteResult!=nullptr)
{
OutputDebugString(L“离散结果\n”);
布尔bDetected=false;
hr=m_pDiscreteResult->get_Detected(&b检测);
如果(成功(hr)和检测(&B)
{
OutputDebugString(L“检测到手势\n”);
StringCchPrintf(smessage,_countof(smessage),L“检测到手势%d\n”,b检测到);
OutputDebugString(smessage);
浮动置信度=0.0f;
hr=m_pDiscreteResult->get_Confidence(&Confidence);
如果(成功(hr)&置信度!=0.0f)
{
OutputDebugString(L“检测到置信度\t”);
//如果(置信度>0.3f)
//{
StringCchPrintf(smessage,_countof(smessage),L“置信值为%f\n”,置信度);
OutputDebugString(smessage);
//}
}
其他的
{
OutputDebugString(L“不信任\n”);
}
}
其他的
{
OutputDebugString(L“未检测到手势\n”);
}
}
其他的
{
OutputDebugString(L“无离散结果\n”);
}
案例GestureType::GestureType_Continuous:
hr=m_pVGBFrame->get_continuousgesturesult(m_pgesturelist[i],&m_pContinousResult);
if(成功(hr)和&m_pContinousResult!=nullptr)
{
OutputDebugString(L“连续手势\n”);
WCHAR-gesturename[100];
hr=m_pgesturelist[i]->get_Name(100,手势名);
//如果(gesturename==L“SwipeLeft”)
//{
浮动进度=0.0f;
OutputDebugString(L“获取连续手势的进度\t”);
hr=m_pContinousResult->get_Progress(&Progress);
如果(成功(人力资源)和进度!=0.0f)
{
StringCchPrintf(smessage,_countof(smessage),L“进度值为%f\n”,进度);
OutputDebugString(smessage);
}
//}
}
其他的
{
OutputDebugString(L“无连续手势\n”);
}
违约:
打破
}
}
其他的
{
OutputDebugString(L“无效手势id\n”);
}
}
其他的
{
OutputDebugString(L“无帧\n”);
}
}
}
我的代码有错误吗?我需要修改代码吗?有人能帮我吗
void CBodyBasics::ReadVGBFrameMultiple(int t_bodyCount)
for (int i = 0; i < t_bodyCount; i++)
{
hr = m_pVGBFrameReader[i]->CalculateAndAcquireLatestFrame(&m_pVGBFrame);
if (SUCCEEDED(hr) && m_pVGBFrame != nullptr)
{
OutputDebugString(L"vgb frame\n");
BOOLEAN bGestureTracked = false;
hr = m_pVGBFrame->get_IsTrackingIdValid(&bGestureTracked);
if (SUCCEEDED(hr) && bGestureTracked)
{
OutputDebugString(L"valid gesture id and gesture tracked\n");
GestureType gesturetype;
m_pgesturelist[i]->get_GestureType(&gesturetype);
switch (gesturetype)
{
case GestureType::GestureType_Discrete:
hr = m_pVGBFrame->get_DiscreteGestureResult(m_pgesturelist[i], &m_pDiscreteResult);
if (SUCCEEDED(hr) && m_pDiscreteResult != nullptr)
{
OutputDebugString(L"discrete result\n");
BOOLEAN bDetected = false;
hr = m_pDiscreteResult->get_Detected(&bDetected);
if (SUCCEEDED(hr) && bDetected)
{
OutputDebugString(L"gesture detected\n");
StringCchPrintf(smessage, _countof(smessage), L"gesture detected %d\n", bDetected);
OutputDebugString(smessage);
float confidence = 0.0f;
hr = m_pDiscreteResult->get_Confidence(&confidence);
if (SUCCEEDED(hr) && confidence != 0.0f)
{
OutputDebugString(L"confidence is detected \t");
//if (confidence > 0.3f)
//{
StringCchPrintf(smessage, _countof(smessage), L"confidence value is %f\n", confidence);
OutputDebugString(smessage);
//}
}
else
{
OutputDebugString(L"no confidence\n");
}
}
else
{
OutputDebugString(L"gesture not detected\n");
}
}
else
{
OutputDebugString(L"no discrete result\n");
}
case GestureType::GestureType_Continuous:
hr = m_pVGBFrame->get_ContinuousGestureResult(m_pgesturelist[i], &m_pContinousResult);
if (SUCCEEDED(hr) && m_pContinousResult != nullptr)
{
OutputDebugString(L"continuous gesture\n");
WCHAR gesturename[100];
hr = m_pgesturelist[i]->get_Name(100, gesturename);
//if (gesturename == L"SwipeLeft")
//{
float progress = 0.0f;
OutputDebugString(L"get progress of continuous gesture \t");
hr = m_pContinousResult->get_Progress(&progress);
if (SUCCEEDED(hr) && progress != 0.0f)
{
StringCchPrintf(smessage, _countof(smessage), L"progress value is %f\n", progress);
OutputDebugString(smessage);
}
//}
}
else
{
OutputDebugString(L"no continuous gesture\n");
}
default:
break;
}
}
else
{
OutputDebugString(L"invalid gesture id\n");
}
}
else
{
OutputDebugString(L"no frame\n");
}
}