无法让 FaceTracker class 在 HoloLens 2 上工作

Can't get FaceTracker class to work on HoloLens 2

我无法让 FaceTracker Class 在 HoloLens 2 上工作。 一旦我尝试用 ProcessNextFrameAsync Method 检测面孔,我就会得到以下类型的异常:

System.Runtime.InteropServices.COMException (0x80004005): Unspecified error

这只是错误消息的第一部分,如果需要更多信息,我可以添加。

请参阅此处的最小示例。

public async void Start()
{
    var selectedGroup = await FindCameraAsync();
    await StartMediaCaptureAsync(selectedGroup);
}
private async Task StartMediaCaptureAsync(MediaFrameSourceGroup sourceGroup)
{
    faceTracker = await FaceTracker.CreateAsync();
    this.mediaCapture = new MediaCapture();
    await this.mediaCapture.InitializeAsync(settings);
    this.frameProcessingTimer = ThreadPoolTimer.CreatePeriodicTimer(ProcessCurrentVideoFrameAsync, timerInterval);
}
private async Task ProcessCurrentVideoFrameAsync()
{
    const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12;
    var deviceController = this.mediaCapture.VideoDeviceController;
    this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
    VideoFrame videoFrame = new VideoFrame(InputPixelFormat, (int)this.videoProperties.Width (int)this.videoProperties.Height);

    IList<DetectedFace> detectedFaces;
    try
    {
        detectedFaces = await faceTracker.ProcessNextFrameAsync(videoFrame);
    }
    catch (Exception e)
    {
        System.Diagnostics.Debug.WriteLine($"Failed with Exception: {e.ToString()}");
        return;
    }

    videoFrame.Dispose();
}
  1. 我得到了 MediaFrameSourceKind.ColorMediaStreamType.VideoPreview FindCameraAsync() 合适的相机。我认为哪个效果很好。
  2. 开始MediaCaptureFaceTrackerStartMediaCaptureAsync()
  3. 尝试检测 ProcessCurrentVideoFrameAsync()
  4. 中的人脸

以下是我测试过的东西和收到的信息:

非常感谢每一次的鼓励和思考。

2020 年 7 月 14 日更新

我刚刚在本地存储在 HoloLens 2 上的几张单独图像上尝试了 FaceDetector。效果很好。

尽管 FaceDetectorFaceTracker 不完全相同,但它们非常相似。所以我猜这个问题在某种程度上与 MediaCapture.

有关

接下来我将尝试使用 MediaCapture 捕获图像并使用 FaceDetector 进行处理。

如果在此期间有人有更多想法,我将不胜感激。

这是一个官方示例,展示了如何使用 FaceTracker class 在视频流中查找人脸:Basic face tracking sample。而在第 256 行,这是从捕获设备获取预览帧的要点。

但是,根据您的代码,您创建了一个 VideoFrame object and specified the properties and format to it, but you are missing invoke GetPreviewFrameAsync 来将本机网络摄像头框架转换为 VideoFrame 对象。

您可以尝试使用以下代码修复:

private async Task ProcessCurrentVideoFrameAsync()
{
    const BitmapPixelFormat InputPixelFormat = BitmapPixelFormat.Nv12;
    var deviceController = this.mediaCapture.VideoDeviceController;
    this.videoProperties = deviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;
    VideoFrame videoFrame = new VideoFrame(InputPixelFormat, (int)this.videoProperties.Width (int)this.videoProperties.Height);

//add this line code.
    await this.mediaCapture.GetPreviewFrameAsync(videoFrame);