首先要给futures绑定,注意需要用的几个
static const DWORD THIS_APP_FACE_FRAME_FEATURES =
FaceFrameFeatures::FaceFrameFeatures_BoundingBoxInColorSpace
|FaceFrameFeatures::FaceFrameFeatures_BoundingBoxInInfraredSpace
| FaceFrameFeatures::FaceFrameFeatures_PointsInColorSpace
| FaceFrameFeatures::FaceFrameFeatures_RotationOrientation
| FaceFrameFeatures::FaceFrameFeatures_Happy
| FaceFrameFeatures::FaceFrameFeatures_RightEyeClosed
| FaceFrameFeatures::FaceFrameFeatures_LeftEyeClosed
| FaceFrameFeatures::FaceFrameFeatures_MouthOpen
| FaceFrameFeatures::FaceFrameFeatures_MouthMoved
| FaceFrameFeatures::FaceFrameFeatures_LookingAway
| FaceFrameFeatures::FaceFrameFeatures_Glasses
| FaceFrameFeatures::FaceFrameFeatures_FaceEngagement;
//为每个body创建一个source,注意绑定的features
IFaceFrameSource * myFaceFrameSources[BODY_COUNT];
IFaceFrameReader* myFaceFrameReaders[BODY_COUNT];
HRESULT hrface = false;
for (int i = 0; i < BODY_COUNT;i++){
hrface = CreateFaceFrameSource(myKinectSecsor, 0, THIS_APP_FACE_FRAME_FEATURES, &myFaceFrameSources[i]);
if (SUCCEEDED(hrface)){
hrface = myFaceFrameSources[i]->OpenReader(&myFaceFrameReaders[i]);
}
}
//get face point
HRESULT hr3 = false;vector<RectI> myFaceRect;
for (int iFace = 0; iFace < BODY_COUNT; ++iFace)
{
// retrieve the latest face frame from this reader
IFaceFrame* pFaceFrame = nullptr;
hr3 = myFaceFrameReaders[iFace]->AcquireLatestFrame(&pFaceFrame);
BOOLEAN bFaceTracked = false;
if (SUCCEEDED(hr3) && nullptr != pFaceFrame)
{
// check if a valid face is tracked in this face frame
hr3 = pFaceFrame->get_IsTrackingIdValid(&bFaceTracked);
}
if (SUCCEEDED(hr3))
{
if (bFaceTracked)
{
IFaceFrameResult* pFaceFrameResult = nullptr;
RectI faceBox = { 0 };
RectI depthBox = {0};
PointF facePoints[FacePointType::FacePointType_Count];
hr3 = pFaceFrame->get_FaceFrameResult(&pFaceFrameResult);
// need to verify if pFaceFrameResult contains data before trying to access it
if (SUCCEEDED(hr3) && pFaceFrameResult != nullptr)
{
hr3=pFaceFrameResult->get_FaceBoundingBoxInColorSpace(&faceBox);
hr3=pFaceFrameResult->get_FaceBoundingBoxInInfraredSpace(&depthBox);
myFaceRect.push_back(depthBox);
cv::rectangle(bufferMat, cv::Point(faceBox.Left, faceBox.Top), cv::Point(faceBox.Right, faceBox.Bottom), cvScalar(0, 0, 255), 2);
if (SUCCEEDED(hr3))
{
hr3 = pFaceFrameResult->GetFacePointsInColorSpace(FacePointType::FacePointType_Count, facePoints);
}
for (int i = 0; i < 5; i++)
{
cv::circle(bufferMat, cv::Point(facePoints[i].X, facePoints[i].Y),2, cvScalar(255), 2);
}
}
destory(pFaceFrameResult);
}else if (myBody[iFace]){ //如果该body没被绑定,而这个body的骨骼又被提取到了,那么用下面的id来给source绑定上id
BOOLEAN bTracked = false;
// 检查被骨骼跟踪没有
hr3 = myBody[iFace]->get_IsTracked(&bTracked);
UINT64 bodyTId;
if (SUCCEEDED(hr3) && bTracked) {
// 获取跟踪id
hr3 = myBody[iFace]->get_TrackingId(&bodyTId);
if (SUCCEEDED(hr3)) {
// 更新跟踪id
myFaceFrameSources[iFace]->put_TrackingId(bodyTId);
}
}
}
}
destory(pFaceFrame);
}