简体   繁体   English

Python / OpenCV如何处理.yml文件中的大量SIFT功能?

[英]Python/OpenCV how to deal with large number of SIFT feaure in .yml file?

I'm using OpenCv and I took yaml to store SIFT Keypoints and Descriptors. 我正在使用OpenCv,并使用yaml来存储SIFT关键点和描述符。 I have a database of 1659 pictures (.jpg, each picture around 95 KB). 我有一个1659张图片(.jpg,每张图片约95 KB)的数据库。 For each image, I created a .yml file with Keypoints and Descriptors. 对于每个图像,我创建了一个带有关键点和描述符的.yml文件。 Now, for a single image, I ended up with 700 keypoint and descriptors resulting in a file of ca. 现在,对于一幅图像,我最终得到了700个关键点和描述符,结果得到了一个大约文件。 4MB and I would like to avoid using binary files. 4MB,我想避免使用二进制文件。
My questions are: 我的问题是:

  • How can I know if the number of features is adequate to the image? 我如何知道特征数量是否足以容纳图像?
  • There is any way to control the number of features? 有什么方法可以控制功能数量? For example, setting a threshold for SIFT? 例如,为SIFT设置阈值?
  • Now storing a numpy matrix into a yamil file using cv2.FileStorage.write , OpenCv writes each number with a 16 significant digits (ex. 1.9705572128295898e+00). 现在,使用cv2.FileStorage.write将numpy矩阵存储到yamil文件中,OpenCv用16个有效数字(例如1.9705572128295898e + 00)写入每个数字。 Is there a problem if I reduce the significant digits? 如果我减少有效数字是否有问题? For example to 4? 例如到4?
  1. How can I know if the number of features is adequate to the image? 我如何知道特征数量是否足以容纳图像?

It must depends on your image, you task requirements. 它必须取决于您的图像和任务要求。 You should know better than others, or do experiment to make it clear. 您应该比其他人了解更多,或者做一些实验来弄清楚。

  1. There is any way to control the number of features? 有什么方法可以控制功能数量?

Of course. 当然。 When create, just pass the necessary parameters. 创建时,只需传递必要的参数。

cv2.xfeatures2d.SIFT_create([, nfeatures[, nOctaveLayers[, contrastThreshold[, edgeThreshold[, sigma]]]]]) -> retval
 | . @param nfeatures The number of best features to retain. The features are ranked by their scores
 | . (measured in SIFT algorithm as the local contrast)
 | .
 | . @param nOctaveLayers The number of layers in each octave. 3 is the value used in D. Lowe paper. 
 | . The number of octaves is computed automatically from the image resolution.
 | .
 | . @param contrastThreshold The contrast threshold used to filter out weak features in semi-uniform
 | . (low-contrast) regions. The larger the threshold, the less features are produced by the detector.
 | .
 | . @param edgeThreshold The threshold used to filter out edge-like features. Note that the its meaning
 | . is different from the contrastThreshold, i.e. the larger the edgeThreshold, the less features are
 | . filtered out (more features are retained).
 | .
 | . @param sigma The sigma of the Gaussian applied to the input image at the octave \#0. If your image
 | . is captured with a weak camera with soft lenses, you might want to reduce the number.
 |

Such as, I create a sift detector with 50 keypoints and 3 layers: 例如,我创建了一个具有50个关键点和3层的筛选检测器:

sift = cv2.xfeatures2d.SIFT_create(nfeatures = 50, nOctaveLayers=3)

This is the detect result: 这是检测结果:

在此处输入图片说明

  1. Too long. 太长。 I know you stored large number keypoints and descriptors into .yml format in OpenCV-Python. 我知道您在OpenCV-Python中将大量关键点和描述符存储为.yml格式。

Ok, does the .yml really helps when your have large data to store? 好的,当您有大数据要存储时, .yml真的有帮助? Is is really reasonable? And do you really need every element of keypoint (points2f, size, response, octave, class_id) . 是真的很合理吗?您真的需要每个keypoint (points2f, size, response, octave, class_id)元素keypoint (points2f, size, response, octave, class_id) As for descriptor, it is a histogram, or a int array. 对于描述符,它是直方图或int数组。 So even if you save it as int, the value is just ok. 因此,即使将其保存为int,该值也没问题。

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

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