我正在为使用相机拍照的 Microsoft Hololens 在 Unity 引擎中开发一个应用程序。在我们的代码中,首先拍照模式和相机启动,拍照,然后相机被丢弃,拍照模式结束。用户必须在此应用程序的主要功能过程中拍摄几张照片。图片没有存储在任何地方,我们只从它们中获取颜色。
下面是拍照代码:
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
targetTexture = new Texture2D(cameraResolution.width, cameraResolution.height);
// Create a PhotoCapture object
PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject)
{
photoCaptureObject = captureObject;
CameraParameters cameraParameters = new CameraParameters();
cameraParameters.hologramOpacity = 0.0f;
cameraParameters.cameraResolutionWidth = cameraResolution.width;
cameraParameters.cameraResolutionHeight = cameraResolution.height;
cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
// Activate the camera
photoCaptureObject.StartPhotoModeAsync(cameraParameters, delegate (PhotoCapture.PhotoCaptureResult result)
{
// Take a picture
try
{
Debug.Log("Trying to take photo");
photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
}
catch (System.ArgumentException e)
{
Debug.LogError("System.ArgumentException:\n" + e.Message);
}
});
});
然后将其处理为:
void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
{
// Shutdown our photo capture resource
Debug.Log("Disposing of camera");
photoCaptureObject.Dispose();
photoCaptureObject = null;
}
这段代码非常适合我们的项目 - 每次用户点击一个对象时,我们都会拍摄一张照片并从中获取颜色。
由于这是针对 CS 课程中的高级设计项目,因此我们希望向全班展示视频或现场演示。
但是,只要我们的应用程序尝试拍照,记录就会停止。我们无法使用网络摄像头录制视频,也无法在录制时使用我们的上述代码拍照。这是有道理的,似乎我们的应用程序必须从录制过程中抢占网络摄像头才能使用它。这也适用于通过设备门户流式传输视频。
这意味着我们永远无法录制我们正在运行的项目的演示。只要我们的应用程序访问相机,视频录制就会结束。
我发现几年前的帖子和帖子询问过这个问题,但没有一个得到解决。现在有已知的解决方法吗?有什么方法可以让我获得我的项目的视频,同时仍然使用它在应用程序内拍照?