From 13fe5c8a5bf2a5f5c9c138355532126c224bb787 Mon Sep 17 00:00:00 2001 From: asantamaria <asantamaria@iri.upc.edu> Date: Wed, 30 Aug 2017 12:47:58 +0200 Subject: [PATCH] trying to make the active search grid work --- src/CMakeLists.txt | 1 + src/detectors/detector_base.cpp | 39 +++++++++----------- src/detectors/orb/detector_orb.h | 2 +- src/examples/test_algorithm_activesearch.cpp | 24 ++++++------ src/examples/yaml/ACTIVESEARCH.yaml | 10 ++--- 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 494a9a5..c34e454 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -118,6 +118,7 @@ SET(headers algorithms/opticalflowpyrlk/alg_opticalflowpyrlk.h algorithms/activesearch/alg_activesearch.h) + # locate the necessary dependencies FIND_PACKAGE(Eigen3 REQUIRED) FIND_PACKAGE(OpenCV REQUIRED) diff --git a/src/detectors/detector_base.cpp b/src/detectors/detector_base.cpp index 2b32d1e..33d2415 100644 --- a/src/detectors/detector_base.cpp +++ b/src/detectors/detector_base.cpp @@ -30,30 +30,25 @@ KeyPointVector DetectorBase::detect(const cv::Mat& _image, cv::Rect& _roi) { // FIX this KeyPointVector kpts; - if (!_image.empty() && _roi.height > 2*pattern_radius_ && _roi.width > 2*pattern_radius_) + if (!_image.empty()) { cv::Mat _image_roi; - //adaptRoi(getPatternRadius(), _image, _roi, _image_roi); - - std::cout << "radii: " << getPatternRadius() << " ROI: " << _roi.x << " " << _roi.y << " " << _roi.width << " " << _roi.height << std::endl; - - - adaptRoi(100, _image, _roi, _image_roi); - -std::cout << "radii: " << getPatternRadius() << " ROI: " << _roi.x << " " << _roi.y << " " << _roi.width << " " << _roi.height << std::endl; - -//cv::imshow("ACTIVESEARCH algorithm", _image_roi); -//cv::waitKey(1); -// -// sleep(2); - - kpts = detect(_image_roi); - - for (int ii = 0; ii < kpts.size(); ++ii) - { - kpts[ii].pt.x = kpts[ii].pt.x + _roi.x; - kpts[ii].pt.y = kpts[ii].pt.y + _roi.y; - } + adaptRoi(getPatternRadius(), _image, _roi, _image_roi); + + try + { + kpts = detect(_image_roi); + + for (int ii = 0; ii < kpts.size(); ++ii) + { + kpts[ii].pt.x = kpts[ii].pt.x + _roi.x; + kpts[ii].pt.y = kpts[ii].pt.y + _roi.y; + } + } + catch( cv::Exception& e ) + { + std::cerr << "exception caught: " << e.what() << std::endl; + } } return kpts; } diff --git a/src/detectors/orb/detector_orb.h b/src/detectors/orb/detector_orb.h index 94b9090..062e149 100644 --- a/src/detectors/orb/detector_orb.h +++ b/src/detectors/orb/detector_orb.h @@ -63,7 +63,7 @@ inline void DetectorORB::defineDetector(const ParamsBasePtr _params) params_ptr->scoreType, params_ptr->patchSize); - pattern_radius_ = params_ptr->edgeThreshold; + pattern_radius_ = params_ptr->patchSize; } /* diff --git a/src/examples/test_algorithm_activesearch.cpp b/src/examples/test_algorithm_activesearch.cpp index 95035db..43e2d10 100644 --- a/src/examples/test_algorithm_activesearch.cpp +++ b/src/examples/test_algorithm_activesearch.cpp @@ -45,7 +45,7 @@ #include "../algorithms/activesearch/alg_activesearch.h" // TODO: set as user parameters -#define MAX_NEW_FEATURES 100 +#define MAX_NEW_FEATURES 500 #define MIN_FEATURES_TO_TRACK 10 #define MIN_RESPONSE_NEW_FEATURES 80 #define MATCHER_MIN_NORMALIZED_SCORE 0.85 @@ -109,13 +109,13 @@ void detectNewFeatures(cv::Mat& _frame, _active_search_grid_ptr->hitCell(new_keypoints[0]); // Debug - // drawRoi(_frame,roi,_active_search_grid_ptr->getName(),cv::Scalar(50,255,0), 1, 0.1); + drawRoi(_frame,roi,_active_search_grid_ptr->getName(),cv::Scalar(50,255,0), 1, 0.1); } } else { _active_search_grid_ptr->blockCell(roi); - // drawRoi(_frame,roi,_active_search_grid_ptr->getName(),cv::Scalar(255,0,0), 1, 0.1); + drawRoi(_frame,roi,_active_search_grid_ptr->getName(),cv::Scalar(255,0,0), 1, 0.1); } // Debug @@ -367,8 +367,8 @@ int main(void) active_search_grid_ptr->setParams(params_ptr); // Set main ROI areas depending on ACTIVE SEARCH GRID sizes - roi_h_ = params_ptr->img_size_v/params_ptr->n_cells_v; - roi_w_ = params_ptr->img_size_h/params_ptr->n_cells_h; + roi_h_ = params_ptr->img_size_v/(params_ptr->n_cells_v); + roi_w_ = params_ptr->img_size_h/(params_ptr->n_cells_h); std::vector<feature> features_last_frame_vec; @@ -382,16 +382,16 @@ int main(void) // Process std::vector<feature> features_tracked_vec; -// if (features_last_frame_vec.size() < MIN_FEATURES_TO_TRACK) -// { + if (features_last_frame_vec.size() < MIN_FEATURES_TO_TRACK) + { // TODO: When to renew? active_search_grid_ptr->renew(); detectNewFeatures(frame_cur, det_ptr, des_ptr, active_search_grid_ptr, features_tracked_vec); -// } -// else -// { -// trackFeatures(frame_cur, det_ptr, des_ptr, mat_ptr, active_search_grid_ptr, features_last_frame_vec,features_tracked_vec); -// } + } + else + { + trackFeatures(frame_cur, det_ptr, des_ptr, mat_ptr, active_search_grid_ptr, features_last_frame_vec,features_tracked_vec); + } features_last_frame_vec.clear(); features_last_frame_vec = features_tracked_vec; diff --git a/src/examples/yaml/ACTIVESEARCH.yaml b/src/examples/yaml/ACTIVESEARCH.yaml index 8b5804e..49de716 100644 --- a/src/examples/yaml/ACTIVESEARCH.yaml +++ b/src/examples/yaml/ACTIVESEARCH.yaml @@ -8,18 +8,18 @@ detector: nfeatures: 100 scale factor: 2 nlevels: 8 - edge threshold: 8 # 16 + edge threshold: 16 # 16 first level: 0 WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5 score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; - patch size: 15 # 31 + patch size: 31 # 31 descriptor: type: "ORB" nfeatures: 100 scale factor: 2 nlevels: 8 - edge threshold: 8 # 16 + edge threshold: 16 # 16 first level: 0 WTA_K: 2 # See: http://docs.opencv.org/trunk/db/d95/classcv_1_1ORB.html#a180ae17d3300cf2c619aa240d9b607e5 score type: 1 #enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 }; @@ -33,7 +33,7 @@ algorithm: type: "ACTIVESEARCH" img size h: 640 img size v: 480 - grid height: 8 - grid width: 12 + grid height: 10 + grid width: 10 margin: 0 separation: 10 \ No newline at end of file -- GitLab