bazar  1.3.1
planar_object_recognizer.h
Go to the documentation of this file.
1 /*
2 Copyright 2005, 2006 Computer Vision Lab,
3 Ecole Polytechnique Federale de Lausanne (EPFL), Switzerland.
4 All rights reserved.
5 
6 This file is part of BazAR.
7 
8 BazAR is free software; you can redistribute it and/or modify it under the
9 terms of the GNU General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 BazAR is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15 PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License along with
18 BazAR; if not, write to the Free Software Foundation, Inc., 51 Franklin
19 Street, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21 #ifndef PLANAR_OBJECT_RECOGNIZER_H
22 #define PLANAR_OBJECT_RECOGNIZER_H
23 
24 #include <keypoints/keypoint.h>
25 #include <keypoints/yape.h>
26 #include <starter.h>
27 #include "affine_image_generator.h"
28 #include "object_view.h"
31 
36 
37 
38 
40 static const int hard_max_detected_pts = 5000;
41 
50 {
51 public:
54 
56  planar_object_recognizer(string directory_name);
57 
59 
62  bool build_with_cache(string filename, int max_point_number_on_model,
63  int patch_size, int yape_radius,
64  int tree_number, int nbLev,
65  LEARNPROGRESSION LearnProgress=0);
66 
67  bool build(IplImage *model_image,
68  int max_point_number_on_model, int patch_size,
69  int yape_radius, int tree_number, int nbLev,
70  LEARNPROGRESSION LearnProgress=0, int *roi=0);
72 
74 
78 
83 
85  void set_noise_level(int noise_level);
86 
88  void set_use_random_background(bool use_random_background);
89 
91  void set_range_variation_for_theta(float min_theta, float max_theta);
93  void set_range_variation_for_phi(float min_phi, float max_phi);
94 
96  void independent_scaling(float min_lambda1, float max_lambda1, float min_lambda2, float max_lambda2);
98  void constrained_scaling(float min_lambda1, float max_lambda1,
99  float min_lambda2, float max_lambda2,
100  float min_l1_l2, float max_l1_l2);
101 
103  void use_orientation_correction(void);
105 
107  void set_max_depth(int p_max_depth) { max_depth = p_max_depth; }
108 
110  void set_sample_number_for_refining(int sample_number) { sample_number_for_refining = sample_number; }
113 
115  void learn(int max_point_number_on_model,
116  int patch_size, int yape_radius,
117  int tree_number, int nbLev=5,
118  LEARNPROGRESSION LearnProgress=0);
119 
121  void save(string directory_name);
122 
125  bool load(string directory_name);
126 
140  bool detect(IplImage * input_image);
141 
143  void set_max_detected_pts(int max);
144 
146 
148  void detect_points(IplImage * input_image);
149  void preprocess_points(void);
150  void match_points(bool fill_match_struct = true);
155 
161 
166 
172 
181 
183 
185  IplImage * create_result_image(IplImage * input_image,
186  bool p_draw_points, bool p_draw_matches,
187  bool p_draw_object, bool p_draw_model_image,
188  int line_width = 2);
189 
192  void debug_model_point(int p_index_of_model_point_to_debug)
193  { index_of_model_point_to_debug = p_index_of_model_point_to_debug; }
194 
196  void save_one_image_per_match(IplImage * input_image, const char * matches_dir);
197  void save_one_image_per_match_model_to_input(IplImage * input_image, const char * matches_dir);
198  void save_one_image_per_match_input_to_model(IplImage * input_image, const char * matches_dir);
199 
201 
203  void initialize(void);
204 
206 
208 
209  pair<object_keypoint, int> * search_for_existing_model_point(vector< pair<object_keypoint, int> > * tmp_model_points,
210  float cu, float cv, int scale);
211  void detect_most_stable_model_points(int max_point_number_on_model,
212  int patch_size, int view_number,
213  double min_view_rate,
214  LEARNPROGRESSION LearnProgress=0);
215  void save_image_of_model_points(int patch_size, char * filename = 0);
216 
219 
220  // For position estimation:
222  bool three_random_correspondences(int * n1, int * n2, int * n3);
223  bool valid(affinity * A);
224 
227 
230  void default_settings(void);
234 
237 
240 
245 
250 
254 
257 
260 
265 
267 
268  void save_patch_before_and_after_correction(IplImage * image,
269  int u, int v, int patch_size,
270  image_class_example * pv,
271  int point_index,
272  int call_number);
273  void concat_model_and_input_images(IplImage * input_image, bool p_draw_model_image = true);
274  void draw_points(int line_width = 1);
275  void draw_model_points(int line_width = 1);
276  void draw_input_image_points(int line_width = 1);
277  void draw_matches(int line_width = 2);
278  void draw_inlier_matches(int line_width = 1);
279  void draw_model(void);
281  int x0, y0; // up left corner of modelImage in modelInputImage
282  int u_input_image, v_input_image; // up left corner of inputImage in modelInputImage
284 
285  void check_target_size(IplImage *image);
286 };
287 
289 #endif // PLANAR_OBJECT_RECOGNIZER_H