faceframe kinect2.0 api 注意点

首先要给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);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 Android 相机预览界面中添加人像框,可以通过在 SurfaceView 或 TextureView 上叠加一个带有透明背景的 ImageView 来实现。以下是实现步骤: 1. 在布局文件中添加 SurfaceView 或 TextureView 和 ImageView。 ```xml <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- SurfaceView 或 TextureView --> <SurfaceView android:id="@+id/surface_view" android:layout_width="match_parent" android:layout_height="match_parent" /> <!-- 带有透明背景的 ImageView --> <ImageView android:id="@+id/face_frame" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:src="@drawable/face_frame" /> </RelativeLayout> ``` 其中,@drawable/face_frame 是一个带有人像框的图片资源。 2. 调整 ImageView 的位置和大小,使其与预览画面重合。 ```java SurfaceView surfaceView = findViewById(R.id.surface_view); ImageView faceFrame = findViewById(R.id.face_frame); surfaceView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // 获取 SurfaceView 的宽高 int width = surfaceView.getWidth(); int height = surfaceView.getHeight(); // 调整 ImageView 的位置和大小 RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) faceFrame.getLayoutParams(); layoutParams.width = width / 2; layoutParams.height = height / 2; layoutParams.leftMargin = width / 4; layoutParams.topMargin = height / 4; faceFrame.setLayoutParams(layoutParams); // 只需要调整一次,移除监听器 surfaceView.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); ``` 其中,调整 ImageView 的位置和大小需要在 SurfaceView 的尺寸确定后进行,因此需要在 onGlobalLayout 回调中进行。 3. 调用相机 API 开始预览。 ```java private Camera camera; private Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() { @Override public void onPreviewFrame(byte[] data, Camera camera) { // 获取预览数据的 byte 数组 } }; private void startCameraPreview() { camera = Camera.open(); try { camera.setPreviewDisplay(surfaceView.getHolder()); camera.setPreviewCallback(previewCallback); camera.startPreview(); } catch (IOException e) { e.printStackTrace(); } } ``` 在预览回调中,可以获取预览数据的 byte 数组,用于后续的人脸检测等操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值