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

2024-09-22 16:29:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我很难做到这一点。 我的图像集由小图像(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找到


Tags: oftheto图像参数isintscore
1条回答
网友
1楼 · 发布于 2024-09-22 16:29:27

由于探测器的窗口大小和刻度的数量,通常不能同时看到球体和小图像。窗口大小为7 x 7,选择的比例数为8,比例因子为1.2。这是探测器的典型设置,但如果你做数学运算,你会很快意识到,当你进一步缩小时,窗口大小将过大,提示很少检测(如果有的话)。我不建议您在这里使用ORB

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

假设您有一个名为im的灰度图像,例如:

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

相关问题 更多 >