EuclideanNorm() public méthode

Calculate Euclidean norm of the vector comprised of the point's coordinates - distance from (0, 0) in other words.
public EuclideanNorm ( ) : float
Résultat float
        private void DrawVelocityMap(UnmanagedImage output)
        {
            Point sumVelocity = new Point();

            int indention = 7;
            int step      = 10;

            Invoke(() => step = VelocitiesDistanceTrackBar.Value);

            //Point[,] velocityField = ((dynamic)_tracker).CalculateVelocityField(_currentPreprocessedImage, _previousPreprocessedImage);

            for (int x = indention; x < _frameSize.Width - indention; x += step)
            {
                for (int y = indention; y < _frameSize.Height - indention; y += step)
                {
                    IntPoint p        = new IntPoint(x, y);
                    Point    velocity = _tracker.CalculateVelocity(_currentPreprocessedImage, _previousPreprocessedImage, p);
                    //Point velocity = velocityField[y, x];

                    sumVelocity += velocity;

                    if (velocity.EuclideanNorm() != 0.0f)
                    {
                        IntPoint newp = (p + velocity).Round();
                        Drawing.Line(output, p, newp, Color.White);
                        output.SetPixel(newp, Color.Red);
                    }
                }
            }

            Invoke(() => InfoLabel.Text = string.Format("Summary motion: ({0:+00.00;-00.00}; {1:+00.00;-00.00})", sumVelocity.X / 10, sumVelocity.Y / 10));
        }
        private void UpdateCursor()
        {
            if (ControlCursorCheckBox.Checked && _featureRegion != null && !_featureRegion.IsLost)
            {
                if (AbsolutePositioningCheckBox.Checked)
                {
                    IntPoint delta = new IntPoint(
                        -_featureRegion.Location.X + _featureCenterPostion.X,
                        +_featureRegion.Location.Y - _featureCenterPostion.Y);

                    float speedFactor = 2.6f;

                    IntPoint screenCursorDelta = new IntPoint(
                        (int)(speedFactor * delta.X * _screenResolution.Width / _frameSize.Width),
                        (int)(speedFactor * delta.Y * _screenResolution.Height / _frameSize.Height));

                    IntPoint centerScreen = new IntPoint(_screenResolution.Width / 2, _screenResolution.Height / 2);

                    IntPoint newPosition = new IntPoint(
                        (int)Math.Max(0, Math.Min(_screenResolution.Width - 1, centerScreen.X + screenCursorDelta.X)),
                        (int)Math.Max(0, Math.Min(_screenResolution.Height - 1, centerScreen.Y + screenCursorDelta.Y)));

                    Cursor.Position = newPosition.ToGDIPoint();
                }
                else
                {
                    // inversing X axis
                    Point delta = new Point(
                        -_featureRegion.Location.X + _previousFeaturePointLocation.X,
                        _featureRegion.Location.Y - _previousFeaturePointLocation.Y);

                    _lastDeltas.Add(delta);

                    if (_lastDeltas.Count > _valuablePointsNumber)
                    {
                        _lastDeltas.RemoveAt(0);
                    }

                    Point sumDelta = _lastDeltas.Aggregate <Point, Point>(new Point(), (sum, p) => sum + p);
                    Point avgDelta = sumDelta / _lastDeltas.Count;

                    IntPoint screenCursorDelta = (avgDelta * 10.0f * (float)Math.Pow(avgDelta.EuclideanNorm(), 0.8)).Round();

                    IntPoint newPosition = Cursor.Position.ToAForgePoint() + screenCursorDelta;

                    Cursor.Position = newPosition.ToGDIPoint();

                    if (_lastDeltas.Count == _valuablePointsNumber)
                    {
                        if (avgDelta.EuclideanNorm() > _idleThreshold)
                        {
                            _idleStart = DateTime.Now;
                        }

                        if ((DateTime.Now - _idleStart).TotalSeconds > _idleSecondToClick)
                        {
                            mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, (uint)Cursor.Position.X, (uint)Cursor.Position.Y, 0, 0);
                            _idleStart = DateTime.Now;
                        }
                    }
                }
            }

            _previousFeaturePointLocation = _featureRegion.Location;
        }
Exemple #3
0
        public void EuclideanNormTest( float x, float y, float expectedNorm )
        {
            Point point = new Point( x, y );

            Assert.AreEqual( point.EuclideanNorm( ), expectedNorm );
        }