Пример #1
0
        public TrackerModel(IApp app, BackgroundReadingLoop readingLoop,
                            TrackerProcessingMode processingMode, DnnModel dnnModel, SensorOrientation sensorOrientation, float smoothingFactor)
            : base(app)
        {
            // try to create tracking loop first
            readingLoop.GetCalibration(out calibration);
            trackingLoop = new BackgroundTrackingLoop(in calibration, processingMode, dnnModel, sensorOrientation, smoothingFactor);
            trackingLoop.BodyFrameReady += TrackingLoop_BodyFrameReady;
            trackingLoop.Failed         += BackgroundLoop_Failed;

            this.readingLoop          = readingLoop;
            readingLoop.CaptureReady += ReadingLoop_CaptureReady;
            readingLoop.Failed       += BackgroundLoop_Failed;

            Title = readingLoop.ToString();

            // Image and skeleton visualizers for depth
            var depthMode = readingLoop.DepthMode;

            depthImageVisualizer    = ImageVisualizer.CreateForDepth(dispatcher, depthMode.WidthPixels(), depthMode.HeightPixels());
            depthSkeletonVisualizer = new SkeletonVisualizer(dispatcher, depthMode.WidthPixels(), depthMode.HeightPixels(), ProjectJointToDepthMap);

            // Image and skeleton visualizers for color
            var colorRes = readingLoop.ColorResolution;

            if (colorRes != ColorResolution.Off)
            {
                colorImageVisualizer       = ImageVisualizer.CreateForColorBgra(dispatcher, colorRes.WidthPixels(), colorRes.HeightPixels());
                colorSkeletonVisualizer    = new SkeletonVisualizer(dispatcher, colorRes.WidthPixels(), colorRes.HeightPixels(), ProjectJointToColorImage);
                bodyIndexMapTransformation = new BodyIndexMapTransformation(in calibration);
            }

            // Proportions between columns
            if (colorRes != ColorResolution.Off)
            {
                DepthColumnWidth = new GridLength(depthImageVisualizer.WidthPixels, GridUnitType.Star);
                ColorColumnWidth = new GridLength(
                    depthImageVisualizer.HeightPixels * colorImageVisualizer.WidthPixels / colorImageVisualizer.HeightPixels,
                    GridUnitType.Star);
            }
            else
            {
                DepthColumnWidth = new GridLength(1, GridUnitType.Star);
                ColorColumnWidth = new GridLength(0, GridUnitType.Pixel);
            }
        }
    void Start()
    {
        if (useAppConfig)
        {
            AppConfig conf = AppManager.AppConfig;
            colorResolution = conf.ColorResolution;
            imageFormat     = conf.ImageFormat;
            fps             = conf.Fps;
            depthMode       = conf.DepthMode;
            processingMode  = conf.ProcessingMode;
        }

        colourKernelId = computeShader.FindKernel("ColourTex");
        irKernelId     = computeShader.FindKernel("IRTex");
        depthKernelId  = computeShader.FindKernel("DepthTex");

        switch (colorResolution)
        {
        case ColorResolution.R720p:
        {
            colourWidth  = 1280;
            colourHeight = 720;
            break;
        }

        case ColorResolution.R1080p:
        {
            colourWidth  = 1920;
            colourHeight = 1080;
            break;
        }

        default:
        {
            colorResolution = ColorResolution.R1080p;
            colourWidth     = 1920;
            colourHeight    = 1080;
            break;
        }
        }

        if (uiEnabled)
        {
            colourTex = new RenderTexture(colourWidth, colourHeight, 24)
            {
                enableRandomWrite = true
            };
            colourTex.Create();
            colourImage.texture = colourTex;

            irTex = new RenderTexture(irWidth, irHeight, 24)
            {
                enableRandomWrite = true
            };
            irTex.Create();
            irImage.texture = irTex;

            depthTex = new RenderTexture(colourWidth, colourHeight, 24)
            {
                enableRandomWrite = true
            };
            depthTex.Create();
            depthImage.texture = depthTex;
        }

        Init();
    }