新手求助:HoloLens 2 AR应用中如何访问相机流实现标记识别?
Hey there! Let’s work through your HoloLens 2 marker recognition issue together— I’ve tackled similar problems with MRTK and camera streams, so here’s a step-by-step breakdown to get things working:
First off, HoloLens is strict about hardware permissions, so let’s make sure your app has access to the camera:
- Open
Edit > Project Settings > Player > Publishing Settings > Capabilities - Ensure Webcam and SpatialPerception are both checked (SpatialPerception helps with alignment, even if you’re just using markers)
- If you haven’t already, add runtime permission requests in your code. HoloLens won’t auto-grant camera access on first launch:
using UnityEngine; void Start() { if (!WebCamDevice.HasUserAuthorization()) { WebCamDevice.RequestUserAuthorization(); } }
MRTK handles HoloLens’s camera pipeline natively— manually adding AR camera components or custom cameras will almost always cause conflicts:
- Delete any custom AR cameras or AR-related components you added to the Main Camera
- Run
Mixed Reality Toolkit > Configure > Apply Mixed Reality Project Settings— this auto-sets up the correct Main Camera with theMixed Reality Cameracomponent - Confirm the Main Camera is a child of
MixedRealityPlaySpace(it should be by default after running the setup tool)
Before troubleshooting marker recognition, confirm the camera feed is reaching your app:
- Add a
RawImageto your UI Canvas - Attach this simple debug script to the Canvas:
using UnityEngine; using UnityEngine.UI; public class CameraFeedDebug : MonoBehaviour { public RawImage debugDisplay; private WebCamTexture camTexture; void Start() { if (WebCamDevice.HasUserAuthorization()) { WebCamDevice[] devices = WebCamTexture.devices; if (devices.Length > 0) { camTexture = new WebCamTexture(devices[0].name, 1920, 1080); debugDisplay.texture = camTexture; camTexture.Play(); } } } void OnDestroy() => camTexture?.Stop(); } - Deploy to HoloLens— if you see the camera feed in the UI, the stream is working; if not, circle back to permissions or MRTK setup.
HoloLens’s camera has unique specs that might not match your external camera setup:
- HoloLens 2’s main camera runs at 1920x1080@30fps with a ~60° horizontal FOV
- Update your marker recognition library’s camera settings to match these values:
- For Vuforia: In the
AR Cameracomponent, select "HoloLens Camera" as the device, set focus mode to Auto, and input the correct resolution/FOV - For ARToolKit: Adjust the
ARController’s camera width/height to 1920/1080 and set FOV to 60°
- For Vuforia: In the
- Make sure the library is using perspective projection (HoloLens doesn’t use orthogonal cameras)
Multiple active cameras or modified camera properties can block the marker recognition library from accessing the stream:
- Ensure only the MRTK Main Camera is enabled in your scene
- Check for scripts that modify the camera’s
targetTexture,cullingMask, ordepth— these can override the feed going to your marker library
If all else fails, isolate the issue with a clean project:
- Create a new Unity project, import MRTK Foundation and your marker library
- Set up only the essentials:
MixedRealityPlaySpace, MRTK-configured Main Camera, marker prefab, and the camera feed debug UI - Deploy to HoloLens— if markers work here, your original project has conflicting components or settings to track down
Hope these steps get your marker recognition up and running on HoloLens 2!
内容的提问来源于stack exchange,提问作者Imran Khan

