Invalid pointer when matching NARF features

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Invalid pointer when matching NARF features

Hello, I have the following code:

int matchNarf(pcl::PointCloud<pcl::Narf36> narf_descriptors,
                pcl::PointCloud<pcl::Narf36> narf_descriptors2) {
        // A kd-tree object that uses the FLANN library for fast search of nearest neighbors.
        pcl::KdTreeFLANN<pcl::Narf36> matching = new pcl::KdTreeFLANN<pcl::Narf36>(
        pcl::KdTree<pcl::Narf36>::PointCloudConstPtr ptr_narf_descriptors(
        // A Correspondence object stores the indices of the query and the match,
        // and the distance/weight.
        std::vector<int> correspondence(100);

        // Check every descriptor computed for the scene.
        for (int i = 0; i < narf_descriptors2.points.size(); ++i) {
                std::vector<int> neighbors(10);
                std::vector<float> squaredDistances(1);
                // Ignore NaNs.
                if (pcl_isfinite([0])) {
                        // Find the nearest neighbor (in descriptor space)...
                        int neighborCount = matching.nearestKSearch(,
                                        1, neighbors, squaredDistances);
                        // ...and add a new correspondence if the distance is less than a threshold
                        // (SHOT distances are between 0 and 1, other descriptors use different metrics).
                        if (neighborCount == 1 && squaredDistances[0] < 0.25f) {
                                //correspondence.push_back(neighbors[0], static_cast<int>(i), squaredDistances[0]);
        //std::cout << "Found " << correspondence.size() << " correspondences\n";
        return correspondence.size();

It is giving me "free(): invalid pointer" error, and I know it is in the last "for", it does it one time and then it jumps to the error. I tried the code before with PointXYZ and it was working, but now It is clearly not. What is happening?