Exemplo n.º 1
0
        internal static bool TryCreateTrackerHandle(ref Sensor.Calibration calibration, BodyTracking.TrackerConfiguration config,
                                                    out NativeHandles.TrackerHandle trackerHandle, out string message)
        {
            string runtimePath;

            lock (bodyTrackingRuntimeInitializationSync)
            {
                if (string.IsNullOrEmpty(bodyTrackingRuntimePath))
                {
                    bodyTrackingRuntimePath = GetBodyTrackingRuntimePath(out message);
                    if (string.IsNullOrEmpty(bodyTrackingRuntimePath))
                    {
                        trackerHandle = null;
                        return(false);
                    }
                }

                runtimePath = bodyTrackingRuntimePath;
            }

            if (!CheckBodyTrackingRuntimeVersion(bodyTrackingRuntimePath, out message))
            {
                trackerHandle = null;
                return(false);
            }

            // Force loading of k4a.dll,
            // because k4abt.dll depends on it
            var tmp = new Sensor.Capture();

            tmp.Dispose();

            // We have to change current directory,
            // because Body Tracking runtime will try to load ONNX file from current directory
            // (Adding to Path environment variable doesn't work.)
            using (new CurrentDirectoryOverrider(runtimePath))
            {
                if (BodyTracking.NativeApi.TrackerCreate(ref calibration, config, out trackerHandle) != NativeCallResults.Result.Succeeded ||
                    trackerHandle == null || trackerHandle.IsInvalid)
                {
                    if (IsBodyTrackingRuntimeAvailable(out message))
                    {
                        message = "Cannot initialize body tracking runtime. See logs for details.";
                    }
                    return(false);
                }
            }

            message = null;
            return(true);
        }
Exemplo n.º 2
0
        public static void CreateDummy(DepthMode depthMode, ColorResolution colorResolution, out Calibration calibration)
        {
            calibration = default(Calibration);

            // depth camera
            calibration.DepthMode = depthMode;
            depthMode.GetNominalFov(out var hFovDegrees, out var vFovDegrees);
            InitDummyCameraCalibration(ref calibration.DepthCameraCalibration,
                                       depthMode.WidthPixels(), depthMode.HeightPixels(),
                                       hFovDegrees, vFovDegrees);

            // color camera
            calibration.ColorResolution = colorResolution;
            colorResolution.GetNominalFov(out hFovDegrees, out vFovDegrees);
            InitDummyCameraCalibration(ref calibration.ColorCameraCalibration,
                                       colorResolution.WidthPixels(), colorResolution.HeightPixels(),
                                       hFovDegrees, vFovDegrees);

            // extrinsics
            calibration.Extrinsics = new CalibrationExtrinsics[(int)CalibrationGeometry.Count * (int)CalibrationGeometry.Count];
            for (var i = 0; i < calibration.Extrinsics.Length; i++)
            {
                InitDummyExtrinsics(ref calibration.Extrinsics[i]);
            }
        }
Exemplo n.º 3
0
        public static void CreateFromRaw(byte[] rawCalibration, DepthMode depthMode, ColorResolution colorResolution, out Calibration calibration)
        {
            if (rawCalibration == null)
            {
                throw new ArgumentNullException(nameof(rawCalibration));
            }
            var res = NativeApi.CalibrationGetFromRaw(rawCalibration, Helpers.Int32ToUIntPtr(rawCalibration.Length), depthMode, colorResolution, out calibration);

            if (res == NativeCallResults.Result.Failed)
            {
                throw new InvalidOperationException("Cannot create calibration from parameters specified.");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates dummy (no distortions, ideal pin-hole geometry, all sensors are aligned) but valid calibration data.
        /// This can be useful for testing and subbing needs.
        /// </summary>
        /// <param name="depthMode">Depth mode for which dummy calibration should be created. Can be <see cref="DepthMode.Off"/>.</param>
        /// <param name="colorResolution">Color resolution for which dummy calibration should be created. Can be <see cref="ColorResolution.Off"/>.</param>
        /// <param name="calibration">Result: created dummy calibration data for <paramref name="depthMode"/> and <paramref name="colorResolution"/> specified.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="depthMode"/> and <paramref name="colorResolution"/> cannot be equal to <c>Off</c> simultaneously.</exception>
        public static void CreateDummy(DepthMode depthMode, ColorResolution colorResolution, out Calibration calibration)
        {
            if (depthMode == DepthMode.Off && colorResolution == ColorResolution.Off)
            {
                throw new ArgumentOutOfRangeException(nameof(depthMode) + " and " + nameof(colorResolution), $"{nameof(depthMode)} and {nameof(colorResolution)} cannot be equal to Off simultaneously.");
            }

            calibration = default;

            // depth camera
            calibration.DepthMode = depthMode;
            depthMode.GetNominalFov(out var hFovDegrees, out var vFovDegrees);
            InitDummyCameraCalibration(ref calibration.DepthCameraCalibration,
                                       depthMode.WidthPixels(), depthMode.HeightPixels(),
                                       hFovDegrees, vFovDegrees);

            // color camera
            calibration.ColorResolution = colorResolution;
            colorResolution.GetNominalFov(out hFovDegrees, out vFovDegrees);
            InitDummyCameraCalibration(ref calibration.ColorCameraCalibration,
                                       colorResolution.WidthPixels(), colorResolution.HeightPixels(),
                                       hFovDegrees, vFovDegrees);

            // extrinsics
            calibration.Extrinsics = new CalibrationExtrinsics[(int)CalibrationGeometry.Count * (int)CalibrationGeometry.Count];
            for (var i = 0; i < calibration.Extrinsics.Length; i++)
            {
                InitDummyExtrinsics(ref calibration.Extrinsics[i]);
            }
        }
Exemplo n.º 5
0
        /// <summary>Gets the camera calibration for a device from a raw calibration blob.</summary>
        /// <param name="rawCalibration">Raw calibration blob obtained from a device or recording. The raw calibration must be <c>0</c>-terminated. Cannot be <see langword="null"/>.</param>
        /// <param name="depthMode">Mode in which depth camera is operated.</param>
        /// <param name="colorResolution">Resolution in which color camera is operated.</param>
        /// <param name="calibration">Result: calibration data.</param>
        /// <exception cref="ArgumentNullException"><paramref name="rawCalibration"/> cannot be <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException"><paramref name="rawCalibration"/> must be 0-terminated.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="depthMode"/> and <paramref name="colorResolution"/> cannot be equal to <c>Off</c> simultaneously.</exception>
        public static void CreateFromRaw(byte[] rawCalibration, DepthMode depthMode, ColorResolution colorResolution, out Calibration calibration)
        {
            if (rawCalibration == null)
            {
                throw new ArgumentNullException(nameof(rawCalibration));
            }
            if (rawCalibration.IndexOf(0) < 0)
            {
                throw new ArgumentException($"{nameof(rawCalibration)} must be 0-terminated.", nameof(rawCalibration));
            }
            if (depthMode == DepthMode.Off && colorResolution == ColorResolution.Off)
            {
                throw new ArgumentOutOfRangeException(nameof(depthMode) + " and " + nameof(colorResolution), $"{nameof(depthMode)} and {nameof(colorResolution)} cannot be equal to Off simultaneously.");
            }
            var res = NativeApi.CalibrationGetFromRaw(rawCalibration, Helpers.Int32ToUIntPtr(rawCalibration.Length), depthMode, colorResolution, out calibration);

            if (res == NativeCallResults.Result.Failed)
            {
                throw new InvalidOperationException("Cannot create calibration from parameters specified.");
            }
        }
Exemplo n.º 6
0
        /// <summary>Gets the camera calibration for the entire Azure Kinect device.</summary>
        /// <param name="depthMode">Mode in which depth camera is operated.</param>
        /// <param name="colorResolution">Resolution in which color camera is operated.</param>
        /// <param name="calibration">Output: calibration data.</param>
        /// <remarks><para>
        /// The <paramref name="calibration"/> represents the data needed to transform between the camera views and may be
        /// different for each operating <paramref name="depthMode"/> and <paramref name="colorResolution"/> the device is configured to operate in.
        /// </para><para>
        /// The <paramref name="calibration"/> output is used as input to all calibration and transformation functions.
        /// </para></remarks>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="depthMode"/> and <paramref name="colorResolution"/> cannot be equal to <c>Off</c> simultaneously.</exception>
        /// <exception cref="ObjectDisposedException">This method cannot be called for disposed object.</exception>
        /// <exception cref="DeviceConnectionLostException">Connection with Azure Kinect device has been lost.</exception>
        /// <exception cref="InvalidOperationException">Cannot read calibration data for some unexpected reason. See logs for details.</exception>
        /// <seealso cref="GetCalibration(DepthMode, ColorResolution, out Calibration)"/>
        public void GetCalibration(DepthMode depthMode, ColorResolution colorResolution, out Calibration calibration)
        {
            if (depthMode == DepthMode.Off && colorResolution == ColorResolution.Off)
            {
                throw new ArgumentOutOfRangeException(nameof(depthMode) + " and " + nameof(colorResolution), $"{nameof(depthMode)} and {nameof(colorResolution)} cannot be equal to Off simultaneously.");
            }

            CheckResult(NativeApi.DeviceGetCalibration(handle.ValueNotDisposed, depthMode, colorResolution, out calibration));
        }