Ask Your Question

Revision history [back]

I modified the code but i have retrieve the same result. Indices and dist are always contains 0 values in The system never executed the line " Debug.WriteLine("This Point Is Good"); I will be very gratefull if anyone could to fix my code. I am very lost with knntree examples. The second version of the code with the Guanta fix is:

  private void Pruebas(){
        //Load Image To Compare With ALL Images in Database
        Image<Gray, byte> observedImage = new Image<Gray, byte>(@"C:\Users\gabri_000\Pictures\uneuro.png");
        VectorOfKeyPoint observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
        Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints);

        //Path With ALL Images Database
        //We will to build the big index for use with flann algorithm
        string[] images = Directory.GetFiles(@"C:\Users\gabri_000\Pictures", "*.png");
        foreach (string image in images)
        {
            DateTime start = DateTime.Now;
            Debug.WriteLine("Current Image  " + image);
            Image<Gray, byte> observedimage = new Image<Gray, byte>(image);

            observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedimage, null);
            matrix = surfCPU.ComputeDescriptorsRaw(observedimage, null, observedKeyPoints);

            if (supermatrix == null)
            {
                supermatrix = new Matrix<float>(matrix.Rows, matrix.Cols);
                supermatrix = matrix;
            }
            else
            {
                supermatrix= supermatrix.ConcateVertical(matrix);
            }


            DateTime end = DateTime.Now;

            Debug.WriteLine("Process Time " + (end - start));

        }

        //At this point, we should to build the index of the big  matrix
        Index fln = new Index(supermatrix, 4);

        //Retrieve The Rows supermatrix

        Matrix<int> indices = new Matrix<int>(supermatrix.Rows, k);
        Matrix<float> dist = new Matrix<float>(supermatrix.Rows, k);

        fln.KnnSearch(observedDescriptors, indices, dist, k, 12);

        Debug.WriteLine("-----------------------");

        for (int i = 0; i < indices.Size.Height; i++)
        {
            if (dist.Data[i, 0] < 0.6 * dist.Data[i, 1])
            {
                Debug.WriteLine("This Point Is Good");
                Debug.WriteLine("The image most similar is" + i);
            }

        }


    }

I modified the code but i have retrieve the same result. Indices and dist are always contains 0 values in The system never executed the line " Debug.WriteLine("This Point Is Good"); I will be very gratefull if anyone could to fix my code. I am very lost with knntree examples. The second version of the code with the Guanta fix is:

  private void Pruebas(){
        //Load Image To Compare With ALL Images in Database
        Image<Gray, byte> observedImage = new Image<Gray, byte>(@"C:\Users\gabri_000\Pictures\uneuro.png");
        VectorOfKeyPoint observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
        Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints);

        //Path With ALL Images Database
        //We will to build the big index for use with flann algorithm
        string[] images = Directory.GetFiles(@"C:\Users\gabri_000\Pictures", "*.png");
        foreach (string image in images)
        {
            DateTime start = DateTime.Now;
            Debug.WriteLine("Current Image  " + image);
            Image<Gray, byte> observedimage = new Image<Gray, byte>(image);

            observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedimage, null);
            matrix = surfCPU.ComputeDescriptorsRaw(observedimage, null, observedKeyPoints);

            if (supermatrix == null)
            {
                supermatrix = new Matrix<float>(matrix.Rows, matrix.Cols);
                supermatrix = matrix;
            }
            else
            {
                supermatrix= supermatrix.ConcateVertical(matrix);
            }


            DateTime end = DateTime.Now;

            Debug.WriteLine("Process Time " + (end - start));

        }

        //At this point, we should to build the index of the big  matrix
        Index fln = new Index(supermatrix, 4);

        //Retrieve The Rows supermatrix

        Matrix<int> indices = new Matrix<int>(supermatrix.Rows, k);
        Matrix<float> dist = new Matrix<float>(supermatrix.Rows, k);

        fln.KnnSearch(observedDescriptors, indices, dist, k, 12);

        Debug.WriteLine("-----------------------");

        for (int i = 0; i < indices.Size.Height; i++)
        {
            if (dist.Data[i, 0] < 0.6 * dist.Data[i, 1])
            {
                Debug.WriteLine("This Point Is Good");
                Debug.WriteLine("The image most similar is" + i);
            }

        }


    }

I modified the code but i have retrieve the same result. Indices and dist are always contains 0 values in The system never executed the line " Debug.WriteLine("This Point Is Good"); I will be very gratefull if anyone could to fix my code. I am very lost with knntree examples. The second version of the code with the Guanta fix is:

   SURFDetector surfCPU = new SURFDetector(50, false);
    Matrix<float> matrix,supermatrix;
    VectorOfKeyPoint observedKeyPoints, modelKeyPoints;
    Image<Gray, byte> observedImage, modelImage;
    int k = 2;

    private void Pruebas(){
        //Load Image To Compare With ALL Images in Database
        Image<Gray, byte> observedImage = new Image<Gray, byte>(@"C:\Users\gabri_000\Pictures\uneuro.png");
        VectorOfKeyPoint observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedImage, null);
        Matrix<float> observedDescriptors = surfCPU.ComputeDescriptorsRaw(observedImage, null, observedKeyPoints);

        //Path With ALL Images Database
        //We will to build the big index for use with flann algorithm
        string[] images = Directory.GetFiles(@"C:\Users\gabri_000\Pictures", "*.png");
        foreach (string image in images)
        {
            DateTime start = DateTime.Now;
            Debug.WriteLine("Current Image  " + image);
            Image<Gray, byte> observedimage modelImage = new Image<Gray, byte>(image);

            observedKeyPoints = surfCPU.DetectKeyPointsRaw(observedimage, modelKeyPoints = surfCPU.DetectKeyPointsRaw(modelImage, null);
            matrix = surfCPU.ComputeDescriptorsRaw(observedimage, surfCPU.ComputeDescriptorsRaw(modelImage, null, observedKeyPoints);
modelKeyPoints);

            if (supermatrix == null)
            {
                supermatrix = new Matrix<float>(matrix.Rows, matrix.Cols);
                supermatrix = matrix;
            }
            else
            {
                supermatrix= supermatrix.ConcateVertical(matrix);
            }


            DateTime end = DateTime.Now;

            Debug.WriteLine("Process Time " + (end - start));

        }

        //At this point, we should to build the index of the big  matrix
        Index fln = new Index(supermatrix, 4);

        //Retrieve The Rows supermatrix

        Matrix<int> indices = new Matrix<int>(supermatrix.Rows, k);
        Matrix<float> dist = new Matrix<float>(supermatrix.Rows, k);
 
        fln.KnnSearch(observedDescriptors, indices, dist, k, 12);

        Debug.WriteLine("-----------------------");

        for (int i = 0; i < indices.Size.Height; i++)
        {
            if (dist.Data[i, 0] < 0.6 * dist.Data[i, 1])
            {
                Debug.WriteLine("This Point Is Good");
                Debug.WriteLine("The image most similar is" + i);
            }

        }


    }