From: <hug...@li...> - 2012-03-18 09:05:55
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgroot/hugin/hugin/rev/344134bcc4a1 changeset: 5747:344134bcc4a1 user: tmodes date: Sun Mar 18 10:04:56 2012 +0100 description: Added option to load distortion and vignetting data from lens database to pto_gen and PTBatcherGUI diffstat: src/hugin1/hugin/xrc/batch_frame.xrc | 20 +++++++++++++ src/hugin1/ptbatcher/FindPanoDialog.cpp | 22 ++++++++++++-- src/hugin1/ptbatcher/FindPanoDialog.h | 4 ++- src/hugin_base/panodata/SrcPanoImage.cpp | 48 ++++++++++++++++++++++++++++++++ src/hugin_base/panodata/SrcPanoImage.h | 8 +++++ src/tools/pto_gen.cpp | 37 ++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 4 deletions(-) diffs (277 lines): diff -r e67ac7f2fba6 -r 344134bcc4a1 src/hugin1/hugin/xrc/batch_frame.xrc --- a/src/hugin1/hugin/xrc/batch_frame.xrc Sun Mar 18 09:05:05 2012 +0100 +++ b/src/hugin1/hugin/xrc/batch_frame.xrc Sun Mar 18 10:04:56 2012 +0100 @@ -200,6 +200,26 @@ <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL</flag> <cellpos>3,1</cellpos> </object> + <object class="sizeritem"> + <object class="wxStaticText"> + <label>Lens database:</label> + </object> + <flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL</flag> + <cellpos>4,0</cellpos> + </object> + <object class="sizeritem"> + <object class="wxCheckBox" name="find_pano_load_distortion"> + <label>Load distortion data</label> + </object> + <flag>wxEXPAND|wxALIGN_CENTRE_VERTICAL</flag> + <cellpos>4,1</cellpos> + </object> + <object class="sizeritem"> + <object class="wxCheckBox" name="find_pano_load_vignetting"> + <label>Load vignetting data</label> + </object> + <cellpos>5,1</cellpos> + </object> <vgap>6</vgap> <hgap>12</hgap> <growablecols>1</growablecols> diff -r e67ac7f2fba6 -r 344134bcc4a1 src/hugin1/ptbatcher/FindPanoDialog.cpp --- a/src/hugin1/ptbatcher/FindPanoDialog.cpp Sun Mar 18 09:05:05 2012 +0100 +++ b/src/hugin1/ptbatcher/FindPanoDialog.cpp Sun Mar 18 10:04:56 2012 +0100 @@ -70,6 +70,8 @@ m_list_pano=XRCCTRL(*this,"find_pano_list",wxCheckListBox); m_ch_naming=XRCCTRL(*this,"find_pano_naming",wxChoice); m_cb_createLinks=XRCCTRL(*this,"find_pano_create_links",wxCheckBox); + m_cb_loadDistortion=XRCCTRL(*this,"find_pano_load_distortion",wxCheckBox); + m_cb_loadVignetting=XRCCTRL(*this,"find_pano_load_vignetting",wxCheckBox); //set parameters wxConfigBase* config = wxConfigBase::Get(); @@ -118,6 +120,10 @@ m_ch_naming->SetSelection(i); config->Read(wxT("/FindPanoDialog/linkStacks"),&val,true); m_cb_createLinks->SetValue(val); + config->Read(wxT("/FindPanoDialog/loadDistortion"),&val,false); + m_cb_loadDistortion->SetValue(val); + config->Read(wxT("/FindPanoDialog/loadVignetting"),&val,false); + m_cb_loadVignetting->SetValue(val); m_button_send->Disable(); }; @@ -142,6 +148,8 @@ config->Write(wxT("/FindPanoDialog/includeSubDirs"),m_cb_subdir->GetValue()); config->Write(wxT("/FindPanoDialog/Naming"),m_ch_naming->GetSelection()); config->Write(wxT("/FindPanoDialog/linkStacks"),m_cb_createLinks->GetValue()); + config->Write(wxT("/FindPanoDialog/loadDistortion"),m_cb_loadDistortion->GetValue()); + config->Write(wxT("/FindPanoDialog/loadVignetting"),m_cb_loadDistortion->GetValue()); CleanUpPanolist(); }; @@ -224,7 +232,7 @@ CleanUpPanolist(); m_list_pano->Clear(); EnableButtons(false); - SearchInDir(m_start_dir,m_cb_subdir->GetValue()); + SearchInDir(m_start_dir,m_cb_subdir->GetValue(), m_cb_loadDistortion->GetValue(), m_cb_loadVignetting->GetValue()); } else { @@ -293,7 +301,7 @@ return doj::alphanum_comp(std::string(s1.mb_str(wxConvLocal)),std::string(s2.mb_str(wxConvLocal))); }; -void FindPanoDialog::SearchInDir(wxString dirstring, bool includeSubdir) +void FindPanoDialog::SearchInDir(wxString dirstring, bool includeSubdir, bool loadDistortion, bool loadVignetting) { std::vector<PossiblePano*> newPanos; wxTimeSpan max_diff(0,0,30,0); //max. 30 s difference between images @@ -318,6 +326,14 @@ if(img->hasEXIFread()) { img->readProjectionFromDB(); + if(loadDistortion) + { + img->readDistortionFromDB(); + }; + if(loadVignetting) + { + img->readVignettingFromDB(); + }; bool found=false; for(unsigned int i=0; i<newPanos.size() && !m_stopped && !found; i++) { @@ -372,7 +388,7 @@ bool cont=dir.GetFirst(&filename,wxEmptyString,wxDIR_DIRS); while(cont && !m_stopped) { - SearchInDir(dir.GetName()+wxFileName::GetPathSeparator()+filename,includeSubdir); + SearchInDir(dir.GetName()+wxFileName::GetPathSeparator()+filename,includeSubdir, loadDistortion, loadVignetting); cont=dir.GetNext(&filename); } }; diff -r e67ac7f2fba6 -r 344134bcc4a1 src/hugin1/ptbatcher/FindPanoDialog.h --- a/src/hugin1/ptbatcher/FindPanoDialog.h Sun Mar 18 09:05:05 2012 +0100 +++ b/src/hugin1/ptbatcher/FindPanoDialog.h Sun Mar 18 10:04:56 2012 +0100 @@ -79,6 +79,8 @@ wxCheckListBox* m_list_pano; wxChoice* m_ch_naming; wxCheckBox* m_cb_createLinks; + wxCheckBox* m_cb_loadDistortion; + wxCheckBox* m_cb_loadVignetting; std::vector<PossiblePano*> m_panos; wxString m_start_dir; @@ -87,7 +89,7 @@ TIFFErrorHandler m_oldtiffwarning; void EnableButtons(const bool state); - void SearchInDir(wxString dirstring,bool includeSubdir); + void SearchInDir(wxString dirstring,bool includeSubdir, bool loadDistortion, bool loadVignetting); void CleanUpPanolist(); DECLARE_EVENT_TABLE() }; diff -r e67ac7f2fba6 -r 344134bcc4a1 src/hugin_base/panodata/SrcPanoImage.cpp --- a/src/hugin_base/panodata/SrcPanoImage.cpp Sun Mar 18 09:05:05 2012 +0100 +++ b/src/hugin_base/panodata/SrcPanoImage.cpp Sun Mar 18 10:04:56 2012 +0100 @@ -724,6 +724,54 @@ return success; }; +bool SrcPanoImage::readDistortionFromDB() +{ + bool success=false; + if(!getExifLens().empty() || (!getExifMake().empty() && !getExifModel().empty())) + { + LensDB::LensDB& lensDB=LensDB::LensDB::GetSingleton(); + if(lensDB.FindLens(getExifMake(), getExifModel(), getExifLens())) + { + if(getExifFocalLength()>0) + { + std::vector<double> dist; + if(lensDB.GetDistortion(getExifFocalLength(),dist)) + { + if(dist.size()==3) + { + dist.push_back(1.0-dist[0]-dist[1]-dist[2]); + setRadialDistortion(dist); + success=true; + }; + }; + }; + }; + }; + return success; +}; + +bool SrcPanoImage::readVignettingFromDB() +{ + bool success=false; + if(!getExifLens().empty() || (!getExifMake().empty() && !getExifModel().empty())) + { + LensDB::LensDB& lensDB=LensDB::LensDB::GetSingleton(); + if(lensDB.FindLens(getExifMake(), getExifModel(), getExifLens())) + { + if(getExifFocalLength()>0) + { + std::vector<double> vig; + if(lensDB.GetVignetting(getExifFocalLength(),getExifAperture(),getExifDistance(),vig)) + { + setRadialVigCorrCoeff(vig); + success=true; + }; + }; + }; + }; + return success; +}; + double SrcPanoImage::calcHFOV(SrcPanoImage::Projection proj, double fl, double crop, vigra::Size2D imageSize) { // calculate diagonal of film diff -r e67ac7f2fba6 -r 344134bcc4a1 src/hugin_base/panodata/SrcPanoImage.h --- a/src/hugin_base/panodata/SrcPanoImage.h Sun Mar 18 09:05:05 2012 +0100 +++ b/src/hugin_base/panodata/SrcPanoImage.h Sun Mar 18 10:04:56 2012 +0100 @@ -391,6 +391,14 @@ you need to call SrcPanoImage::readEXIF before to fill some values @return true, if information could be read from database */ bool readProjectionFromDB(); + /** tries to read distortion data from lensfun database + you need to call SrcPanoImage::readEXIF before to fill some values + @return true, if information could be read from database */ + bool readDistortionFromDB(); + /** tries to read vignetting data from lensfun database + you need to call SrcPanoImage::readEXIF before to fill some values + @return true, if information could be read from database */ + bool readVignettingFromDB(); /** returns true, if image has masks associated */ bool hasMasks() const; diff -r e67ac7f2fba6 -r 344134bcc4a1 src/tools/pto_gen.cpp --- a/src/tools/pto_gen.cpp Sun Mar 18 09:05:05 2012 +0100 +++ b/src/tools/pto_gen.cpp Sun Mar 18 10:04:56 2012 +0100 @@ -57,6 +57,10 @@ << " -s, --stacklength=INT Number of images in stack" << endl << " (default: 1, no stacks)" << endl << " -l, --linkstacks Link image positions in stacks" << endl + << " --distortion Try to load distortion information from" + << " lensfun database" << endl + << " --vignetting Try to load vignetting information from" + << " lensfun database" << endl << " -h, --help Shows this help" << endl << endl; } @@ -98,7 +102,10 @@ {"crop", required_argument, NULL, 'c' }, {"stacklength", required_argument, NULL, 's' }, {"linkstacks", no_argument, NULL, 'l' }, + {"distortion", no_argument, NULL, 300 }, + {"vignetting", no_argument, NULL, 301 }, {"help", no_argument, NULL, 'h' }, + 0 }; @@ -110,6 +117,8 @@ int stackLength=1; bool linkStacks=false; vigra::Rect2D cropRect(0,0,0,0); + bool loadDistortion=false; + bool loadVignetting=false; while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1) { switch (c) @@ -178,6 +187,12 @@ case 'l': linkStacks=true; break; + case 300: + loadDistortion=true; + break; + case 301: + loadVignetting=true; + break; case ':': cerr <<"Option " << longOptions[optionIndex].name << " requires a number" << endl; return 1; @@ -324,6 +339,28 @@ cerr << "ERROR: caught exception: " << e.what() << std::endl; cerr << "Could not get pixel type for file " << filelist[i] << std::endl; }; + if(loadDistortion) + { + if(srcImage.readDistortionFromDB()) + { + cout << "\tRead distortion data from lensfun database." << endl; + } + else + { + cout << "\tNo valid distortion data found in lensfun database." << endl; + }; + }; + if(loadVignetting) + { + if(srcImage.readVignettingFromDB()) + { + cout << "\tRead vignetting data from lensfun database." << endl; + } + else + { + cout << "\tNo valid vignetting data found in lensfun database." << endl; + }; + }; pano.addImage(srcImage); }; |