【发布时间】:2019-03-26 11:12:04
【问题描述】:
我正在尝试使用我的 PhotoCapture 统一脚本通过 Hololens 拍照。我想使用 Vuforia Engine ARCamera,以便在看到我创建的 AR-GUI 的同时看到现实(用于未来的功能)。
我得到的主要错误是:
拍摄照片失败(hr = 0xC00D3704)
为什么会这样?我该如何解决?
FocusManager 单例尚未初始化。 UnityEngine.Debug:断言(布尔值,字符串) HoloToolkit.Unity.Singleton`1:AssertIsInitialized() (在 资产/HoloToolkit/Common/Scripts/Singleton.cs:51) HoloToolkit.Unity.CanvasHelper:Start() (在 Assets/HoloToolkit/Utilities/Scripts/CanvasHelper.cs:30)
也是启动unity场景的时候出现的错误,但是我之前没有出现过...
这是我正在使用的代码,放置在 ARCamera 上(还尝试了带有 vuforia 行为脚本的混合现实相机,但没有出现第二个错误)。另外,我想向借用此代码的人道歉,因为我不记得指向您网站的链接。
public class PhotoCaptureExample : MonoBehaviour
{
PhotoCapture photoCaptureObject = null;
Texture2D targetTexture = null;
public string path = "";
CameraParameters cameraParameters = new CameraParameters();
void Start()
{
}
void Update()
{
if (Input.GetKeyDown("k"))
{
Debug.Log("k was pressed");
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.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
photoCaptureObject.TakePhotoAsync(OnCapturedPhotoToMemory);
});
});
}
}
string FileName(int width, int height)
{
return string.Format("screen_{0}x{1}_{2}.png", width, height, DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
}
void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
{
// Copy the raw image data into the target texture
photoCaptureFrame.UploadImageDataToTexture(targetTexture);
Resolution cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
targetTexture.ReadPixels(new Rect(0, 0, cameraResolution.width, cameraResolution.height), 0, 0);
targetTexture.Apply();
byte[] bytes = targetTexture.EncodeToPNG();
string filename = FileName(Convert.ToInt32(targetTexture.width), Convert.ToInt32(targetTexture.height));
//save to folder under assets
File.WriteAllBytes(Application.dataPath + "/Snapshots/" + filename, bytes);
Debug.Log("The picture was uploaded");
// Deactivate the camera
photoCaptureObject.StopPhotoModeAsync(OnStoppedPhotoMode);
}
void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
{
// Shutdown the photo capture resource
photoCaptureObject.Dispose();
photoCaptureObject = null;
}
}
我似乎无法到达OnCapturedPhotoToMemory,或者它已经被方法调用中断了。现在再次尝试,代码偶尔不会注册我已经推送了k...
感谢任何帮助!
【问题讨论】:
-
FocusManager 被设置成什么?这真的是统一脚本吗?对我来说它看起来像普通的 c#
-
老实说,我不知道 FocusManager 是什么或它来自哪里:S 它之前没有出现,但是当我从 holotoolkits mixedRealityCamera 改回 ARCamera 时可能已经发生了。 . 它是C#,但与统一脚本(统一编写的脚本)不兼容吗?
-
哦,对不起,我打错标签了!!!
-
好的,但是它告诉你焦点管理器尚未设置,这似乎是错误的第一点?
-
@BugFinder 是的。出现错误后,在 SimpleSinglePointerSelector 私有 void Start() 方法中对
FocusManager.AssertIsInitialized();进行了 3 次调用。 CanvasHelper 中的一个私有 void Start() 方法。还有一个在 CanvaseditorExtention 中检查“我们的场景中是否有焦点管理器”。这些我都没有碰过。
标签: c# unity3d vuforia hololens