/// <summary> /// Helper method that the MLArucoTracker API uses to marshal the results recieved from the device. /// Results are released after being queried for. /// </summary> /// <param name="trackerResults">The array of marker results found by the device.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successfully fetched and returned all detections. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if failed to return detection data due to an invalid resultArray. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed to return detections due to an internal error. /// </returns> public static MLResult.Code GetResults(out MLArucoTrackerResultNative[] trackerResultsArray) { MLResult.Code resultCode = (NativeBindings.MLArucoTrackerGetResult(Instance.Handle, out MLArucoTrackerResultArrayNative resultsArray)); if (!MLArucoTracker.DidNativeCallSucceed(resultCode)) { trackerResultsArray = new MLArucoTrackerResultNative[0]; return(resultCode); } trackerResultsArray = new MLArucoTrackerResultNative[resultsArray.Count]; for (int i = 0; i < resultsArray.Count; i++) { IntPtr offsetPtr = Marshal.ReadIntPtr(new IntPtr(resultsArray.Detections.ToInt64() + (Marshal.SizeOf(typeof(IntPtr)) * i))); MLArucoTrackerResultNative trackerResult = (MLArucoTrackerResultNative)Marshal.PtrToStructure(offsetPtr, typeof(MLArucoTrackerResultNative)); trackerResultsArray[i] = trackerResult; } resultCode = NativeBindings.MLArucoTrackerReleaseResult(ref resultsArray); foreach (NativeBindings.MLArucoTrackerResultNative trackerResult in trackerResultsArray) { if (!NativeBindings.MapTrackerResults.ContainsKey(trackerResult.Id)) { NativeBindings.MapTrackerResults.Add(trackerResult.Id, trackerResult); } } if (!MLArucoTracker.DidNativeCallSucceed(resultCode)) { return(resultCode); } return(resultCode); }