简体   繁体   English

OpenCV / Python:将图片与数据库匹配的快速方法

[英]OpenCV / Python : Fast way to match a picture with a database

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.我想将一张图片与目前包含 2500 多张图片的数据库进行匹配,但我需要找到一种方法来获得至少 10k 张图片的良好结果。

I already read a lot of posts on stackoverflow but I couldn't find a proper solution to my problem.我已经阅读了很多关于 stackoverflow 的帖子,但我找不到合适的解决方案来解决我的问题。 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)我目前有一些代码可以完成这项任务,但速度太慢(大约 6 秒才能找到与 2500 张图像匹配的内容)

I'm using ORB detector cv2.ORB() to find keypoints and descriptors, FlannBasedMatcher and findHomography function with RANSAC as you can see below.我正在使用 ORB 检测器cv2.ORB()来查找关键点和描述符、FlannBasedMatcher 和带有 RANSAC 的 findHomography 函数,如下所示。

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.我希望我足够清楚,如果您需要更多详细信息,请在评论中发表。

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 .我找到了一种更快的方法来完成这项工作,我在启动时用整个数据库建立了一个 FLANN 索引(这对于 3k 图片来说并没有那么慢),我从这个链接获得了帮助。 Also, and that's the most important part, I changed my flann_params to this :另外,这是最重要的部分,我将flann_params更改为:

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.为了不损失这些参数的准确性,我将使用 ORB 检测器提取的特征点数量从 400 更改为 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它解决了我的问题,在比赛完成之前 2 到 3 秒(没有 FLANN 索引的 6 秒),现在大约是 25/30 毫秒

But even after this solution, I'm still open to new suggestions to improve accuracy without losing much speed.但即使在这个解决方案之后,我仍然愿意接受新的建议来提高准确性而不损失太多速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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