什么是Windows.Media.IVideoFrameStatics?

时间:2019-04-14 20:08:38

标签: unity3d uwp hololens

我试图将faceTacker应用于hololens。为此,我使用Hololens Camera Stream,因为MediaCapture使用了XAML中的CaptureElement。 我的问题是当我为FaceTracker实现videoFrame时出现此错误:

System.InvalidCastException: Unable to cast object of type 'System.__ComObject' to type 'Windows.Media.IVideoFrameStatics'.
   at System.StubHelpers.StubHelpers.GetCOMIPFromRCW_WinRT(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget)
   at Windows.Media.VideoFrame.CreateWithSoftwareBitmap(SoftwareBitmap bitmap)
   at test02.OnFrameSampleAcquired(VideoCaptureSample sample)

当我在Google上编写它时,我得到了有关Windows Media Player的结果,所以我不知道它是什么以及如何解决它...

这是我的代码:

    void OnFrameSampleAcquired(VideoCaptureSample sample)
    {
        if (frameSample == null || frameSample.Length < sample.dataLength)
        {
            frameSample = new byte[sample.dataLength];
        }

        sample.CopyRawImageDataIntoBuffer(frameSample);

        IBuffer ibuffer = null;
        if(frameSample != null)
            ibuffer = frameSample.AsBuffer();
        else
            Debug.Log("frameSample null");

        SoftwareBitmap softwareBitmapFrameSample = new SoftwareBitmap(BitmapPixelFormat.Nv12, this._resolution.width, this._resolution.height);
        softwareBitmapFrameSample.CopyFromBuffer(ibuffer);

        if(softwareBitmapFrameSample == null)
            Debug.Log("Failed to create SoftwareBitmap");
        else
            Debug.Log("SoftwareBitmap success");
        try
        {
            Debug.Log("BEFORE VIDEOfRAME");
            VideoFrame videoFrameSample = VideoFrame.CreateWithSoftwareBitmap(softwareBitmapFrameSample);
        }catch(Exception ex){
            Debug.Log(ex);
        }/*
        UnityEngine.WSA.Application.InvokeOnAppThread(() =>
        {
//                faces = await this.faceTracker.ProcessNextFrameAsync();
        }, false);*/
}

感谢您的帮助

0 个答案:

没有答案