Matching RIFT features with KdTreeFLANN

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Matching RIFT features with KdTreeFLANN

adr_arroyo
Hello,
I am trying to match two point clouds of descriptors of type RIFT32, finding how many matches there are between both. I have the following code:

int matchRIFTFeaturesKnn(pcl::PointCloud<RIFT32>::Ptr descriptors1,
                pcl::PointCloud<RIFT32>::Ptr descriptors2) {
        // A kd-tree object that uses the FLANN library for fast search of nearest neighbors.
        pcl::KdTreeFLANN<RIFT32> matching = new pcl::KdTreeFLANN<RIFT32>();
        pcl::KdTree<RIFT32>::PointCloudConstPtr ptr_descriptors1(descriptors1);
        matching.setInputCloud(ptr_descriptors1);
        // A Correspondence object stores the indices of the query and the match,
        // and the distance/weight.
        std::vector<int> correspondence;

        // Check every descriptor computed for the scene.
        for (size_t i = 0; i < descriptors2->points.size(); ++i) {
                std::vector<int> neighbors(1);
                std::vector<float> squaredDistances(1);
                // Find the nearest neighbor (in descriptor space)...
                int neighborCount = matching.nearestKSearch(descriptors2->points.at(i),
                                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]);
                        correspondence.push_back(neighbors[0]);
                }
        }
        std::cout << "Found " << correspondence.size() << " correspondences\n";
        return correspondence.size();
}


But It is giving me a compilation error about the class KdTreeFLANN:

CMakeFiles/comparator.dir/src/comparator.cpp.o: In function `matchRIFTFeaturesKnn(boost::shared_ptr<pcl::PointCloud<pcl::Histogram<32> > >, boost::shared_ptr<pcl::PointCloud<pcl::Histogram<32> > >)':
comparator.cpp:(.text+0xe87): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::KdTreeFLANN(bool)' not defined
comparator.cpp:(.text+0xea1): not defined `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::KdTreeFLANN(bool)' not defined
comparator.cpp:(.text+0xf0a): referencia a `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::Histogram<32> > const> const&, boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)' not defined
comparator.cpp:(.text+0x102d): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::nearestKSearch(pcl::Histogram<32> const&, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o: In function `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::~KdTreeFLANN()':
comparator.cpp:(.text._ZN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEED2Ev[_ZN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEED5Ev]+0x20): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::cleanup()' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x10): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::setInputCloud(boost::shared_ptr<pcl::PointCloud<pcl::Histogram<32> > const> const&, boost::shared_ptr<std::vector<int, std::allocator<int> > const> const&)' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x28): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::nearestKSearch(pcl::Histogram<32> const&, int, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&) const' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x40): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::radiusSearch(pcl::Histogram<32> const&, double, std::vector<int, std::allocator<int> >&, std::vector<float, std::allocator<float> >&, unsigned int) const' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x58): reference to `pcl::KdTreeFLANN<pcl::Histogram<32>, flann::L2_Simple<float> >::setEpsilon(float)' not defined
collect2: error: ld returned 1 exit status
make[2]: *** [comparator] Error 1
make[1]: *** [CMakeFiles/comparator.dir/all] Error 2
make: *** [all] Error 2

What am I doing wrong?
Cheers
Reply | Threaded
Open this post in threaded view
|

Re: Matching RIFT features with KdTreeFLANN

Sérgio Agostinho
Hey,

Recompile PCL with the option PCL_NO_PRECOMPILE set to ON. The class is not currently being instantiated with the type you're using.


Cheers

2017-07-10 10:08 GMT+01:00 adr_arroyo <[hidden email]>:
Hello,
I am trying to match two point clouds of descriptors of type RIFT32, finding
how many matches there are between both. I have the following code:

int matchRIFTFeaturesKnn(pcl::PointCloud<RIFT32>::Ptr descriptors1,
                pcl::PointCloud<RIFT32>::Ptr descriptors2) {
        // A kd-tree object that uses the FLANN library for fast search of nearest
neighbors.
        pcl::KdTreeFLANN<RIFT32> matching = new pcl::KdTreeFLANN<RIFT32>();
        pcl::KdTree<RIFT32>::PointCloudConstPtr ptr_descriptors1(descriptors1);
        matching.setInputCloud(ptr_descriptors1);
        // A Correspondence object stores the indices of the query and the match,
        // and the distance/weight.
        std::vector<int> correspondence;

        // Check every descriptor computed for the scene.
        for (size_t i = 0; i < descriptors2->points.size(); ++i) {
                std::vector<int> neighbors(1);
                std::vector<float> squaredDistances(1);
                // Find the nearest neighbor (in descriptor space)...
                int neighborCount = matching.nearestKSearch(descriptors2->points.at(i),
                                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]);
                        correspondence.push_back(neighbors[0]);
                }
        }
        std::cout << "Found " << correspondence.size() << " correspondences\n";
        return correspondence.size();
}


But It is giving me a compilation error about the class KdTreeFLANN:

CMakeFiles/comparator.dir/src/comparator.cpp.o: In function
`matchRIFTFeaturesKnn(boost::shared_ptr<pcl::PointCloud&lt;pcl::Histogram&lt;32>
> >, boost::shared_ptr<pcl::PointCloud&lt;pcl::Histogram&lt;32> > >)':
comparator.cpp:(.text+0xe87): reference to
`pcl::KdTreeFLANN<pcl::Histogram&lt;32>, flann::L2_Simple<float>
>::KdTreeFLANN(bool)' not defined
comparator.cpp:(.text+0xea1): not defined
`pcl::KdTreeFLANN<pcl::Histogram&lt;32>, flann::L2_Simple<float>
>::KdTreeFLANN(bool)' not defined
comparator.cpp:(.text+0xf0a): referencia a
`pcl::KdTreeFLANN<pcl::Histogram&lt;32>, flann::L2_Simple<float>
>::setInputCloud(boost::shared_ptr<pcl::PointCloud&lt;pcl::Histogram&lt;32>
> const> const&, boost::shared_ptr<std::vector&lt;int,
std::allocator&lt;int> > const> const&)' not defined
comparator.cpp:(.text+0x102d): reference to
`pcl::KdTreeFLANN<pcl::Histogram&lt;32>, flann::L2_Simple<float>
>::nearestKSearch(pcl::Histogram<32> const&, int, std::vector<int,
std::allocator&lt;int> >&, std::vector<float, std::allocator&lt;float> >&)
const' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o: In function
`pcl::KdTreeFLANN<pcl::Histogram&lt;32>, flann::L2_Simple<float>
>::~KdTreeFLANN()':
comparator.cpp:(.text._ZN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEED2Ev[_ZN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEED5Ev]+0x20):
reference to `pcl::KdTreeFLANN<pcl::Histogram&lt;32>,
flann::L2_Simple<float> >::cleanup()' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x10):
reference to `pcl::KdTreeFLANN<pcl::Histogram&lt;32>,
flann::L2_Simple<float>
>::setInputCloud(boost::shared_ptr<pcl::PointCloud&lt;pcl::Histogram&lt;32>
> const> const&, boost::shared_ptr<std::vector&lt;int,
std::allocator&lt;int> > const> const&)' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x28):
reference to `pcl::KdTreeFLANN<pcl::Histogram&lt;32>,
flann::L2_Simple<float> >::nearestKSearch(pcl::Histogram<32> const&, int,
std::vector<int, std::allocator&lt;int> >&, std::vector<float,
std::allocator&lt;float> >&) const' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x40):
reference to `pcl::KdTreeFLANN<pcl::Histogram&lt;32>,
flann::L2_Simple<float> >::radiusSearch(pcl::Histogram<32> const&, double,
std::vector<int, std::allocator&lt;int> >&, std::vector<float,
std::allocator&lt;float> >&, unsigned int) const' not defined
CMakeFiles/comparator.dir/src/comparator.cpp.o:(.rodata._ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE[_ZTVN3pcl11KdTreeFLANNINS_9HistogramILi32EEEN5flann9L2_SimpleIfEEEE]+0x58):
reference to `pcl::KdTreeFLANN<pcl::Histogram&lt;32>,
flann::L2_Simple<float> >::setEpsilon(float)' not defined
collect2: error: ld returned 1 exit status
make[2]: *** [comparator] Error 1
make[1]: *** [CMakeFiles/comparator.dir/all] Error 2
make: *** [all] Error 2

What am I doing wrong?
Cheers



--
View this message in context: http://www.pcl-users.org/Matching-RIFT-features-with-KdTreeFLANN-tp4044742.html
Sent from the Point Cloud Library (PCL) Users mailing list mailing list archive at Nabble.com.
_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users


_______________________________________________
[hidden email] / http://pointclouds.org
http://pointclouds.org/mailman/listinfo/pcl-users
Reply | Threaded
Open this post in threaded view
|

Re: Matching RIFT features with KdTreeFLANN

adr_arroyo
Hi, thanks but I am not directly compiling pcl, this is my code inwhich I am including the pcl library. How do I set that option with the CMakelists of my own code?

Cheers