简体   繁体   English

OpenCV-Python密集的SIFT

[英]OpenCV-Python dense SIFT

OpenCV has very good documentation on generating SIFT descriptors , but this is a version of "weak SIFT", where the key points are detected by the original Lowe algorithm . OpenCV有关于生成SIFT描述符的非常好的文档 ,但这是“弱SIFT”的版本,其中关键点由原始Lowe算法检测。 The OpenCV example reads something like: OpenCV示例读取如下内容:

img = cv2.imread('home.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

sift = cv2.SIFT()
kp = sift.detect(gray,None)
kp,des = sift.compute(gray,kp)

What I'm looking for is strong/dense SIFT, which does not detect keypoints but instead calculates SIFT descriptors for a set of patches (eg 16x16 pixels, 8 pixels padding) covering an image as a grid. 我正在寻找的是强/密SIFT,它不检测关键点,而是计算一组补丁(例如16x16像素,8像素填充)的SIFT描述符,覆盖图像作为网格。 As I understand it, there are two ways to do this in OpenCV: 据我了解,在OpenCV中有两种方法可以做到这一点:

  • I could divide the image in a grid myself, and somehow convert those patches to KeyPoints 我可以自己将图像分成网格,并以某种方式将这些补丁转换为KeyPoints
  • I could use a grid-based feature detector 我可以使用基于网格的特征检测器

In other words, I'd have to replace the sift.detect() line with something that gives me the keypoints I require. 换句话说,我必须用能够提供我需要的关键点的东西替换sift.detect()行。

My problem is that the rest of the OpenCV documentation, especially wrt Python, is severely lacking, so I have no idea how to achieve either of these things. 我的问题是OpenCV文档的其余部分,特别是wrt Python,严重缺乏,所以我不知道如何实现这两个方面。 I see in the C++ documentation that there are keypoint detectors for grid, but I don't know how to use these from Python. 我在C ++文档中看到网格有关键点检测器,但我不知道如何从Python中使用它们。

The alternative is to switch to VLFeat, which has a very good DSift/PHOW implementation but means that I'll have to switch from python to matlab. 另一种方法是切换到VLFeat,它具有非常好的DSift / PHOW实现,但意味着我必须从python切换到matlab。

Any ideas? 有任何想法吗? Thanks. 谢谢。

You can use Dense Sift in opencv 2.4.6 <. 你可以在opencv 2.4.6中使用Dense Sift <。 Creates a feature detector by its name. 按名称创建特征检测器。

cv2.FeatureDetector_create(detectorType) cv2.FeatureDetector_create(detectorType)

Then "Dense" string in place of detectorType 然后用"Dense"字符串代替detectorType

eg:- 例如:-

dense=cv2.FeatureDetector_create("Dense")
kp=dense.detect(imgGray)
kp,des=sift.compute(imgGray,kp)

I'm not sure what your goal is here, but be warned, the SIFT descriptor calculation is extremely slow and was never designed to be used in a dense fashion. 我不确定你的目标是什么,但是要注意,SIFT描述符计算速度非常慢,并且从未设计为以密集的方式使用。 That being said, OpenCV makes it fairly trivial to do so. 话虽如此,OpenCV使这样做变得相当简单。

Basically instead of using sift.detect(), you just fill in the keypoint array yourself by making a grid a keypoints however dense you want them. 基本上不是使用sift.detect(),而是通过使网格成为关键点而不是你想要的密集来自己填充关键点数组。 Then a descriptor will be calculated for each keypoint when you pass the keypoints to sift.compute(). 然后,当您将关键点传递给sift.compute()时,将为每个关键点计算描述符。

Depending on the size of your image and the speed of your machine, this might take a very long time. 根据图像的大小和机器的速度,这可能需要很长时间。 If copmutational time is a factor, I suggest you look at some of the binary descriptors OpenCV has to offer. 如果copmutational时间是一个因素,我建议你看一下OpenCV提供的一些二进制描述符。

Inspite of the OpenCV way being the standard, it was too slow for me. 尽管OpenCV方式成为标准,但对我来说这太慢了。 So for that, I used pyvlfeat, which is basically python bindings to VL-FEAT. 所以为此,我使用了pyvlfeat,它基本上是对VL-FEAT的python绑定。 The functions carry similar syntax as the Matlab functions 这些函数具有与Matlab函数类似的语法

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

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