---
title: "Discussion on \"QR Code tracking in the HoloLens\" | Hashnode"
description: "Discussion on \"QR Code tracking in the HoloLens\". C# Unity example"
url: "https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [QR Code tracking in the HoloLens](https://shaynek.hashnode.dev/qr-code-tracking-in-the-hololens?utm_source=hashnode&utm_medium=feed)

C# Unity example

Mar 11, 2021 · 5 min read · shaynek.hashnode.dev  
Updated Jan 12, 2022  
Read the article

-   [#csharp](https://hashnode.com/tag/csharp)
-   [#unity](https://hashnode.com/tag/unity)

## Written by

[Shayne Kiekebosch](https://hashnode.com/@ShayneK)

@ShayneK · New Zealand

  
[View profile](https://hashnode.com/@ShayneK)

Mixed Reality and game dev with Unity, .NET Windows software.

.NET developer specialising in Windows Mixed Reality and Windows forms/services. Utilising Unity I have developed applications for the Microsoft HoloLens 1 and 2 and the Meta Quest 1, 2 and Pro. I was also a senior dev at Blackout Games working on their Rugby Management Game.

## Responses 3

Markdown supported · ⌘↵ to post

[Hubert (Sathaporn) Hu](https://hashnode.com/@shubertkai)

[Jan 8, 2022](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/61d9d782cda0d0294b696c38)

Thanks Shayne, this code saved my project.

The code is outdated though if you are using OpenXR. There's now a better way to compute the QR Code's pose. For QRCodeInformation, I'm adding another field called "SpatialGraphNodeID":

```
public class QRCodeInformation
{
    public string Data { get; set; }
    public float Length { get; set; }
#if WINDOWS_UWP
    public SpatialCoordinateSystem QRSpatialCoordinateSystem { get; set; }
    public Guid SpatialGraphNodeID { get; set; } 
    public QRCodeInformation(string data, SpatialCoordinateSystem qrSpatialCoordinateSystem, float length, Guid spatialGraphNodeID)
    {
        Data = data;
        Length = length;
        QRSpatialCoordinateSystem = qrSpatialCoordinateSystem;
        SpatialGraphNodeID = spatialGraphNodeID;
    }
#endif
    public QRCodeInformation() { }
}
```

I had to change some code to match the new constructor's signature.

Then, to find the pose, I use this code instead:

```
SpatialGraphNode node = SpatialGraphNode.FromStaticNodeId(SpatialGraphNodeID);
        Pose pose;
        if (node != null && node.TryLocate(FrameTime.OnUpdate, out pose))
        {
            if (CameraCache.Main.transform.parent != null)
            {
                pose = pose.GetTransformedBy(CameraCache.Main.transform.parent);
            }
            marker.transform.SetPositionAndRotation(pose.position, pose.rotation);
        }
```

This snippet is from: [Microsoft' QR Source Code](https://github.com/yl-msft/QRTracking/blob/main/SampleQRCodes/Assets/Scripts/SpatialGraphNodeTracker.cs)

I hate making public posts very much. However, I think this would be a very good PSA for anyone who's about to go Kylo Ren on their equipment.

PS: I could clean up your code to remove any WinRT reference too, but I just have no fight left at the moment.

[Shayne Kiekebosch](https://hashnode.com/@ShayneK)

[Jan 12, 2022](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/61d9d782cda0d0294b696c38#reply-61df52746bf5f0642b8f1347)

Oh cool thanks [Hubert (Sathaporn) Hu](https://hashnode.com/@shubertkai). I have moved on from HoloLens development so I don't have access to any of my old code. I'll edit the post for OpenXR to come look at your comment.

[Hubert (Sathaporn) Hu](https://hashnode.com/@shubertkai)

[Jan 12, 2022](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/61d9d782cda0d0294b696c38#reply-61df5d976bf5f0642b8f1452)

[Shayne Kiekebosch](https://hashnode.com/@ShayneK), I found out that the pose still needs to be transformed though - so the matrix conversion is still useful.

[Patrick Ryan](https://hashnode.com/@patrickatkeylogic)

[Sep 23, 2021](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/614cb11d544e242e0c93f3aa)

Just a heads up for anyone stumbling across this as of September 2021: `UnityEngine.XR.WSA.WorldManager` is deprecated so the line to obtain the rootSpatialCoordinateSystem can be replaced with the following:

```
rootSpatialCoordinateSystem = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation().CoordinateSystem;
```

[Shayne Kiekebosch](https://hashnode.com/@ShayneK)

[Oct 6, 2021](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/614cb11d544e242e0c93f3aa#reply-615d0161e16040649ad7e006)

Thanks for the message! I recently ran into this too doing a Unity upgrade. I should try and edit the post.

[rajendra dhaundiyal](https://hashnode.com/@rdhaundiyal)

[May 12, 2021](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/609bbabc00bbde79d86a6275)

Hi Shaynek, thanks for the article. I was able to run the demo but have one question. there are eventhandlers for add,remove and update qr code. I understand that add event is called when i bring a QR code in front of hololens camera but not able to understand when will the remove and update event be called.

[Shayne Kiekebosch](https://hashnode.com/@ShayneK)

[May 27, 2021](https://hashnode.com/posts/qr-code-tracking-in-the-hololens/604a7f27ad1cac7d577dfa06/comment/609bbabc00bbde79d86a6275#reply-60af1faf9b1e2e1dccbca65c)

Hi Rajendra, sorry for the late reply! I never got an email notification for your comment.

As I remember it, the remove event is when the QR code is removed from the HoloLens' camera view and the update is when the QR code changes, like it position.

An easy test would be to output (Debug.Log()) something for each event handler and run some tests with some QR codes. I don't currently have set up to run these tests at the moment.

Hope that helps and thanks for the comment!
