00001 #ifndef osl_harris_h 00002 #define osl_harris_h 00003 //: 00004 // \file 00005 // \brief The Harris corner detector 00006 // 00007 // \par Parameters : 00008 // - corner_count_max - maximum no of corners required. 00009 // - gauss_sigma - sigma for the Gaussian smoothing. 00010 // - relative minimum - a guidance term: first attempt will be to collect all 00011 // corners whose corner strength is greater than (max 00012 // strength * relative minimum). 00013 // - scale factor - the 'k' from the Harris auto-correlation expression. 00014 // 00015 // \author Paul Beardsley, Robotics Research Group, Oxford University 00016 // \date 16 October 1995 00017 // 00018 // \verbatim 00019 // Modifications: 00020 // First version generated from C code with minimal modification for C++/TargetJr data structures. 00021 // P.Vanroose Mar97 corrected memory management (point_list_ & *free_*()) 00022 // P.Vanroose Aug97 point_list_ now safer (added AddPoint(); SetPointList() out of use now) 00023 // J.Mundy Jan98 slight modified the interface to correspond to new style using parameter blocks and image dispatch 00024 // \endverbatim 00025 00026 #include <vcl_iosfwd.h> 00027 #include <vcl_vector.h> 00028 #include <vcl_utility.h> 00029 #include <vxl_config.h> 00030 #include <vil1/vil1_memory_image_of.h> 00031 #include <osl/osl_harris_params.h> 00032 #include <osl/osl_roi_window.h> 00033 00034 //: An osl_harris object stores the internal buffers used by the Harris corner detector. 00035 class osl_harris 00036 { 00037 public: 00038 osl_harris(osl_harris_params const & params) : image_w(0), image_h(0), params_(params) { } 00039 00040 void compute(vil1_image const &image) { 00041 prepare_buffers(image.width(), image.height()); 00042 compute_gradients(image); 00043 compute_2nd_moments(); 00044 compute_cornerness(); 00045 compute_corners(); 00046 } 00047 00048 void get_corners(vcl_vector<vcl_pair<float, float> > &) const; 00049 void get_corners(vcl_vector<float> &, vcl_vector<float> &) const; 00050 void save_corners(vcl_ostream &stream) const; 00051 void save_corners(char const *file) const; 00052 00053 // these buffers persist between invocations so that 00054 // unnecessary allocation is not performed (a.stoddart). 00055 int image_w, image_h; 00056 00057 // the input image, as a monochrome byte bitmap. 00058 vil1_memory_image_of<vxl_byte> image_buf; 00059 00060 // gradient bitmaps. 00061 vil1_memory_image_of<int> image_gradx_buf; 00062 vil1_memory_image_of<int> image_grady_buf; 00063 00064 // second moment matrix of the gradient vector. 00065 vil1_memory_image_of<float> image_fxx_buf; 00066 vil1_memory_image_of<float> image_fxy_buf; 00067 vil1_memory_image_of<float> image_fyy_buf; 00068 00069 // the cornerness response map and its maximum value. 00070 vil1_memory_image_of<float> image_cornerness_buf; 00071 float corner_max; 00072 00073 // local maximum map. 00074 vil1_memory_image_of<bool> image_cornermax_buf; 00075 00076 // region of interest ? 00077 osl_roi_window window_str; 00078 00079 00080 // These are the stages of algorithm. Clients can call a subset of 00081 // these manually in order to insert algorithms of their own choice. 00082 void prepare_buffers(int w, int h); 00083 void compute_gradients(vil1_image const &); 00084 void compute_2nd_moments(); 00085 void compute_cornerness(); 00086 void compute_corners(); 00087 00088 protected: 00089 osl_harris_params params_; 00090 vcl_vector<vcl_pair<float, float> > cc; // corners 00091 private: 00092 // these routines called by compute() : 00093 void do_non_adaptive(double *corner_min); 00094 void do_adaptive(); 00095 }; 00096 00097 #endif // osl_harris_h