# Pupil tracking lost

**URL:** <https://forum.magicleap.cloud/t/pupil-tracking-lost/5224>\
**Category:** Unity Development\
**Tags:** eye-tracking\
**Created:** [February 18, 2025, 3:09pm UTC](https://forum.magicleap.cloud/t/pupil-tracking-lost/5224 "2025-02-18T15:09:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wangzipai96](https://avatars.discourse-cdn.com/v4/letter/w/ba9def/32.png) [@wangzipai96](https://forum.magicleap.cloud/u/wangzipai96)\
**Post date:** [February 18, 2025, 3:09pm UTC](https://forum.magicleap.cloud/t/pupil-tracking-lost/5224/1 "2025-02-18T15:09:03Z")

</div>

Dear community,

We are reading pupil size from the ML2 goggle, and in some rare cases, pupil tracking is lost, and the eye camera images appear to be mis-cropped, as shown below. Does anyone have any idea what might be causing this?

 ![Screenshot 2025-02-18 at 10.03.29 AM](https://us1.discourse-cdn.com/flex019/uploads/magicleap1/original/2X/a/a2a0b1f74590aae8394d220286914b66c44f5234.jpeg)  
These are the left and right temple eye images from the same acquisition session and at the same time frame. The left eye appears normal with proper readings, but the right eye has lost its reading.

Moreover, we are experiencing a low success rate in eye calibration. The program keeps prompting us to change the nose pad or forehead pad, but it still fails even after trying all available pad combinations. Since we are only interested in pupil size and not gaze location, how important is it to complete the eye calibration? Additionally, do you have any suggestions for improving the calibration success rate?

Thank you very much!  
Zipai

---

<div class="post-metadata">

**Author:** ![ababilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/ababilinski/32/79_2.png) [@ababilinski](https://forum.magicleap.cloud/u/ababilinski)\
**Post date:** [February 19, 2025, 12:49am UTC](https://forum.magicleap.cloud/t/pupil-tracking-lost/5224/2 "2025-02-19T00:49:27Z")

</div>

Interesting, can you please share how you are capturing the eye images?

To make sure you obtain an accurate pupil size reading, check the eye confidence value to make sure the cameras are able to detect the user’s eyes.

---

<div class="post-metadata">

**Author:** ![erik.d](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/erik.d/32/2268_2.png) [@erik.d](https://forum.magicleap.cloud/u/erik.d)\
**Post date:** [February 19, 2025, 6:01pm UTC](https://forum.magicleap.cloud/t/pupil-tracking-lost/5224/3 "2025-02-19T18:01:34Z")

</div>

@ababilinski @wangzipai96 I can answer that as I am the dev that implemented the imagery capture for the project.

For some background:  
The code used to capture the imagery was largely pulled from examples provided by the developer resources at the end of 2023.  
At the end of 2024 we made the move to update the Unity project to use the ML SDK v2.5.0 along with OpenXR.

I don’t believe the aforementioned issue was encountered with earlier builds from before the migration, so I don’t know if perhaps something has changed with the API since then.  
The image capture code in out project has not changed between the migration.

That said, here is the code that performs the imagery grab:

```csharp
public override bool CaptureImagery()
    {
        if (!PermissionsManager.PermissionsGranted) return false;

        MLResult result = MLEyeCamera.GetLatestCameraData(out eyeCameraData, 0);

        // disregard when the cameras aren't showing all frames
        if (eyeCameraData.Frames.Length < MLEyeCamera.ActiveCamerasCount) return false;

        if (result.IsOk)
        {
            EyeCaptureFrameData eyeCaptureData = new() {
                frameData = new FrameData[eyeCameraData.FrameCount]
            };

            MLEyeCamera.EyeCameraFrameBuffer frameBuffer;
            FrameData newFrameData;

            for (int i = 0; i < eyeCameraData.FrameCount; i++)
            {
                frameBuffer = eyeCameraData.Frames[i].FrameBuffer;

                newFrameData = new()
                {
                    Width = (int)(frameBuffer.Stride / frameBuffer.BytesPerPixel),
                    Height = (int)frameBuffer.Height,
                    Size = frameBuffer.Size,
                    framePosition = eyeCameraData.Frames[i].CameraID,
                    Data = new byte[frameBuffer.Size]
                };

                MLEyeCamera.CopyImageFrameDataToByteArray(frameBuffer, ref newFrameData.Data);

                eyeCaptureData.frameData[i] = newFrameData;
            }

            frameData.Add(eyeCaptureData);
        }

        return true;
    }

```

The project utilizes the following:  
**Unity: 2022.3.42f1**  
**Unity ML SDK: 2.5.0**  
**ML OS: 1.10.0**

---

<div class="post-metadata">

**Author:** ![ababilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/ababilinski/32/79_2.png) [@ababilinski](https://forum.magicleap.cloud/u/ababilinski)\
**Post date:** [March 5, 2025, 7:12pm UTC](https://forum.magicleap.cloud/t/pupil-tracking-lost/5224/4 "2025-03-05T19:12:27Z")

</div>

When are you calling `CaptureImagery()`? Could you share a script that we can use to validate the issue?
