Explain this algorithm (Compare points in SURF algorithm)
I need to know if this algorithm is a known one:
void getMatches(IpVec &ipts1, IpVec &ipts2, IpPairVec &matches, float ratio) {
float dist, d1, d2;
Ipoint *match;
matches.clear();
for (unsigned int i = 0; i < ipts1.size(); i++) {
d1 = d2 = FLT_MAX;
for (unsigned int j = 0; j < ipts2.size(); j++) {
dist = ipts1[i] - ipts2[j];
if (dist < d1) // if this feature matches better than current best
{
d2 = d1;
d1 = dist;
match = &ipts2[j];
} else if (dist < d2) // this feature matches better than second best
{
d2 = dist;
}
}
// If match has a d1:d2 ratio < 0.65 ipoints are a match
if (d1 / d2 < ratio) {
// Store the change in position
ipts1[i].dx = match->x - ipts1[i].x;
ipts1[i].dy = match->y - ipts1[i].y;
matches.push_back(std::make_pair(ipts1[i], *match));
}
}
}
class Ipoint {
public:
//! Destructor
~Ipoint() {
};
//! Constructor
Ipoint() : orientation(0) {
};
//! Gets the distance in descriptor space between Ipoints
float operator-(const Ipoint &rhs) {
float sum = 0.f;
for (int i = 0; i < 64; ++i) {
//std::cout << i << "\n";
try {
sum += (this->descriptor[i] - rhs.descriptor[i])*(this->descriptor[i] - rhs.descriptor[i]);
} catch (char *str) {
std::cout << "Caught some other exception: " << str << "\n";
}
}
return sqrt(sum);
};
//! Coordinates of the detected interest point
float x, y;
//! Detected scale
float scale;
//! Orientation measured anti-clockwise from +ve x-axis
float orientation;
//! Sign of laplacian for fast matching purposes
int laplacian;
//! Vector of descriptor components
float descriptor[64];
//! Placeholds for point motion (can be used for frame to frame motion analysis)
float dx, dy;
//! Used to store cluster index
int clusterIndex;
};
This compares the results of SURF algorithm.
- This is a nearest neighbor algorithm? That looks like the func is searching the nearest point of every point.
- Can I do the same using Quadtree or kd-tree?
- There is a better algorithm to compare to images points and know if them are the same or similar?
- Preferable I want to store them into mysql and build a kd-tree to compare 1 image through all images, that's possible?
- RANSAC is 开发者_JS百科useful for anything in this task?
- There is any method to catch false positives?
You've asked a lot of questions and I don't think I can answer all of them, but here are answers to as much of your question as I can.
This is most certainly a nearest-neighbor algorithm where the goal is to find the two closest points to each point in the first vector and then check whether the ratio of their distances is less than some cutoff value.
You could do this with a quadtree or kd-tree, but because your points are all one-dimensional values you could do much better using a balanced binary search tree. Given such a tree, if you thread a linked list through the nodes, you can find the k nearest neighbors to some test point p by looking up the closest element p in the binary search tree, then traversing (k + 1) steps in each direction and taking the k closest points of what you find. This runs in time O(lg n + k), where n is the number of points and k is as above. This is substantially more efficient than what you have now, which takes O(n) time per lookup.
If the dimensionality of your feature vector is more than 1, but less than 20, then using kd-trees would be a very effective measure.
For higher dimensionalities, you might want to either reduce the number of dimensions with PCA before applying a kd-tree or use a more scalable ANN structure, such as locality-sensitive hashing.
SURF is best for scene and object detection. If you need to find out if two images are the same, you would do better with global descriptor algorithms, such as GIST. The advantage of using a global descriptor is that you get a single vector for the whole image and image comparison is performed with simple Eucledian distance.
You could definitely do this using MySQL because you don't need a kd-tree. A simple balanced binary tree should be sufficient.
RANSAC is a method of estimating model parameters that is robust against outliers. It is useful for using SURF features for combining multiple photographs into a 3D scene.
Checking for false positives is definitely a machine learning exercise and I'm not well-trained in that area. You could probably do this using a supervised learning algorithm (such as an SVM, boosted decision tree, or neural network), but I don't know enough to advise you on this.
Hope this helps!
I'll just answer 5 since templatetypedef addresses the rest. RANSAC is a parameter estimation method (kinda like finding the line of best fit to a set of data points). So its not directly useful in nearest neighbor searches.
精彩评论