简体   繁体   中英

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. I have a database of 1659 pictures (.jpg, each picture around 95 KB). For each image, I created a .yml file with Keypoints and Descriptors. Now, for a single image, I ended up with 700 keypoint and descriptors resulting in a file of ca. 4MB and I would like to avoid using binary files.
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?
  • 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). Is there a problem if I reduce the significant digits? For example to 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:

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.

Ok, does the .yml really helps when your have large data to store? Is is really reasonable? And do you really need every element of keypoint (points2f, size, response, octave, class_id) . As for descriptor, it is a histogram, or a int array. So even if you save it as int, the value is just ok.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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