简体   繁体   中英

C++/SIFT/SQL - If there a way to compare efficiently a SIFT descriptor of an image with a SIFT descriptor in a SQL database?

I would like to find a way which would allow to compare a SIFT descriptor of an image (query) with descriptors in a SQL database which contains lots of descriptors of differents pictures.

In fact, my final purpose is to do an application which allow to compare one picture with lots of picture in a database (not in my device) but in a SQL database.

The first thing i thought was to stock each descriptors on the SQL database and compare each descriptors to another one using the Brute Force method or the FlanneBased method. The problem is that,in a SQL database, it would take a long time to compute a matching because of the "mathematics" behind the matching (Euclidean distance for example is sqrt(a²+b² +...) ) and it's not possible to do that kind of comparison in an huge database.

For example a SIFT descriptor contains 128 numbers if i'm not mistaken so imagine the time comparing each number of each descriptors together.

If there another way to do that stuff ? I know in a SQL database, requests are efficient when you use something like "SELECT a FROM b WHERE ..."

Therefore i wonder if there is a way to stock SIFT descriptors in an efficiently way ? For example i thought about "to crypte" the descriptors into a kind of big string chain and each chain would be unique and therefore i could compare them together but i don't know if it's a good solution.

I've already read this post : Comparing SIFT features stored in a mysql database but it didn't help me. Thank you.

If I were you, I would prefer comparing the descriptors in the code, rather than in SQL. SQL isn't meant for that. I would do the following:-

1. Pre-load N descriptors from SQL onto memory.
2. Compare distances to query descriptor, descriptor by descriptor.
3. If distance<threshold, push to possiblematches.
4. When you reach N/2 descriptors, push the next N.
5. Compare all matches, choose the best one or the best D descriptors, as per your requirement.

However, for this, I'd rather use OpenCV¡s inbuilt FileStorage class which provides I/O onto XML and YAML files; it solves the headache of manually parsing descriptor values.

It is not optimal to use a SQL database to compare SIFT. OpenCV proposes some keypoint matchers that are more efficient. You can find an example in ./samples/cpp/matcher_simple.cpp with SURF descriptors that is easily adaptable to SIFT. Basicaly, the core is

BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);

As far as I remember, some matchers (eg Flann) only works with descriptors of certain type (CV_32F).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM