1
2 /* autopano-sift, Automatic panorama image creation
3 * Copyright (C) 2004 -- Sebastian Nowozin
4 *
5 * This program is free software released under the GNU General Public
6 * License, which is included in this software package (doc/LICENSE).
7 */
8
9 /* GenerateKeys.cs
10 *
11 * SIFT feature detector keypoint file generator
12 *
13 * (C) Copyright 2004 -- Sebastian Nowozin (nowozin@cs.tu-berlin.de)
14 *
15 * "This software is provided for non-commercial use only. The University of
16 * British Columbia has applied for a patent on the SIFT algorithm in the
17 * United States. Commercial applications of this software may require a
18 * license from the University of British Columbia."
19 * For more information, see the LICENSE file supplied with the distribution.
20 */
21
22 #include "AutoPanoSift.h"
23
main(int argc,char * argv[])24 int main (int argc, char* argv[])
25 {
26 WriteLine("SIFT Keypoint Generation, version %s\n", PACKAGE_VERSION);
27
28 if ((argc-1) < 2 || (argc-1) > 3) {
29 WriteLine ("usage: generatekeys.exe image output.key [minDim]\n");
30
31 WriteLine ("image: Image file (any common format: JPEG, PNG, TIFF, ..)");
32 WriteLine ("output.key: Output keypoint file");
33 WriteLine (" The output file can be stored in gzip compressed format by appending\n \".gz\" to the filename.");
34 WriteLine ("minDim: (optional) Downscale resolution");
35 WriteLine (" The image is repeatedly halfed in size until both width and height\n are below 'minDim'.");
36 WriteLine ("");
37
38 return -1;
39 }
40
41 // 1. load the image file
42 //WriteLine ("opening %s", argv[1]);
43
44 DisplayImage* pic = DisplayImage_new(argv[1]);
45 int pW = pic->width;
46 int pH = pic->height;
47
48 double startScale = 1.0;
49 if ((argc-1) >= 3) {
50 int downRes;
51 if (!sscanf(argv[3], "%d", &downRes)) {
52 WriteLine ("Downscale resolution \"%s\" is not valid.\nUse a positive integer.", argv[3]);
53 return -1;
54 }
55
56 if (downRes > 0) {
57 startScale = DisplayImage_ScaleWithin(pic, downRes);
58 WriteLine ("Scaled picture, starting with scale %0.04f",
59 startScale);
60 }
61 }
62
63 ImageMap* picMap = DisplayImage_ConvertToImageMap(pic);
64 DisplayImage_delete(pic);
65
66 // 2. find the features
67 LoweFeatureDetector* lf = LoweFeatureDetector_new0();
68 if (argc > 3) {
69 LoweFeatureDetector_DetectFeaturesDownscaled (lf, picMap, 0, 1.0 / startScale);
70 } else
71 LoweFeatureDetector_DetectFeatures (lf, picMap);
72
73 WriteLine ("found %d global keypoints",
74 ArrayList_Count(LoweFeatureDetector_GlobalNaturalKeypoints(lf)));
75
76 KeypointXMLWriter_WriteComplete (argv[1], pW, pH, argv[2],
77 LoweFeatureDetector_GlobalNaturalKeypoints(lf));
78
79 LoweFeatureDetector_delete(lf);
80 return 0;
81 }
82
83
84