Giter VIP home page Giter VIP logo

Comments (3)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 28, 2024
I do get random numbers the radiusSearch(), but not for knnSearch(). The 
results are the same, always... Can you double check? If it still does not 
work, please provide more info about your platform, etc. thanks

Original comment by [email protected] on 9 Nov 2011 at 1:55

from javacv.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 28, 2024
yes, indeed knn is not generating random numbers.
Though it works extremely inefficient, instead of working faster it works 
slower.
Perhaps you could take a look:
private Integer[] findPairs(CvSURFPoint[] objectKeypoints,
            FloatBuffer[] objectDescriptors, CvSURFPoint[] imageKeypoints,
            FloatBuffer[] imageDescriptors) {

        boolean[] lessRidiculous = new boolean[imageDescriptors.length];
        Integer[] toReturn = new Integer[objectDescriptors.length*2];
        int numNeighbors = 100; 
        int matchCounter = 0;

        LinearIndexParams kdParams = new LinearIndexParams();
        SearchParams searchParams = new SearchParams(descriptorLength, 0.5f, true);

        // Populate imageMat
        CvMat imageMat = CvMat.create(imageDescriptors.length, descriptorLength, CV_32F);
        for (int i = 0; i < imageDescriptors.length; i++) 
        { 
            for (int j = 0; j < descriptorLength; j++) 
            { 
                imageMat.put(i, j, imageDescriptors[i].get(j) ); 
            } 
        } 

        Index flannIndex = new Index(imageMat, kdParams, 1);

        for (int c = 0; c < objectDescriptors.length; c++)
        {
            CvMat queryMat = CvMat.create(1, descriptorLength, CV_32F);

            CvMat indicesMat = CvMat.create(1, numNeighbors, CV_32S);
            CvMat indicesMat = CvMat.create(1, numNeighbors, CV_32S);
            CvMat distancesMat = CvMat.create(1, numNeighbors, CV_32F);
            // Populate queryMat 
            for (int i = 0; i < descriptorLength; i++) 
            { 
                queryMat.put(0, i, (double) objectDescriptors[c].get(i));
            } 
            flannIndex.knnSearch(queryMat, indicesMat, distancesMat, numNeighbors, searchParams);

            //System.out.println("Index " + indicesMat.get(0,0) + " Distance " + distancesMat.get(0,0) + "Index " + indicesMat.get(0,1) + " Distance " + distancesMat.get(0,1));
            int nearestNeighbor = (int)indicesMat.get(0,0);  
            if (indicesMat !=null && nearestNeighbor >0 && nearestNeighbor < imageDescriptors.length && !lessRidiculous[nearestNeighbor])
            {
                lessRidiculous[nearestNeighbor] = true;
                //System.out.println("M " + c + " " + nearestNeighbor  + " d " + distancesMat.get(0,0));
                toReturn[matchCounter++]  = c;
                toReturn[matchCounter++]  = nearestNeighbor ;
            }
        }
        System.out.println("Matches count " + matchCounter);
        return Arrays.copyOf(toReturn, matchCounter); 
        }

Original comment by [email protected] on 10 Nov 2011 at 9:23

from javacv.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 28, 2024
Well, CvMat.create() is a pretty heavy operation. You should move those calls 
outside the loop. 

BTW, check out the NetBeans profiler: http://profiler.netbeans.org/ . With that 
tool we can easily find which calls use most of the CPU time.

Original comment by [email protected] on 26 Nov 2011 at 7:04

  • Changed state: Done

from javacv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.