Beispiel #1
0
        /// <summary>
        /// Analyzes the image frame, applies filters and creates new <see cref="TrackerResult"/> objects.
        /// This method performs a deep analysis over the frame and is computationally expensive.
        /// Use this method wisely and never more than once per frame. If you need to get the tracker results
        /// multiple times in a frame use <see cref="GetLatestResult"/> instead.
        /// </summary>
        /// <param name="weightThreshold">The allowed amount of particles distribution to consider a good result.</param>
        /// <returns>The latest tracking result.</returns>
        public List <TrackerResult> Compute(float weightThreshold = 0.01f)
        {
            _result.Clear();

            if (_input != null && _running)
            {
                int dstW = _input.width / _downscaleAmount;
                int dstH = _input.height / _downscaleAmount;

                if (_input.data == null)
                {
                    return(_result);
                }

                if (_downscaleAmount > 1)
                {
                    int requiredBufferLenght = dstW * dstH * 3;

                    if (_resizedBuffer == null || _resizedBuffer.Length != requiredBufferLenght)
                    {
                        _resizedBuffer = new byte[requiredBufferLenght];
                    }

                    ResizeBuffer(_resizedBuffer, _input.data, _input.width, _input.height, dstW, dstH, 3, 3);
                }
                else
                {
                    _resizedBuffer = _input.data;
                }

                if (enableColorTrack)
                {
                    for (int i = 0; i < _processors.Count; ++i)
                    {
                        ColorProcessor clp    = _processors[i];
                        TrackerResult  result = _resultHash[i];

                        clp.Compute(_resizedBuffer, result, dstW, dstH, weightThreshold, useKalmanFilter);

                        if (!IsPositionNearToBounds(ref result.center, 10.0f))
                        {
                            result.center *= _downscaleAmount;
                            _result.Add(result);
                        }
                    }
                }

                if (enableColorMap)
                {
                    _colorMap.ComputeColorMap(_resizedBuffer, dstW, dstH, colorTargets, _downscaleAmount, colorMapPointSpacing);
                }

                if (listener != null && _result.Count > 0)
                {
                    listener.WhenNewResultAvailable(this);
                }
            }

            return(_result);
        }
Beispiel #2
0
        public override void PostProcess()
        {
            int threadCount = Math.Max(Environment.ProcessorCount - 2, 1);

            IProcessor <PointData> fractalProcessor    = InitializeRenderer(DestImage.Width, DestImage.Height);
            IProcessor <double>    innerColorProcessor = new ColorProcessor <SingleColorAlgorithm>(DestImage.Width, DestImage.Height);
            IProcessor <double>    outerColorProcessor = new ColorProcessor <SmoothColoringAlgorithm>(DestImage.Width, DestImage.Height);

            SkiaImageBuilder imageBuilder = new SkiaImageBuilder(DestImage);

            fractalProcessor.SetupAsync(new ProcessorConfig
            {
                ThreadCount = threadCount,
                Params      = GetParams()
            }, CancellationToken.None).Wait();
            PointData[,] inputData = fractalProcessor.ProcessAsync(CancellationToken.None).Result;

            innerColorProcessor.SetupAsync(new ColorProcessorConfig
            {
                ThreadCount = threadCount,
                Params      = new EmptyColoringParams(),
                PointClass  = PointClass.Inner,
                InputData   = inputData
            }, CancellationToken.None).Wait();
            double[,] innerIndicies = innerColorProcessor.ProcessAsync(CancellationToken.None).Result;

            outerColorProcessor.SetupAsync(new ColorProcessorConfig
            {
                ThreadCount = threadCount,
                Params      = new EmptyColoringParams(),
                PointClass  = PointClass.Outer,
                InputData   = inputData
            }, CancellationToken.None).Wait();
            double[,] outerIndicies = outerColorProcessor.ProcessAsync(CancellationToken.None).Result;

            imageBuilder.CreateImage(outerIndicies, innerIndicies, OuterColors, InnerColors);
        }
Beispiel #3
0
 public FirstVisitor(ColorProcessor colorProcessor)
 {
     _colorProcessor = colorProcessor;
 }