Question

I am working on real time object recognition using Opancv4android, i am able to detect, extract feature points using ORB detector and descriptor extractor from the image i capture using camera . Now, i want to build a Kdtree and train them with these feature points and later i match these feature points in the tree with feature points detected by the camera in real time and recognizance the object . Please help me on how do i go about building a KD tree in opencv or any pointers or references/tutorials on KDtree for opencv will be very helpful.

Was it helpful?

Solution 2

FLANN matcher (also this link)is based on the kd-tree, it is build automatically inside matcher.

But I recommend you to use BFMatcher with Hamming distance - it is designed for binary descriptor as ORB in your case. Here is an example how it is used for FREAK (binary descriptor too).

OTHER TIPS

Approach for implementation, will post the code once its completely done

Collecting the training set

capture all the images on which you want to train and store them in your SDcard/external directory in android and have a xml/txt files which contains all the names of the images you have captured.

Feature extraction

capture the frames from camera ans pass it to a Mat object from there you can extract the features to get the query descriptor set. For extracting the features from the training set, you read the file from the storage location get the list of images in the file and pass all the images stored into a vector of Mat objects and extract the feature points to get training descriptor set.

Descriptor matching

same goes here, you need to pass query descriptor and vector of training descriptor and you get the output in terms of vector of Dmatches after obtaining the result of correct match you can draw matches between the images or use homography to draw a rectangle on the recognised object.

Skeleton code

static void detectKeypoints( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
                  const vector<Mat>& trainImages, vector<vector<KeyPoint> >& trainKeypoints,
                  Ptr<FeatureDetector>& featureDetector )
{

featureDetector->detect( queryImage, queryKeypoints );
featureDetector->detect( trainImages, trainKeypoints );

}

static void computeDescriptors( const Mat& queryImage, vector<KeyPoint>& queryKeypoints, Mat& queryDescriptors,
                     const vector<Mat>& trainImages, vector<vector<KeyPoint> >& trainKeypoints, vector<Mat>& trainDescriptors,
                     Ptr<DescriptorExtractor>& descriptorExtractor )
{

descriptorExtractor->compute( queryImage, queryKeypoints, queryDescriptors );
descriptorExtractor->compute( trainImages, trainKeypoints, trainDescriptors );


}

static void matchDescriptors( const Mat& queryDescriptors, const vector<Mat>& trainDescriptors,
                   vector<DMatch>& matches, Ptr<DescriptorMatcher>& descriptorMatcher )
{

descriptorMatcher->add( trainDescriptors );
descriptorMatcher->train();

descriptorMatcher->match( queryDescriptors, matches );

CV_Assert( queryDescriptors.rows == (int)matches.size() || matches.empty() );


}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top