public static List <Descriptor> Calculate(Mat image, List <InterestingPoint> points)
        {
            var dx       = new Mat(image.Width, image.Height);
            var dy       = new Mat(image.Width, image.Height);
            var gradient = SobelHelper.Sobel(image, dx, dy, BorderWrapType.Mirror);

            return(Calculate(dx, dy, gradient, points));
        }
Example #2
0
        public static List <InterestingPoint> DoMoravec(double minValue, int windowSize, int shiftSize, int locMaxRadius, Mat image)
        {
            _image = image.Clone();

            _image = SobelHelper.Sobel(_image, BorderWrapType.Mirror); // Считаем градиент в каждой точке

            Mat mistakeImage = GetMinimums(_image, windowSize, shiftSize);


            List <InterestingPoint> candidates =
                CommonMath.getCandidates(mistakeImage, mistakeImage.Height, mistakeImage.Width, locMaxRadius, minValue);


            return(candidates);
        }
Example #3
0
        public static List <Descriptor> Calculate(Mat image, List <InterestingPoint> points)
        {
            var dx       = new Mat(image.Width, image.Height);
            var dy       = new Mat(image.Width, image.Height);
            var gradient = SobelHelper.Sobel(image, dx, dy, BorderWrapType.Mirror);

            var descriptors = new List <Descriptor>();
            var step        = 2 * Math.PI / BINS_COUNT;

            foreach (var center in points)
            {
                var bins = new double[BINS_COUNT];

                int from = GRID_SIZE * BLOCK_SIZE / 2,
                    to   = GRID_SIZE * BLOCK_SIZE - from;

                for (var u = -from; u < to; u++)
                {
                    for (var v = -from; v < to; v++)
                    {
                        int x = center.getX() + u,
                            y = center.getY() + v;

                        var theta = Math.Atan2(dy.GetPixel(x, y, BorderWrapType.Mirror),
                                               dx.GetPixel(x, y, BorderWrapType.Mirror)) + Math.PI;
                        var magnitude = gradient.GetPixel(x, y, BorderWrapType.Mirror);

                        var leftBin  = Math.Min((int)Math.Floor(theta / step), BINS_COUNT - 1);
                        var rightBin = (leftBin + 1) % BINS_COUNT;

                        var ratio = theta % step / step;
                        bins[leftBin]  += magnitude * (1 - ratio);
                        bins[rightBin] += magnitude * ratio;
                    }
                }

                var vector = new Vector(BINS_COUNT, bins).Normalize();

                descriptors.Add(new Descriptor
                {
                    Point  = center,
                    Vector = vector
                });
            }

            return(descriptors);
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            BorderWrapType Edgemode = BorderWrapType.Mirror;

            if (RB_Zero.Checked == true)
            {
                Edgemode = BorderWrapType.Black;
            }
            if (RB_EdgeCoppy.Checked == true)
            {
                Edgemode = BorderWrapType.Copy;
            }
            if (RB_EdgeReflection.Checked == true)
            {
                Edgemode = BorderWrapType.Wrap;
            }
            if (RB_WrapImage.Checked == true)
            {
                Edgemode = BorderWrapType.Mirror;
            }

            Mat sobelMat  = new Mat(_image.Width, _image.Height);
            Mat sobelMatX = new Mat(_image.Width, _image.Height);
            Mat sobelMatY = new Mat(_image.Width, _image.Height);

            if (RB_Sobel.Checked == true)
            {
                sobelMat = SobelHelper.Sobel(_image, sobelMatX, sobelMatY, Edgemode);
            }

            Bitmap picture;

            picture           = Transformer.FromMatToBitmap(sobelMatX);
            pictureBox1.Image = picture;

            picture           = Transformer.FromMatToBitmap(sobelMatY);
            pictureBox2.Image = picture;

            picture           = Transformer.FromMatToBitmap(sobelMat);
            pictureBox3.Image = picture;
        }
Example #5
0
        /*
         * public static WrappedImage GetHarrisMatrix(int windowSize, int windowRadius, int width, int height)
         * {
         *  WrappedImage harrisMat = new WrappedImage(height, width);
         *
         *  Mat SobelX = SobelHelper.GetSobelX(_image, BorderHandling.Mirror);
         *  Mat SobelY = SobelHelper.GetSobelY(_image, BorderHandling.Mirror);
         *
         *  for (int y = 0; y < height; y++)
         *  {
         *      for (int x = 0; x < width; x++)
         *      {
         *          double[,] gauss = ConvolutionMatrix.CountGaussMatrix(windowSize);
         *
         *          // Считаем матрицу H
         *          double[,] currentMatrix = new double[2, 2];
         *          for (int u = -windowRadius; u <= windowRadius; u++)
         *          {
         *              for (int v = -windowRadius; v <= windowRadius; v++)
         *              {
         *                  double Ix = WrappedImage.getPixel(SobelX, y + u, x + v, BorderHandling.Mirror);
         *                  double Iy = WrappedImage.getPixel(SobelY, y + u, x + v, BorderHandling.Mirror);
         *
         *                  double gaussPoint = CommonMath.getPixel(gauss, u + windowRadius, v + windowRadius, 3);
         *
         *                  currentMatrix[0, 0] += Math.Pow(Ix, 2) * gaussPoint;
         *                  currentMatrix[0, 1] += Ix * Iy * gaussPoint;
         *                  currentMatrix[1, 0] += Ix * Iy * gaussPoint;
         *                  currentMatrix[1, 1] += Math.Pow(Iy, 2) * gaussPoint;
         *              }
         *          }
         *
         *          double[] eigenvalues = getEigenvalues(currentMatrix);
         *          harrisMat.buffer[y, x] = Math.Min(eigenvalues[0], eigenvalues[1]);
         *      }
         *  }
         *
         *  return harrisMat;
         * }
         *
         * static public double[] getEigenvalues(double[,] matrix) // Считаем собственные числа
         * {
         *  double[] eigenvalues = new double[2];
         *
         *  double a = 1;
         *  double b = -matrix[0, 0] - matrix[1, 1];
         *  double c = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];
         *  double d = Math.Pow(b, 2) - 4 * a * c;
         *  if (Math.Abs(d) < 1e-4)
         *      d = 0;
         *  if (d < 0)
         *  {
         *      return eigenvalues;
         *  }
         *
         *  eigenvalues[0] = (-b + Math.Sqrt(d)) / (2 * a);
         *  eigenvalues[1] = (-b - Math.Sqrt(d)) / (2 * a);
         *
         *  return eigenvalues;
         * }
         */


        public static Mat Find(Mat image, int radius, double threshold, BorderWrapType borderWrap)
        {
            var gauss  = Gauss.GetFullKernel(radius / 3D);
            var gaussK = gauss.Width / 2;

            var dx = new Mat(image.Width, image.Height);
            var dy = new Mat(image.Width, image.Height);

            SobelHelper.Sobel(image, dx, dy, BorderWrapType.Mirror);

            var lambdas = new Mat(image.Width, image.Height);

            for (var x = 0; x < image.Width; x++)
            {
                for (var y = 0; y < image.Height; y++)
                {
                    double a = 0, b = 0, c = 0;

                    for (var u = -radius; u <= radius; u++)
                    {
                        for (var v = -radius; v <= radius; v++)
                        {
                            var multiplier = gauss.GetAt(u + gaussK, v + gaussK);

                            a += multiplier * MathHelper.Sqr(dx.GetPixel(x + u, y + v, borderWrap));
                            b += multiplier * dx.GetPixel(x + u, y + v, borderWrap) *
                                 dy.GetPixel(x + u, y + v, borderWrap);
                            c += multiplier * MathHelper.Sqr(dy.GetPixel(x + u, y + v, borderWrap));
                        }
                    }

                    lambdas.Set(x, y, LambdaMin(a, b, c));
                }
            }

            return(CornerDetectionHelper.FindPoints(lambdas, threshold));
        }