diff --git a/ASIFT_tests/demo_ASIFT_src/ASIFT_matcher.cpp b/ASIFT_tests/demo_ASIFT_src/ASIFT_matcher.cpp index 425a423..9def179 100644 --- a/ASIFT_tests/demo_ASIFT_src/ASIFT_matcher.cpp +++ b/ASIFT_tests/demo_ASIFT_src/ASIFT_matcher.cpp @@ -308,12 +308,12 @@ bool ASIFT_matcher::match(vector& image, unsigned int w, unsigned int h, return true; } -void ASIFT_matcher::computeROI(int& x, int& y, unsigned int& h, unsigned int& w) const +bool ASIFT_matcher::computeROI(int& x, int& y, unsigned int& h, unsigned int& w) const { if(getNbMatch()==0) { cerr<<"Error : cannot compute ROI without matchs"< upLe, doRi; //UpLeft / DownRight @@ -348,12 +348,117 @@ void ASIFT_matcher::computeROI(int& x, int& y, unsigned int& h, unsigned int& w) h=doRi.second-y; w=doRi.first-x; - // x=zoom*upLe.first; //Système de coordonée ? (devrait etre bon) - // y=zoom*upLe.second; - // h=zoom*(doRi.second-upLe.second); - // w=zoom*(doRi.first-upLe.first); + return true; } +bool ASIFT_matcher::computeCenter(int& cx, int& cy) const +{ + if(getNbMatch()==0) + { + cerr<<"Error : cannot compute Center without matchs"< > kp_euc_dist; + + if(computeCenter(cx,cy)) + { + // cout<<"Center : "< temp_euc_dist; + for(unsigned int j=0;j<_matchings[i].size();j++) + { + keypoint kp = _matchings[i][j].first; + euc_dist =sqrt((kp.x-cx)*(kp.x-cx)+(kp.y-cy)+(kp.y-cy)); + dist_avg+=euc_dist; + temp_euc_dist.push_back(euc_dist); + } + total_kp += _matchings[i].size(); + kp_euc_dist.push_back(temp_euc_dist); + } + dist_avg/=total_kp; + // cout<<"Dist avg: "< filtered_match; + + for(unsigned int i=0;i<_matchings.size();i++) + { + matchingslist new_match; + for(unsigned int j=0;j<_matchings[i].size();j++) + { + euc_dist =kp_euc_dist[i][j]; + + if(euc_dist& image, unsigned int w, unsigned int h, unsigned int num_tilts =1); - void print() const; - void computeROI(int& x, int& y, unsigned int& h, unsigned int& w) const; + void print() const; //Debugging function + bool computeROI(int& x, int& y, unsigned int& h, unsigned int& w) const; //Compute the bounding rectangle of the keypoints + bool computeCenter(int& cx, int& cy) const; + bool distFilter(int threshold); //Filter keypoint which are far (Euclidian distance) from the center. void setResizeImg(bool resize_imgs){ _resize_imgs=resize_imgs;} void showDebug(bool showDebug){ _showDebug=showDebug;} - const vector < unsigned int >& getNbMatchs() const{ return _num_matchings;} unsigned int getNbMatch() const; const vector< matchingslist >& getMatch() const{ return _matchings;} diff --git a/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/ASIFT_matcher.cpp.o b/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/ASIFT_matcher.cpp.o index b3112bd..2610ec8 100644 Binary files a/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/ASIFT_matcher.cpp.o and b/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/ASIFT_matcher.cpp.o differ diff --git a/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/test_ASIFT.cpp.o b/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/test_ASIFT.cpp.o index e6f1cb9..1fa2c24 100644 Binary files a/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/test_ASIFT.cpp.o and b/ASIFT_tests/demo_ASIFT_src/CMakeFiles/test_ASIFT.dir/test_ASIFT.cpp.o differ diff --git a/ASIFT_tests/demo_ASIFT_src/results/res.png b/ASIFT_tests/demo_ASIFT_src/results/res.png index cbcd724..9f4c0cc 100644 Binary files a/ASIFT_tests/demo_ASIFT_src/results/res.png and b/ASIFT_tests/demo_ASIFT_src/results/res.png differ diff --git a/ASIFT_tests/demo_ASIFT_src/test_ASIFT b/ASIFT_tests/demo_ASIFT_src/test_ASIFT index ac2d3fe..33e0f89 100755 Binary files a/ASIFT_tests/demo_ASIFT_src/test_ASIFT and b/ASIFT_tests/demo_ASIFT_src/test_ASIFT differ diff --git a/ASIFT_tests/demo_ASIFT_src/test_ASIFT.cpp b/ASIFT_tests/demo_ASIFT_src/test_ASIFT.cpp index 3d1d76d..ccb6688 100644 --- a/ASIFT_tests/demo_ASIFT_src/test_ASIFT.cpp +++ b/ASIFT_tests/demo_ASIFT_src/test_ASIFT.cpp @@ -2,13 +2,14 @@ int main(int argc, char **argv) { - if ((argc !=2) && (argc != 3) && (argc != 4)) { + if ((argc <2) || (argc > 5)) { std::cerr << " ******************************************************************************* " << std::endl << " *************************** ASIFT image matching **************************** " << std::endl << " ******************************************************************************* " << std::endl - << "Usage: " << argv[0] << " imgIn.png [Tilt number option] [Resize option: 0/1] " << std::endl + << "Usage: " << argv[0] << " imgIn.png [Tilt number option] [Filter option] [Resize option] " << std::endl << "- imgIn.png: input image (in PNG format). " << std::endl - << "- [Tilt number option: 1..(32+ ?)] : 8: Recommended / 1: no tilt. " << std::endl + << "- [Tilt number option: 1..(32+ ?)] : 7: Recommended / 1: no tilt. " << std::endl + << "- [Filter option: 0..3]. Standard deviation filter coeff (1-68%/2-95%/3-99%). 0: no filtering. " << std::endl << "- [Resize option: 0/1]. 1: input images resize to 800x600 (default). 0: no resize. " << std::endl << " ******************************************************************************* " << std::endl << " ********************* Jean-Michel Morel, Guoshen Yu, 2010 ******************** " << std::endl @@ -36,12 +37,12 @@ int main(int argc, char **argv) vector ipixels1_zoom; int flag_resize = 1; - if (argc == 4) + if (argc == 5) { - flag_resize = atoi(argv[3]); + flag_resize = atoi(argv[4]); } - if ((argc==2) || (argc == 3) || (flag_resize != 0)) + if (flag_resize != 0) { cout << "WARNING: The input images is resized to " << wS << "x" << hS << " for ASIFT. " << endl << " But the results will be normalized to the original image size." << endl << endl; @@ -101,24 +102,34 @@ int main(int argc, char **argv) zoom1 = 1; } + std::string refData[] = { "book_training/train_image_000.png", "book_training/train_image_001.png"}; - + ASIFT_matcher matcher; matcher.setResizeImg(flag_resize); time_t tstart, tend; tstart = time(0); - matcher.addReference(refData[0].c_str(), 8); - matcher.addReference(refData[1].c_str(), 8); // matcher.print(); // matcher.match(refData[3].c_str(), 4); if(argc>2) - matcher.match(ipixels1_zoom, wS1, hS1, atoi(argv[2])); + { + matcher.addReference(refData[0].c_str(), atoi(argv[2])); + matcher.addReference(refData[1].c_str(), atoi(argv[2])); + matcher.match(ipixels1_zoom, wS1, hS1, atoi(argv[2])); + } else + { + matcher.addReference(refData[0].c_str(), 7); + matcher.addReference(refData[1].c_str(), 7); matcher.match(ipixels1_zoom, wS1, hS1); + } + + if(argc>3 && atoi(argv[3])>0) + matcher.distFilter(atoi(argv[3])); tend = time(0); @@ -130,17 +141,13 @@ int main(int argc, char **argv) cout<<" "<first.x), (int) (zoom1*ptrH->first.y), point_size, point_size, 255, w1, h1); } } + + //////////////////////////////////////////////////////////////////// Draw ROI + if(matcher.computeROI(x,y,h,w)) + draw_square(opixelsASIFT, zoom1*x, zoom1*y, zoom1*w, zoom1*h, 255, w1, h1); + + //////////////////////////////////////////////////////////////////// Draw Center + if(matcher.computeCenter(cx,cy)) + { + draw_square(opixelsASIFT, zoom1*(cx-6), zoom1*(cy-6), zoom1*12, zoom1*12, 160, w1, h1); + draw_line(opixelsASIFT, zoom1*cx, zoom1*(cy-6), zoom1*cx, zoom1*(cy+6), 255, w1, h1); + draw_line(opixelsASIFT, zoom1*(cx-6), zoom1*cy, zoom1*(cx+6), zoom1*cy, 255, w1, h1); + } + ///////////////////////////////////////////////////////////////// Save imgOut write_png_f32("./results/res.png", opixelsASIFT, w1, h1, 1);