HoloLens With OpenCVForUnity Example
Demo Video (old version)

Environment
:warning:IMPORTANT: Development Environment Setup
The setup procedure for HoloLens projects using Unity and MRTK has changed significantly. The legacy Mixed Reality Feature Tool no longer functions on the latest Windows 11 environments.
Prerequisites (OpenXR Stack)
To run this project, you must import the following assets:
The MRTK3 package versions used by this project are based on the following GitHub release:
Note: MRTK3 packages are independently versioned. There is no single unified MRTK3 version number. The versions below correspond to the packages included in the above release.
| Package |
Version |
org.mixedrealitytoolkit.core |
3.3.0 |
org.mixedrealitytoolkit.input |
3.3.0 |
org.mixedrealitytoolkit.uxcore |
3.3.0 |
org.mixedrealitytoolkit.spatialmanipulation |
3.4.0 |
org.mixedrealitytoolkit.uxcomponents |
3.4.0 |
org.mixedrealitytoolkit.uxcomponents.noncanvas |
3.1.5 |
org.mixedrealitytoolkit.standardassets |
3.2.1 |
Installation Order
Please install the packages in the following specific order to ensure all dependencies are resolved correctly:
-
Unity OpenXR Plugin
-
Add the following line to the dependencies section of the manifest.json file:
"com.unity.xr.openxr": "1.14.3",
-
Microsoft Mixed Reality OpenXR Plugin
-
Add the following line to the dependencies section of the manifest.json file:
"com.microsoft.mixedreality.openxr": "1.11.2",
-
MRTK Graphics Tools
-
Add the following line to the dependencies section of the manifest.json file:
"com.microsoft.mrtk.graphicstools.unity": "https://github.com/microsoft/MixedReality-GraphicsTools-Unity.git?path=/com.microsoft.mrtk.graphicstools.unity#v0.8.1",
-
MRTK Core Definitions (org.mixedrealitytoolkit.core 3.3.0)
-
MRTK Input (org.mixedrealitytoolkit.input 3.3.0)
- Download
org.mixedrealitytoolkit.input-3.3.0.tgz from the same MRTK3 GitHub release.
- Import it using UPM’s Add package from tarball… option.
-
MRTK UX Core (org.mixedrealitytoolkit.uxcore 3.3.0)
- Download
org.mixedrealitytoolkit.uxcore-3.3.0.tgz from the same MRTK3 GitHub release.
- Import it using UPM’s Add package from tarball… option.
-
MRTK Spatial Manipulation (org.mixedrealitytoolkit.spatialmanipulation 3.4.0)
- Download
org.mixedrealitytoolkit.spatialmanipulation-3.4.0.tgz from the same MRTK3 GitHub release.
- Import it using UPM’s Add package from tarball… option.
-
MRTK Standard Assets (org.mixedrealitytoolkit.standardassets 3.2.1)
- Download
org.mixedrealitytoolkit.standardassets-3.2.1.tgz from the same MRTK3 GitHub release.
- Import it using UPM’s Add package from tarball… option.
-
MRTK UX Components (org.mixedrealitytoolkit.uxcomponents 3.4.0)
- Download
org.mixedrealitytoolkit.uxcomponents-3.4.0.tgz from the same MRTK3 GitHub release.
- Import it using UPM’s Add package from tarball… option.
-
MRTK UX Components (Non-Canvas) (org.mixedrealitytoolkit.uxcomponents.noncanvas 3.1.5)
- Download
org.mixedrealitytoolkit.uxcomponents.noncanvas-3.1.5.tgz from the same MRTK3 GitHub release.
- Import it using UPM’s Add package from tarball… option.
Setup (Unity 2022 / Built-in Render Pipeline / OpenXR / MRTK 3 / DirectX 11 / Visual Studio 2022)
-
Download the latest release .unitypackage.
-
Create a new Unity project.
- Use
HoloLensWithOpenCVForUnityExample as the project name.
- Change the platform to
UWP in the Build Settings window.
-
Import and configure the Unity OpenXR Plugin, Microsoft Mixed Reality OpenXR Plugin, Mixed Reality Graphics Tools, and MRTK3.
-
Import OpenCVForUnity.
-
Select Tools > OpenCV for Unity > Open Setup Tools.
-
Click the Move StreamingAssets Folder button.
-
Keep the following files and delete the rest:
StreamingAssets/OpenCVForUnity/objdetect/haarcascade_frontalface_alt.xml
StreamingAssets/OpenCVForUnity/objdetect/lbpcascade_frontalface.xml
-
Clone the HoloLensCameraStream repository.
- Copy the
HoloLensCameraStream/HoloLensVideoCaptureExample/Assets/CamStream/ folder into the project’s Assets/ folder.
-
Import HoloLensWithOpenCVForUnityExampleMRTK3.unitypackage.
-
Add the Unity scene files to the build list.
- In the Build Settings window, add all
Assets/HoloLensWithOpenCVForUnityExample/*.unity files to the Scenes In Build list.
-
Configure the project settings.
- Add
XR_PLUGIN_OPENXR to the Scripting Define Symbols list.
- Enable the WebCam capability in the Publishing Settings tab.
-
(Optional) Configure performance settings for HoloLens.
-
Build the project.
- In the Build Settings window, click Build.
- In the folder selection dialog, create a new folder named
App next to the Assets folder.
- Select the
App folder as the build destination.
- Unity will generate a Visual Studio solution in this folder.
-
Open the Visual Studio solution.
- Open the generated solution:
App/HoloLensWithOpenCVForUnityExample.sln
- This Visual Studio solution is used to deploy the application to your HoloLens.
-
Configure the deployment settings.
-
In the Visual Studio toolbar, select the appropriate solution platform:
x86 for HoloLens 1
ARM64 for HoloLens 2
-
Set the deployment target (the green Start button) to:
Device if the HoloLens is connected to your computer via USB.
Remote Machine if the HoloLens is connected via Wi-Fi.
-
Deploy and run the application.
- Select Debug > Start Debugging in Visual Studio.
- Once the application is deployed to the HoloLens, you can check the deployment status and application output in the Output window.
- Print the AR marker
CanonicalMarker-d10-i1-sp500-bb1.pdf and ArUcoMarkers_DICT_4X4_50_0-8.pdf on A4-size paper for use with the sample.
Additional Resources
| Project Assets |
Build Settings |
 |
 |
| Player Settings |
 |
ScreenShot (old version)





评论