如何在 OpenCV 中使用带有小图像的 ORB 特征检测器

And*_*sta 1 python opencv image-processing feature-extraction orb

我很难完成这项工作。我的图像集由小图像 (58x65) 组成。

我正在使用带有以下参数的 ORB:

# Initiate ORB detector
# default: ORB(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31, int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31)
orb = cv2.ORB_create(
  nfeatures = 500,                    # The maximum number of features to retain.
  scaleFactor = 1.2,                  # Pyramid decimation ratio, greater than 1
  nlevels = 8,                        # The number of pyramid levels.
  edgeThreshold = 7,                  # This is size of the border where the features are not detected. It should roughly match the patchSize parameter
  firstLevel = 0,                     # It should be 0 in the current implementation.
  WTA_K = 2,                          # The number of points that produce each element of the oriented BRIEF descriptor.
  scoreType = cv2.ORB_HARRIS_SCORE,   # The default HARRIS_SCORE means that Harris algorithm is used to rank features (the score is written to KeyPoint::score and is 
                                      # used to retain best nfeatures features); FAST_SCORE is alternative value of the parameter that produces slightly less stable 
                                      # keypoints, but it is a little faster to compute.
  #scoreType = cv2.ORB_FAST_SCORE,
  patchSize = 7                       # size of the patch used by the oriented BRIEF descriptor. Of course, on smaller pyramid layers the perceived image area covered
                                      # by a feature will be larger.
)
Run Code Online (Sandbox Code Playgroud)

可以看出,我更改了 edgeThreshold 和 patchSize 参数,但恐怕这些尺寸太小而无法找到有意义的特征。

我正在使用一组相当大的停车场图像(约 3900 张 58x65 的图像)进行测试,其中包括空的和有人的。

但结果并不一致:一辆停放的汽车(来自集合之外)的图像显示为比​​其他停放的汽车更接近空地。

我可能做错了什么?我的猜测是上面提到的参数。在这个问题上有更多经验的人可以证实这一点吗?

编辑:

是图像的一小部分。

完整的数据集可以在这里找到。

ray*_*ica 5

由于探测器的窗口大小和尺度数量,ORB 和小图像通常不会同时出现。您的窗口大小为 7 x 7,您选择的比例数为 8,比例因子为 1.2。这是检测器的典型设置,但如果您进行数学计算,您很快就会意识到,当您进一步缩小比例时,窗口大小将太大,从而提示很少的检测(如果有)。我不建议您在这里使用 ORB。

尝试使用密集特征描述符,例如 HOG 或密集 SIFT,它为像素的重叠窗口提供特征描述符,无论其组成如何。从您描述的图像来看,这听起来是一个更好的方法。

假设您有一个名为 的灰度图像im,对于 HOG:

import cv2

sample = ... # Path to image here

# Create HOG Descriptor object
hog = cv2.HOGDescriptor()

im = cv2.imread(sample, 0) # Grayscale image

# Compute HOG descriptor
h = hog.compute(im)
Run Code Online (Sandbox Code Playgroud)

对于密集 SIFT:

import cv2

sample = ... # Path to image here

# Create HOG Descriptor object
hog = cv2.HOGDescriptor()

im = cv2.imread(sample, 0) # Grayscale image

# Compute HOG descriptor
h = hog.compute(im)
Run Code Online (Sandbox Code Playgroud)

请注意,对于 SIFT 描述符,您需要安装opencv-contrib-python库的风格(即pip install opencv-contrib-python)。