grid.h
Go to the documentation of this file.
00001 //part of the source code of master thesis, source code produced by Jiri Divis
00010 #ifndef VSLAM_GRID_H_INCLUDED
00011 #define VSLAM_GRID_H_INCLUDED
00012 
00013 #include "utils.h"
00014 
00015 namespace vslam{
00016 
00017 struct Cell{
00018     int row;
00019     int col;
00020     Cell(int _r, int _c) : row(_r), col(_c) {}
00021 };
00022 
00023 inline int col(const Cell& c) { 
00024     return c.col; 
00025 }
00026 
00027 inline int row(const Cell& c) { 
00028     return c.row; 
00029 }
00030 
00036 class Grid{
00037     protected:
00038         int rowsize;
00039         int colsize;
00040         int rownum;
00041         int colnum;
00042         vector<int> ** grid;
00043 
00044     public:
00050         Grid(int _rowsize, int _colsize, const vector<cv::KeyPoint>& keypoints) : 
00051             rowsize(_rowsize), colsize(_colsize){
00052                 rownum=PanoramaParams::height / rowsize + 1;
00053                 colnum=PanoramaParams::width / colsize + 1;
00054                 grid = new vector<int>*[rownum];
00055                 for(int i=0; i<rownum;i++){
00056                     grid[i] = new vector<int>[colnum];
00057                 }
00058                 vector<cv::KeyPoint>::const_iterator it = keypoints.begin();
00059                 int i=0;
00060                 while(it!=keypoints.end()){
00061                     Cell cell = getCell(Vector2d(it->pt.x, it->pt.y));
00062                     (grid[row(cell)][col(cell)]).push_back(i);
00063                     ++it;
00064                     i++;
00065                 }
00066             }
00068         Cell getCell(const Vector2d& image_coords) const{
00069             return Cell(image_coords(1) / rowsize, image_coords(0) / colsize);
00070         }
00071 
00073         vector<int> getNearKeypoints(const Cell& cell) const{
00074             return grid[row(cell)][col(cell)];
00075         };
00076 
00077         ~Grid(){
00078             /*for(int i=0; i<rownum;i++){
00079                     delete grid[i];
00080             }
00081             delete grid;*/
00082         }
00083 };
00084 
00095 inline void nonMaximaSuppresion(
00096         const vector<cv::KeyPoint>& keypoints, double max_num, vector<int>& supressed_keypoint_idxs){
00097     supressed_keypoint_idxs.clear();
00098     vector<bool> included_idxs = vector<bool>(keypoints.size(), false);
00099     double radius=std::sqrt((PanoImCoord::Params::width * PanoImCoord::Params::height) / (3*max_num));
00100     Grid grid(radius, radius, keypoints);
00101     for(size_t i=0; i<keypoints.size(); i++) {
00102         vector<int> keypoint_idxs = grid.getNearKeypoints(grid.getCell(
00103                 Vector2d(keypoints[i].pt.x, keypoints[i].pt.y)));
00104 
00105         vector<int>::const_iterator it = keypoint_idxs.begin();
00106         double max=-1;
00107         int mr_keypoint_idx;
00108         while(it!=keypoint_idxs.end()){
00109             if(keypoints[*it].response >= max){
00110                 max = keypoints[*it].response;
00111                 mr_keypoint_idx = *it;
00112             }
00113             ++it;
00114         }
00115         if(max != -1 && !included_idxs[mr_keypoint_idx]){
00116             supressed_keypoint_idxs.push_back(mr_keypoint_idx);
00117             included_idxs[mr_keypoint_idx]=true;
00118         }
00119     }
00120 }
00122 } //namespace vslam
00123 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines


pose_estimation
Author(s): Jiri Divis/jiridivis@gmail.com
autogenerated on Wed Mar 27 2013 21:00:12