【问题标题】:How to use ORB feature detector with small images in OpenCV如何在 OpenCV 中使用带有小图像的 ORB 特征检测器
【发布时间】:2021-04-12 14:06:48
【问题描述】:

我很难完成这项工作。 我的图像集由小图像 (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.
)

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

我正在测试一组相当大的停车场图像(约 3900 张 58x65 的图像),包括空的和被占用的。

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

我做错了什么?我的猜测是上面提到的参数。在这方面有更多经验的人可以确认一下吗?

编辑:

Here 是图像的一小部分。

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

【问题讨论】:

  • 您是否正在尝试使用 ORB 特征检测器构建汽车分类器? ORB 特征是低级特征,只是从训练集中找到相似的特征并不能很好地发挥作用,正如您现在所想的那样。
  • 不是汽车分类器(识别本田、日产、福特等),而是停车场空间标识符(空的与占用的)
  • 你能展示一些图片(空的和占用的)吗?也许实现了 ORB 检测?
  • 刚刚用图片样本和完整数据集的链接更新了问题

标签: python opencv image-processing feature-extraction orb


【解决方案1】:

ORB 和小图像通常不会一起看到,因为检测器的窗口大小和尺度数量。您的窗口大小为 7 x 7,您选择的比例数为 8,比例因子为 1.2。这是检测器的典型设置,但如果您进行数学计算,您会很快意识到,随着您进一步缩小,窗口大小将太大,如果有的话,只会提示很少检测。我不建议你在这里使用 ORB。

尝试使用密集特征描述符,例如 HOG 或 Dense 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)

对于密集筛选:

import cv2

sample = ... # Path to image here

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

# Create SIFT object
sift = cv2.xfeatures2d.SIFT_create()

# Provide a list of keypoints in spaces of 5 pixels horizontally and vertically
# Change the step size according to what you want
step_size = 5
kp = [cv2.KeyPoint(x, y, step_size) for y in range(0, img.shape[0], step_size) 
                                    for x in range(0, img.shape[1], step_size)]

# Calculate Dense SIFT feature vector
dense_feat = sift.compute(img, kp)

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

【讨论】:

  • 关于 HOG 描述符,它使用了一些更改的参数,但我不知道如何处理生成的输出(直方图),因为我期望一个关键点列表
  • 如果你告诉我你想用关键点做什么,这会给我带来一些好处。使用 HOG,您可以使用滑动窗口,计算每个滑动窗口的 HOG,然后将滑动窗口放入某个判别分类器中,给出每个窗口内对象的概率。 HOG + SVM 传统上用于行人检测(Dalal 和 Triggs 2005)——事实上,HOG 来自这项工作。顺便说一句,HOG 的输出不是直方图。它是一个描述符,非常类似于每个关键点的 SIFT,但长度取决于您设置描述符时的参数。
  • 我正在使用停车场图像数据集来查找训练集图像的关键点,包括空白空间和占用空间。在我使用其他图像(来自同一数据集)并测量到每个训练图像的距离之后。目标是检测搜索到的图像是否更接近空图像或忙碌图像。
  • 首先我尝试使用 PKLOT 数据集,使用小图像(每个 58x65),但无法正常工作。现在我正在尝试使用 CNRPark 数据集(150x150),到目前为止也没有成功。
  • 所以你想在占用空间和非占用空间中找到关键点。你如何处理关键点?一组关键点如何表示图像?你如何用关键点确定一张图像和另一张图像之间的距离?请提供更多详细信息。我想问是因为我坚信你可以在没有关键点的情况下做到这一点。您有小图像,而关键点算法通常适用于较大的图像。
猜你喜欢
  • 2018-04-21
  • 2011-11-06
  • 2019-09-19
  • 2018-01-15
  • 2018-01-30
  • 2013-03-18
  • 2013-11-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多