To access the GitHub repo for the QR code sample:
[!div class=”nextstepaction”] QR code tracking in Unity
With HoloLens 2 and immersive headsets, you can detect QR codes in the environment around the headset, establishing a coordinate system at each code’s real-world location. You can also render holograms in the same location on multiple devices to create a shared experience. Once you enable your device’s webcam, you’ll recognize QR codes in the latest versions of your projects. For best results going into production, we recommend that you review the best practices section.
In this article, you’ll learn about:
Microsoft.MixedReality.QR.pdb
not found” error message?Feature | HoloLens 1st Gen | HoloLens 2 | Immersive headsets |
---|---|---|---|
QR code detection | :heavy_check_mark: | :heavy_check_mark: |
[!NOTE] QR code tracking with immersive Windows Mixed Reality headsets on desktop PCs is supported on Windows 10 Version 2004 and higher. Use the
Microsoft.MixedReality.QRCodeWatcher.IsSupported()
API to determine whether the feature is supported on the current device.
The following table lists the supported and unsupported QR code versions:
QR Code versions | |
---|---|
Supported: | <ul> <li> QR versions 1 - 10 </li> <li> Micro QR codes M1-M4 </li> <li> All encodings </li> |
Not supported: | <ul> <li> QR Codes 10 - 20 (these may work, but are not guaranteed) </li> <li> QR Codes 20+ </li> <li> Tweaked modules, for example: circular modules, reflections, inverted (black/white). </li> <li> Logos </li> <li> Structured appends </li> <ul> |
To be read correctly, QR codes require a margin around all sides of the code. This margin must not contain any printed content and should be four modules (a single black square in the code) wide.
The QR spec contains more information about quiet zones.
QR code detection quality is susceptible to varying illumination and backdrop.
Under normal lighting conditions, provide enough contrast for the black/white modules for better performance.
In extreme lighting conditions with bright lighting or dark backdrop, you can try to reduce and adjust contrast which could improve QR code detection rate. The white background within the QR code can be reduced from 255 downwards.
Windows Mixed Reality devices don’t work with QR codes with sides smaller than 5 cm.
For QR codes with sides ranging from 5 cm to 10 cm, the device must be fairly close to detect the code. It may take longer to detect the code.
The exact time to detect codes depends not only on the size of the QR codes, but how far away you are from the code. Moving closer to the code will help offset issues with size.
The tracking cameras can only detect a certain level of detail. For small codes (less than 10 cm along the sides) you must be fairly close. For a version 1 QR code varying from 10 cm to 25 cm in size, the minimum detection distance is between 0.15 meters and 0.5 meters.
The detection distance for size increases linearly, but also depends on supported QR version or module size. The higher the version, the smaller the modules, which can only be detected from a closer position. You can also try micro-QR codes if you want the distance of detection to be longer. QR detection works with a range of angles += 45 deg to ensure we have proper resolution to detect the code.
Other detection considerations:
For the tradeoff relationship between distance and size of the QR code for optimal detection, see the following graph:
[!IMPORTANT] Always make sure you have enough contrast and a proper border.
Windows Mixed Reality devices detect QR codes at the system level in the driver. When the device is rebooted or the driver restarts, the detected QR codes history is cleared. QR codes redetected are treated as new objects.
We recommend configuring your app to ignore QR codes older than a specific timestamp, which can be specified within the app. The QR Code API specifies the time that last detection happened. Most app developers will use the system time when the app is launched to determine the time a QR code is detected.
QR code data aren’t app-specific. Upon app launch, there will be a list of available QR codes being provided. The app developer will determine which QR codes are relevant to this app.
For recommendations on where and how to place QR codes, refer to Environment considerations for HoloLens.
You’ll need the webcam capability added to your manifest (checkbox in Unity Capabilities). If you’re building as a standard UWP project, it’s also in the package.appxmanifest
in the solution project.
Request access by calling the following function:
#if WINDOWS_UWP
async QRCodeWatcher.RequestAccessAsync();
#endif
The access status should be (status == QRCodeWatcherAccessStatus::Allowed)
.
If access is denied, then the feature will return access denied when you start the QRTracking
.
This API should be called before you construct the QRCodeWatcher
object.
If you’re running the project from Unity, you also need to ensure that you’re calling from the UI thread. Otherwise, the API will always return denied. For more information, see AppCallbacks class in the Unity Manual.
For more information on setting up your project for Unity, see configure Unity for Windows Mixed Reality.
QR tracking is automatic on HoloLens 2, and you’ll need the “webcam” capability added to your app.
All the required files and documentation can be found here.
https://www.nuget.org/packages/Microsoft.MixedReality.QR
Use the NuGet pack to unpack the required files.
Add a reference to the Microsoft.MixedReality.QR.winmd
in your project and start using the API.
Add the correct architecture versions of the plugins and use them accordingly in the build.
Use NuGet for Unity and point to the NuGet pack above.
Check out any QR code generator–here’s one example.
When detected in a single frame, the size is expected to have at most a 1% error from the actual size. For example, a 10 cm code might be up to +/- 1 mm off in measured size. Under continuous detection, a code’s position might drift around by up to +/- 2.5 mm. Once you’ve moved out of detection range, a previous detection’s position is up to the mercy of the map error.
The distance obviously depends on the size of the QR code, and also what version it is. For more information, see distance and angular position from the QR code.
Currently, we don’t support QR codes with logos.
For more information, see what QR code versions are supported?.
QR codes are saved at the system level in driver session, or boot session on HoloLens. For more information, see managing QR code data.
Detected QR codes are persisted in memory by the driver.
Microsoft.MixedReality.QR.pdb
not found” error message?Symbol loading for Microsoft.MixedReality.QR.dll
was skipped because it isn’t specified in the included modules list.
Follow the steps to reproduce this behavior:
You should be able to debug the app with Microsoft.MixedReality.QR.dll, but the DLL isn’t found:
We’re working on adding symbols to the next release. In the meantime, you should still be able to debug your app by excluding the DLL in the Visual Studio options:
For more information, see Configuring Visual Studio’s settings.
There is a limit of 100 QR codes saved at the system level in the driver, within 10 minutes.
QR code smoothing process changed after 20H2, from pose smoothing to size smoothing. To revert behavior to the previous smoothing process, one would apply a smoothing algorithm if the new QR code pose data is detected within 5 seconds or 10 cm of the previously detected frame. The transform data is blended via a weighted ratio of 90% of the current frame with 10% of the previous frame.