Demo code(演示代码) for detecting and matching SIFT features
- 格式:docx
- 大小:17.21 KB
- 文档页数:10
Demo code(演示代码) for detecting and matching SIFT features -------------------------------------------------- David Lowe (lowe@cs.ubc.ca) Version 4, July 6, 2005
This directory contains compiled binary programs for finding SIFT Invariant(不变) features that can run under Linux or Windows. In addition, there is a Matlab script as well as C source code showing how to load the features and do simple feature matching.
See the web page at http://www.cs.ubc.ca/~lowe/keypoints/ for references to the relevant papers describing this approach.
Running from within Matlab --------------------------
If you have access to Matlab, scripts are provided for loading SIFT features and finding matches between images. These were tested under Matlab Version 7 and do not require the image processing toolbox.
Run Matlab in the current directory(目录) and execute(执行) the following commands. The "sift" command calls the appropriate binary to extract SIFT features (under Linux or Windows) and returns them in matrix form. Use "showkeys" to display the keypoints superimposed on the image:
[image, descrips, locs] = sift('scene.pgm'); showkeys(image, locs);
The "match" command is given two image file names. It extracts SIFT features from each image, matches the features between the two images, and displays the results.
match('scene.pgm','book.pgm'); The result shows the two input images next to each other, with lines connecting the matching locations. Most of the matches should be correct(调整) (as can be roughly judged by the fact that they select the correct object in a cluttered(杂乱) image), but there will be a few false(错误)outliers(异常值) that could be removed by enforcing viewpoint consistency constraints.
You can also try matching other images: 书 match('scene.pgm','box.pgm'); 印度香米 match('scene.pgm','basmati.pgm');
For more details, see the comments in the Matlab scripts: sift.m, showkeys.m, and match.m.
Acknowledgments: The Matlab script for loading SIFT features is based on one provided by D. Alvaro and J.J. Guerrero.Binaries for detecting SIFT features ------------------------------------
You do not need Matlab to run the demo. The program binary for keypoint extraction under Linux is named "sift", and should run under most versions of Linux on Intel compatible processors. The executable for Windows is named "siftWin32.exe". The code was developed under Linux and follows Unix conventions, but the Windows binary produces identical keypoints.
You can detect keypoints and display them on the provided test images with the command line option "-display" as follows (for Linux):
% sift -display result.pgm [If you are using Windows, first open the Windows Command Prompt and cd to the directory containing the binary before executing the command. In all cases when using Windows, replace sift with siftWin32.]
This will write out a new image, result.pgm, with arrows overlayed(覆盖图)indicating the locations, scales, and orientations of the key features. You can inspect this image using the public domain program xv:
% xv result.pgm or use any other tool that displays the common PGM image format. [Under Windows, you can use the freeware program IrfanView (www.irfanview.com) to view PGM images and covert to/from other formats.]
Note that(既然) you can control the number of keypoints by scaling(缩放) the image resolution(分辨率). An image of size 500 pixels square will typically give over 1000 keypoints depending on image content, which is plenty for most applications. Images from most digital cameras should be greatly reduced in resolution before being used. Changing image resolution is the best method to control the number of keypoints, as it is the larger scale(规模) keypoints that are most reliable and this is also much more efficient than processing large images. The current compiled binaries(编译文件) will raise an exception(异常) for images with dimensions(尺寸大小) greater than about 1800 pixels in any dimension. Color images will need to be convereted to grayscale (PGM format is only for grayscale images).
ASCII file output for keypoints -------------------------------
Without any command line arguments, the "keypoint" program will