- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个相当简单的应用程序,其中包含以下内容:
context->mFaceTracker = FTCreateFaceTracker();
hr = context->mFaceTracker->Initialize( &mVideoCameraConfig, &mDepthCameraConfig, NULL, NULL );
它工作正常并返回 S_OK,并且 mFaceTracker(据我所知)已正确初始化。然而,下一行是:
hr = context->mFaceTracker->CreateFTResult( &context->mFTResult );
它总是返回 FT_ERROR_UNINITIALIZED,没有分配指针,这让我很困惑。我已经尝试了很多不同的策略来让它工作,从改变设备和检测器的线程工作方式,到将我的 FTcontext 对象从类更改为结构以匹配样本,但都没有成功。 Kinect SDK 样本都工作正常,但尝试在我自己的应用程序中使用它们似乎并没有,尽管我密切关注它们如何初始化设备和面部跟踪器。我很好奇是否还有其他人在初始化 IFTFaceTracker 或 IFTResult 时遇到过这个或类似的问题。此外,我很好奇除了测试 Initialize() 返回的 HRESULT 之外,我还能如何测试 IFTFaceTracker 是否正确初始化。提前致谢,
===编辑
我收到了一些需要更多代码的请求。它建立在 Cinder 上,并为 Cinder 使用此 block :https://github.com/BanTheRewind/Cinder-KinectSdk
我不能发布所有的代码,但我至少在这里发布了大部分相关的 Kinect 初始化代码:
void Kinect::start( const DeviceOptions &deviceOptions )
{
if ( !mCapture ) {
// Copy device options
mDeviceOptions = deviceOptions;
string deviceId = mDeviceOptions.getDeviceId();
int32_t index = mDeviceOptions.getDeviceIndex();
// Clamp device index
if ( index >= 0 ) {
index = math<int32_t>::clamp( index, 0, math<int32_t>::max( getDeviceCount() - 1, 0 ) );
}
// Initialize device instance
long hr = S_OK;
if ( index >= 0 ) {
hr = NuiCreateSensorByIndex( index, &mSensor );
if ( FAILED( hr ) ) {
trace( "Unable to create device instance " + toString( index ) + ": " );
error( hr );
return;
}
} else if ( deviceId.length() > 0 ) {
_bstr_t id = deviceId.c_str();
hr = NuiCreateSensorById( id, &mSensor );
if ( FAILED( hr ) ) {
trace( "Unable to create device instance " + deviceId + ":" );
error( hr );
return;
}
} else {
trace( "Invalid device name or index." );
return;
}
// Check device
hr = mSensor != 0 ? mSensor->NuiStatus() : E_NUI_NOTCONNECTED;
if ( hr == E_NUI_NOTCONNECTED ) {
error( hr );
return;
}
// Get device name and index
if ( mSensor != 0 ) {
mDeviceOptions.setDeviceIndex( mSensor->NuiInstanceIndex() );
BSTR id = ::SysAllocString( mSensor->NuiDeviceConnectionId() );
_bstr_t idStr( id );
if ( idStr.length() > 0 ) {
std::string str( idStr );
mDeviceOptions.setDeviceId( str );
}
::SysFreeString( id );
} else {
index = -1;
deviceId = "";
}
flags |= NUI_INITIALIZE_FLAG_USES_COLOR;
}
hr = mSensor->NuiInitialize( flags );
if ( FAILED( hr ) ) {
trace( "Unable to initialize device " + mDeviceOptions.getDeviceId() + ":" );
error( hr );
return;
}
hr = mSensor->NuiSkeletonTrackingEnable( 0, flags );
if ( FAILED( hr ) ) {
trace( "Unable to initialize skeleton tracking for device " + mDeviceOptions.getDeviceId() + ": " );
error( hr );
return;
}
mIsSkeletonDevice = true;
mThread = CreateThread(NULL, 0, &Kinect::StaticThread, (PVOID)this, 0, 0);
}
}
DWORD WINAPI Kinect::StaticThread(PVOID lpParam)
{
Kinect* device = static_cast<Kinect*>(lpParam);
if (device)
{
return device->run();
}
return 0;
}
void run() {
if(mSensor) {
if(mEnabledFaceTracking)
{
if(mNeedFaceTracker) {
mFaceTracker = new FaceTracker(
mDeviceOptions.getVideoSize().x,
mDeviceOptions.getVideoSize().y,
mDeviceOptions.getDepthSize().x,
mDeviceOptions.getDepthSize().y,
1.0,
1 );
mNeedFaceTracker = false;
}
// make sure we have both color && depth buffers to work with
if(newDepth || newVideo)
{
FT_SENSOR_DATA sensorData(mFTColorImage, mFTDepthImage);
FT_VECTOR3D hint[2]; // this is initialized elsewhere
mFaceTracker->checkFaces( (NUI_SKELETON_FRAME*) &skeletonFrame, mFTColorImage, mFTDepthImage, 1.0, 0);
if(mFaceTracker->getNumFaces() > 0) {
cout << " we have a face " << mFaceTracker->getNumFaces() << endl;
mNewFaceTrackData = true;
mFaceData.clear();
for( int i = 0; i < mFaceTracker->getNumFaces(); i++) {
Face newFace;
mFaceTracker->getProjectedShape(0, newFace.scale, newFace.rotation, newFace.transform, newFace.screenPositions);
mFaceData.push_back(newFace);
}
}
}
}
Sleep( 8 );
}
}
最佳答案
看起来您从未调用(或在代码示例中省略)NuiImageStreamOpen(),例如来自 SingleFace 示例的代码片段,Init 方法中的 KinectSensor.cpp:
hr = NuiImageStreamOpen(
colorType,
colorRes,
0,
2,
m_hNextVideoFrameEvent,
&m_pVideoStreamHandle );
if (FAILED(hr))
{
return hr;
}
hr = NuiImageStreamOpen(
depthType,
depthRes,
(bNearMode)? NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE : 0,
2,
m_hNextDepthFrameEvent,
&m_pDepthStreamHandle );
在调用 CreateFTResult() 之前调用它们可能会修复未初始化的错误。
此外,您调用 CreateThread(),然后调用 run(),但没有 while 循环,因此线程几乎会立即退出,当然没有足够的时间让 Kinect 开始向 FaceTracking 提供数据。
您似乎没有包含正在检查传感器的新数据、更新 mFTColorImage 和 mFTDepthImage 以及设置 newDepth 和 newVideo 标志的线程或事件循环。这可能与您在上面创建的线程相同(前提是您创建了一个 while 循环,并忽略性能或其他需要 Kinect 数据的类),或者可能是与 SingleFace Kinect SDK 示例中不同的线程。
关于c++ - MS Kinect FaceTracker 创建 IFTResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11769786/
我正在尝试使用 Kinect Facetracking 控制机器人炮塔。当用户移动他的头时,炮塔会朝相同的方向移动。我能够获得用户头部的偏航、俯仰和滚动,并使用这些数据控制炮塔。我目前的尝试有效,但不
我有一个相当简单的应用程序,其中包含以下内容: context->mFaceTracker = FTCreateFaceTracker(); hr = context->mFaceTracker->I
好的。我按照本网站上的“使用 CMake 构建”指令集进行操作: http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port 我制作了一个“bui
我是一名优秀的程序员,十分优秀!