Reputation: 495
I would like to match a picture with a database which contains more than 2500 pictures at the moment, but I need to find a way to get good results with at least 10k pictures.
I already read a lot of posts on stackoverflow but I couldn't find a proper solution to my problem. I thought about using histograms, but if I understand well, it is useful to find similarities, however I need a 'perfect' match.
I currently have some code working to do the task, but it is too slow (about 6 seconds to find a match with 2500 images)
I'm using ORB detector cv2.ORB()
to find keypoints and descriptors, FlannBasedMatcher and findHomography function with RANSAC as you can see below.
FLANN_INDEX_LSH = 6
flann_params = dict(algorithm = FLANN_INDEX_LSH, table_number = 6, key_size = 12, multi_probe_level = 1)
...
self.matcher = cv2.FlannBasedMatcher(params, {})
...
(_, status) = cv2.findHomography(ptsA, ptsB, cv2.RANSAC, 4.0)
I want to know if there is a better, and more important, a faster way to match with my database, and maybe a different way to store pictures in a database (I'm currently saving keypoints and descriptors).
I hope I was clear enough, if you need more details, post in comments.
Upvotes: 4
Views: 5280
Reputation: 495
The point of what I am doing is to recognize a page from a book on a video capture, that's why I needed my code to be fast, and accurate.
I found a faster way to do the job, I built a FLANN index with the whole database at startup (which is not that slow with 3k pictures), I got help from this link.
Also, and that's the most important part, I changed my flann_params
to this :
flann_params = dict(algorithm = FLANN_INDEX_LSH, table_number = 10, key_size = 20, multi_probe_level = 0)
In order to not lose accuracy with these parameters, I changed the number of feature points I extract with ORB detector from 400 to 700.
It fixed my problem, before the match was done between 2 and 3 seconds (6 seconds without FLANN index), now it is around 25/30ms
But even after this solution, I'm still open to new suggestions to improve accuracy without losing much speed.
Upvotes: 4