From: <hug...@li...> - 2012-06-26 19:51:36
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgroot/hugin/hugin/rev/034758d1e78e changeset: 5878:034758d1e78e user: tmodes date: Mon Jun 11 17:49:52 2012 +0200 description: cpfind: Add pair wise matching to multirow heuristic if multirow was not successful diffstat: src/hugin_cpfind/cpfind/PanoDetector.cpp | 208 ++++++++++++++++-------------- src/hugin_cpfind/cpfind/PanoDetector.h | 6 +- 2 files changed, 113 insertions(+), 101 deletions(-) diffs (279 lines): diff -r a60692352f59 -r 034758d1e78e src/hugin_cpfind/cpfind/PanoDetector.cpp --- a/src/hugin_cpfind/cpfind/PanoDetector.cpp Thu May 31 18:58:52 2012 +0200 +++ b/src/hugin_cpfind/cpfind/PanoDetector.cpp Mon Jun 11 17:49:52 2012 +0200 @@ -579,9 +579,12 @@ { case ALLPAIRS: case LINEAR: - if(!match(aExecutor)) { - return; + std::vector<HuginBase::UIntSet> imgPairs(_panoramaInfo->getNrOfImages()); + if(!match(aExecutor, imgPairs)) + { + return; + }; }; break; case MULTIROW: @@ -645,12 +648,48 @@ }; } -bool PanoDetector::match(PoolExecutor& aExecutor) +bool PanoDetector::match(PoolExecutor& aExecutor, std::vector<HuginBase::UIntSet> &checkedPairs) { // 3. prepare matches - prepareMatches(); + _matchesData.clear(); + unsigned int aLen = _filesData.size(); + if (getMatchingStrategy()==LINEAR) + { + aLen = _linearMatchLen; + } + + if (aLen >= _filesData.size()) + { + aLen = _filesData.size() - 1; + } + + for (unsigned int i1 = 0; i1 < _filesData.size(); ++i1) + { + unsigned int aEnd = i1 + 1 + aLen; + if (_filesData.size() < aEnd) + { + aEnd = _filesData.size(); + } + + for (unsigned int i2 = (i1+1); i2 < aEnd; ++i2) + { + if(set_contains(checkedPairs[i1], i2)) + { + continue; + }; + // create a new entry in the matches map + _matchesData.push_back(MatchData()); + + MatchData& aM = _matchesData.back(); + aM._i1 = &(_filesData[i1]); + aM._i2 = &(_filesData[i2]); + + checkedPairs[i1].insert(i2); + checkedPairs[i2].insert(i1); + } + } // 4. find matches - TRACE_INFO(endl<< "--- Find matches ---" << endl); + TRACE_INFO(endl<< "--- Find pair-wise matches ---" << endl); try { BOOST_FOREACH(MatchData& aMD, _matchesData) @@ -844,39 +883,6 @@ }; }; -void PanoDetector::prepareMatches() -{ - unsigned int aLen = _filesData.size(); - if (getMatchingStrategy()==LINEAR) - { - aLen = _linearMatchLen; - } - - if (aLen >= _filesData.size()) - { - aLen = _filesData.size() - 1; - } - - for (unsigned int i1 = 0; i1 < _filesData.size(); ++i1) - { - unsigned int aEnd = i1 + 1 + aLen; - if (_filesData.size() < aEnd) - { - aEnd = _filesData.size(); - } - - for (unsigned int i2 = (i1+1); i2 < aEnd; ++i2) - { - // create a new entry in the matches map - _matchesData.push_back(MatchData()); - - MatchData& aM = _matchesData.back(); - aM._i1 = &(_filesData[i1]); - aM._i2 = &(_filesData[i2]); - } - } -} - struct img_ev { unsigned int img_nr; @@ -1046,74 +1052,84 @@ // step 3: now connect all overlapping images _matchesData.clear(); createCPGraph(*_panoramaInfo,graph); - if(findCPComponents(graph, comps)==1 && images_layer.size()>2) + if(findCPComponents(graph, comps)==1) { - PT::Panorama optPano=_panoramaInfo->getSubset(images_layer_set); - //next steps happens only when all images are connected; - //now optimize panorama - PanoramaOptions opts = _panoramaInfo->getOptions(); - opts.setProjection(PanoramaOptions::EQUIRECTANGULAR); - opts.optimizeReferenceImage=0; - // calculate proper scaling, 1:1 resolution. - // Otherwise optimizer distances are meaningless. - opts.setWidth(30000, false); - opts.setHeight(15000); + if(images_layer.size()>2) + { + PT::Panorama optPano=_panoramaInfo->getSubset(images_layer_set); + //next steps happens only when all images are connected; + //now optimize panorama + PanoramaOptions opts = _panoramaInfo->getOptions(); + opts.setProjection(PanoramaOptions::EQUIRECTANGULAR); + opts.optimizeReferenceImage=0; + // calculate proper scaling, 1:1 resolution. + // Otherwise optimizer distances are meaningless. + opts.setWidth(30000, false); + opts.setHeight(15000); - optPano.setOptions(opts); - int w = optPano.calcOptimalWidth(); - opts.setWidth(w); - opts.setHeight(w/2); - optPano.setOptions(opts); + optPano.setOptions(opts); + int w = optPano.calcOptimalWidth(); + opts.setWidth(w); + opts.setHeight(w/2); + optPano.setOptions(opts); - //generate optimize vector, optimize only yaw and pitch - OptimizeVector optvars; - const SrcPanoImage& anchorImage = optPano.getImage(opts.optimizeReferenceImage); - for (unsigned i=0; i < optPano.getNrOfImages(); i++) - { - std::set<std::string> imgopt; - if(i==opts.optimizeReferenceImage) + //generate optimize vector, optimize only yaw and pitch + OptimizeVector optvars; + const SrcPanoImage& anchorImage = optPano.getImage(opts.optimizeReferenceImage); + for (unsigned i=0; i < optPano.getNrOfImages(); i++) { - //optimize only anchors pitch, not yaw - imgopt.insert("p"); + std::set<std::string> imgopt; + if(i==opts.optimizeReferenceImage) + { + //optimize only anchors pitch, not yaw + imgopt.insert("p"); + } + else + { + imgopt.insert("p"); + imgopt.insert("y"); + }; + optvars.push_back(imgopt); } - else + optPano.setOptimizeVector(optvars); + + // remove vertical and horizontal control points + CPVector cps = optPano.getCtrlPoints(); + CPVector newCP; + for (CPVector::const_iterator it = cps.begin(); it != cps.end(); it++) { - imgopt.insert("p"); - imgopt.insert("y"); + if (it->mode == ControlPoint::X_Y) + { + newCP.push_back(*it); + } + } + optPano.setCtrlPoints(newCP); + + if (getVerbose() < 2) + { + PT_setProgressFcn(ptProgress); + PT_setInfoDlgFcn(ptinfoDlg); }; - optvars.push_back(imgopt); - } - optPano.setOptimizeVector(optvars); + //in a first step do a pairwise optimisation + HuginBase::AutoOptimise::autoOptimise(optPano, false); + //now the final optimisation + HuginBase::PTools::optimize(optPano); + if (getVerbose() < 2) + { + PT_setProgressFcn(NULL); + PT_setInfoDlgFcn(NULL); + }; - // remove vertical and horizontal control points - CPVector cps = optPano.getCtrlPoints(); - CPVector newCP; - for (CPVector::const_iterator it = cps.begin(); it != cps.end(); it++) - { - if (it->mode == ControlPoint::X_Y) + //now match overlapping images + if(!matchPrealigned(aExecutor, &optPano, checkedImagePairs, images_layer)) { - newCP.push_back(*it); - } - } - optPano.setCtrlPoints(newCP); - - if (getVerbose() < 2) - { - PT_setProgressFcn(ptProgress); - PT_setInfoDlgFcn(ptinfoDlg); + return false; + }; }; - //in a first step do a pairwise optimisation - HuginBase::AutoOptimise::autoOptimise(optPano, false); - //now the final optimisation - HuginBase::PTools::optimize(optPano); - if (getVerbose() < 2) - { - PT_setProgressFcn(NULL); - PT_setInfoDlgFcn(NULL); - }; - - //now match overlapping images - if(!matchPrealigned(aExecutor, &optPano, checkedImagePairs, images_layer)) + } + else + { + if(!match(aExecutor, checkedImagePairs)) { return false; }; diff -r a60692352f59 -r 034758d1e78e src/hugin_cpfind/cpfind/PanoDetector.h --- a/src/hugin_cpfind/cpfind/PanoDetector.h Thu May 31 18:58:52 2012 +0200 +++ b/src/hugin_cpfind/cpfind/PanoDetector.h Mon Jun 11 17:49:52 2012 +0200 @@ -73,7 +73,7 @@ void printFilenames(); void printHelp(); void run(); - bool match(ZThread::PoolExecutor& aExecutor); + bool match(ZThread::PoolExecutor& aExecutor, std::vector<HuginBase::UIntSet> &checkedPairs); bool matchMultiRow(ZThread::PoolExecutor& aExecutor); /** does only matches image pairs which overlaps and don't have control points @param aExecutor executor for threading @@ -375,13 +375,9 @@ Panorama* _panoramaInfo; Panorama _panoramaInfoCopy; - // void prepareImages(); bool loadProject(); - // void loadImages(); - // void remapBackMatches(); bool checkLoadSuccess(); void CleanupKeyfiles(); - void prepareMatches(); void writeOutput(); void writeKeyfile(ImgData& imgInfo); |