77#include " ../basic/progress.h"
88#include " ../basic/logger.h"
99#include " ../basic/stop_watch.h"
10+ #include " ../opengl/opengl_info.h"
1011
1112// include the header files for SiftGPU and SiftMatchGPU
1213#include " ../../3rd_party/SiftGPU/SiftGPU.h"
@@ -43,14 +44,16 @@ void ImageMatching::apply() {
4344
4445 image_features.clear ();
4546 StopWatch w;
47+ ogf_check_gl;
4648 Logger::out (title ()) << " extracting key points..." << std::endl;
4749 extract_key_points ();
4850 Logger::out (title ()) << " done. time: " << w.elapsed () << std::endl;
49-
51+ ogf_check_gl;
5052 w.start ();
5153 Logger::out (title ()) << " matching the images..." << std::endl;
5254 match_key_points ();
5355 Logger::out (title ()) << " done. time: " << w.elapsed () << std::endl;
56+ ogf_check_gl;
5457}
5558
5659
@@ -67,15 +70,17 @@ void ImageMatching::extract_key_points() {
6770 return ;
6871 }
6972
73+ ogf_check_gl;
7074 SiftGPU* sift = CreateNewSiftGPU ();
75+ ogf_check_gl;
7176 // Create a context for computation, and SiftGPU will be initialized automatically
7277 // The same context can be used by SiftMatchGPU.
7378 // Liangliang: I already have a OpenGL context. Just use it.
7479 if (sift->CreateContextGL () == SiftGPU::SIFTGPU_NOT_SUPPORTED) {
7580 Logger::err (title ()) << " SiftGPU not supported" << std::endl;
7681 return ;
7782 }
78-
83+ ogf_check_gl;
7984 char * argv[] = { " -fo" , " -1" , " -v" , " 0" , " -tc2" , " 7680" , " -b" , " -nomc" };//
8085 // -fo -1 staring from -1 octave
8186 // -v 1 only print out # feature and overall time
@@ -85,7 +90,7 @@ void ImageMatching::extract_key_points() {
8590 int argc = sizeof (argv)/sizeof (char *);
8691 sift->ParseParam (argc, argv);
8792 // sift->SetMaxDimension(8000);
88-
93+ ogf_check_gl;
8994 // /////////////////////////////////////////////////////////////////////
9095 // Only the following parameters can be changed after initialization (by calling ParseParam).
9196 // -dw, -ofix, -ofix-not, -fo, -unn, -maxd, -b
@@ -103,25 +108,25 @@ void ImageMatching::extract_key_points() {
103108 }
104109 if (project_->images [i].ignored )
105110 continue ;
106-
111+ ogf_check_gl;
107112 // Create a context for computation, and SiftGPU will be initialized automatically
108113 // The same context can be used by SiftMatchGPU.
109114 // Liangliang: I already have a OpenGL context. Just use it.
110115 if (sift->CreateContextGL () == SiftGPU::SIFTGPU_NOT_SUPPORTED) {
111116 Logger::err (title ()) << " SiftGPU not supported" << std::endl;
112117 break ;
113118 }
114-
119+ ogf_check_gl;
115120 const std::string& name = project_->images [i].file ;
116121 if (!sift->RunSIFT (name.c_str ())) {
117122 Logger::warn (title ()) << " processing image \' " << FileUtils::simple_name (name) << " \' failed" << std::endl;
118123 project_->set_ignore_image (name, true );
119124 continue ;
120125 }
121-
126+ ogf_check_gl;
122127 std::string sift_file = project_->sfm_keys_dir + ' /' + FileUtils::base_name (name) + " .key" ;
123128 sift->SaveSIFT (sift_file.c_str ());
124-
129+ ogf_check_gl;
125130 int image_width, image_height;
126131 sift->GetImageDimension (image_width, image_height);
127132 float focal_length_in_pixels = 1 .2f * std::max (image_width, image_height);
@@ -131,7 +136,7 @@ void ImageMatching::extract_key_points() {
131136
132137 int num = sift->GetFeatureNum (); // get feature count
133138 Logger::out (title ()) << FileUtils::simple_name (name) << " : " << num << " key points" << std::endl;
134-
139+ ogf_check_gl;
135140 std::vector<SiftGPU::SiftKeypoint> keys;
136141 std::vector<float > descriptors;
137142
@@ -141,17 +146,20 @@ void ImageMatching::extract_key_points() {
141146 // reading back feature vectors is faster than writing files
142147 // if you don't need keys or descriptors, just put NULLs here
143148 sift->GetFeatureVector (&keys[0 ], &descriptors[0 ]);
144- // this can be used to write your own sift file.
149+ // this can be used to write your own sift file.
150+ ogf_check_gl;
145151 }
146152
147153 ImageFeature feature;
154+ ogf_check_gl;
148155 feature.keys = keys;
149156 feature.descriptors = descriptors;
150157 image_features.push_back (feature);
151-
158+ ogf_check_gl;
152159 progress.next ();
153160 }
154161
162+ ogf_check_gl;
155163 delete sift;
156164}
157165
@@ -169,9 +177,9 @@ void ImageMatching::match_key_points() {
169177 Logger::err (title ()) << " could not write matches file \' " << match_table_file << " \' " << std::endl;
170178 return ;
171179 }
172-
180+ ogf_check_gl;
173181 SiftMatchGPU* matcher = new SiftMatchGPU;
174-
182+ ogf_check_gl;
175183 // Before initialization, you can choose between GLSL, and CUDA(if compiled).
176184 // matcher->SetLanguage(SiftMatchGPU::SIFTMATCH_CUDA); // +i for the (i+1)-th device
177185
@@ -189,14 +197,16 @@ void ImageMatching::match_key_points() {
189197 int num1 = (int )keys1.size ();
190198 if (num1 == 0 )
191199 continue ;
192-
200+
201+ ogf_check_gl;
193202 for ( int j = i+1 ; j < num; ++j) {
194203 const std::vector<SiftGPU::SiftKeypoint>& keys2 = image_features[j].keys ;
195204 const std::vector<float >& descriptors2 = image_features[j].descriptors ;
196205 int num2 = (int )keys2.size ();
197206 if (num2 == 0 )
198207 continue ;
199208
209+ ogf_check_gl;
200210 if (progress.is_canceled ()) {
201211 delete matcher;
202212 return ;
@@ -209,18 +219,20 @@ void ImageMatching::match_key_points() {
209219 Logger::err (title ()) << " SiftGPU not supported" << std::endl;
210220 break ;
211221 }
222+ ogf_check_gl;
212223
213224 // Set descriptors to match, the first argument must be either 0 or 1
214225 // if you want to use more than 4096 or less than 4096
215226 // call matcher->SetMaxSift() to change the limit before calling setdescriptor
216227 matcher->SetDescriptors (0 , num1, &descriptors1[0 ]); // image 1
217228 matcher->SetDescriptors (1 , num2, &descriptors2[0 ]); // image 2
218-
229+ ogf_check_gl;
219230 // match and get result.
220231 int (*match_buf)[2 ] = new int [num1][2 ];
221232 // use the default thresholds. Check the declaration in SiftGPU.h
222233 int num_match = matcher->GetSiftMatch (num1, match_buf);
223234 output << i << " " << j << std::endl << num_match << std::endl;
235+ ogf_check_gl;
224236
225237 // enumerate all the feature matches
226238 for (int k = 0 ; k < num_match; ++k) {
@@ -241,11 +253,14 @@ void ImageMatching::match_key_points() {
241253 output << std::endl;
242254
243255 delete[] match_buf;
256+ ogf_check_gl;
244257
245258 progress.next ();
246259 }
247260 }
248261
249262 image_features.clear ();
263+ ogf_check_gl;
250264 delete matcher;
265+ ogf_check_gl;
251266}
0 commit comments