int iCPApp::OnRun() { ReadDetectorConfig(); //read input project HuginBase::PanoramaMemento newPano; int ptoVersion = 0; wxFileName file(m_input); file.MakeAbsolute(); std::ifstream in((const char *)file.GetFullPath().mb_str(HUGIN_CONV_FILENAME)); if(!in.good()) { std::cerr << "could not open script : " << file.GetFullPath().char_str() << std::endl; return 1; } if(!newPano.loadPTScript(in, ptoVersion,(std::string)file.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR).mb_str(HUGIN_CONV_FILENAME))) { std::cerr << "could not parse script: " << file.GetFullPath().char_str() << std::endl; return 1; }; pano.setMemento(newPano); //match images AutoCtrlPointCreator matcher; HuginBase::UIntSet imgs; fill_set(imgs,0, pano.getNrOfImages()-1); //deactivate libpano messages PT_setProgressFcn(ptProgress); PT_setInfoDlgFcn(ptinfoDlg); HuginBase::CPVector cps = matcher.automatch(m_cpsetting,pano,imgs,m_matches,NULL); PT_setProgressFcn(NULL); PT_setInfoDlgFcn(NULL); if(cps.size()==0) { return 1; }; for(unsigned i=0;i<cps.size();i++) { pano.addCtrlPoint(cps[i]); }; //write output HuginBase::OptimizeVector optvec = pano.getOptimizeVector(); std::ofstream of((const char *)m_output.mb_str(HUGIN_CONV_FILENAME)); wxFileName outputFile(m_output); outputFile.MakeAbsolute(); std::string prefix(outputFile.GetPath(wxPATH_GET_SEPARATOR | wxPATH_GET_VOLUME).char_str()); pano.printPanoramaScript(of, optvec, pano.getOptions(), imgs, false, prefix); std::cout << std::endl << "Written output to " << m_output.char_str() << std::endl; return 0; };
void ImagesPanel::RunCPGenerator(CPDetectorSetting &setting, const HuginBase::UIntSet& img) { wxConfigBase* config=wxConfigBase::Get(); long nFeatures = HUGIN_ASS_NCONTROLPOINTS; #if wxCHECK_VERSION(2,9,4) if(wxGetKeyState(WXK_COMMAND)) #else if(wxGetKeyState(WXK_CONTROL)) #endif { nFeatures = config->Read(wxT("/MainFrame/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS); nFeatures = wxGetNumberFromUser( _("Enter maximal number of control points per image pair"), _("Points per Overlap"), _("Control point detector option"), nFeatures, 1, 10000 ); if(nFeatures<1) { return; }; config->Write(wxT("/MainFrame/nControlPoints"), nFeatures); } else { nFeatures = config->Read(wxT("/Assistant/nControlPoints"), HUGIN_ASS_NCONTROLPOINTS); }; AutoCtrlPointCreator matcher; HuginBase::CPVector cps = matcher.automatch(setting, *m_pano, img, nFeatures, this); wxString msg; wxMessageBox(wxString::Format(_("Added %lu control points"), (unsigned long) cps.size()), _("Control point detector result"),wxOK|wxICON_INFORMATION,this); PanoCommand::GlobalCmdHist::getInstance().addCommand( new PanoCommand::AddCtrlPointsCmd(*m_pano, cps) ); };
int main(int argc, char* argv[]) { // parse arguments const char* optstring = "o:i:l:h"; static struct option longOptions[] = { {"output", required_argument, NULL, 'o' }, {"image", required_argument, NULL, 'i' }, {"lines", required_argument, NULL, 'l' }, {"help", no_argument, NULL, 'h' }, 0 }; UIntSet cmdlineImages; int c; int optionIndex = 0; int nrLines = 5; string output; while ((c = getopt_long (argc, argv, optstring, longOptions,&optionIndex)) != -1) { switch (c) { case 'o': output = optarg; break; case 'h': usage(argv[0]); return 0; case 'i': { int imgNr=atoi(optarg); if((imgNr==0) && (strcmp(optarg,"0")!=0)) { cerr << "Could not parse image number."; return 1; }; cmdlineImages.insert(imgNr); }; break; case 'l': nrLines=atoi(optarg); if(nrLines<1) { cerr << "Could not parse number of lines."; return 1; }; break; case ':': cerr <<"Option " << longOptions[optionIndex].name << " requires a number" << endl; return 1; break; case '?': break; default: abort (); } } if (argc - optind != 1) { cout << "Warning: " << argv[0] << " can only work on one project file at one time" << endl << endl; usage(argv[0]); return 1; }; string input=argv[optind]; // read panorama Panorama pano; ifstream prjfile(input.c_str()); if (!prjfile.good()) { cerr << "could not open script : " << input << endl; return 1; } pano.setFilePrefix(hugin_utils::getPathPrefix(input)); DocumentData::ReadWriteError err = pano.readData(prjfile); if (err != DocumentData::SUCCESSFUL) { cerr << "error while parsing panos tool script: " << input << endl; cerr << "DocumentData::ReadWriteError code: " << err << endl; return 1; } if(pano.getNrOfImages()==0) { cerr << "error: project file does not contains any image" << endl; cerr << "aborting processing" << endl; return 1; }; std::vector<size_t> imagesToProcess; if(cmdlineImages.size()==0) { //no image given, process all for(size_t i=0;i<pano.getNrOfImages();i++) { imagesToProcess.push_back(i); }; } else { //check, if given image numbers are valid for(UIntSet::const_iterator it=cmdlineImages.begin();it!=cmdlineImages.end();it++) { if((*it)>=0 && (*it)<pano.getNrOfImages()) { imagesToProcess.push_back(*it); }; }; }; if(imagesToProcess.size()==0) { cerr << "No image to process found" << endl << "Stopping processing" << endl; return 1; }; PT_setProgressFcn(ptProgress); PT_setInfoDlgFcn(ptinfoDlg); cout << argv[0] << " is searching for vertical lines" << endl; #if _WINDOWS //multi threading of image loading results sometime in a race condition //try to prevent this by initialisation of codecManager before //running multi threading part std::string s=vigra::impexListExtensions(); #endif #ifdef HAS_PPL size_t nrCPS=pano.getNrOfCtrlPoints(); Concurrency::parallel_for<size_t>(0,imagesToProcess.size(),[&pano,imagesToProcess,nrLines](size_t i) #else for(size_t i=0;i<imagesToProcess.size();i++) #endif { unsigned int imgNr=imagesToProcess[i]; cout << "Working on image " << pano.getImage(imgNr).getFilename() << endl; // now load and process all images vigra::ImageImportInfo info(pano.getImage(imgNr).getFilename().c_str()); HuginBase::CPVector foundLines; if(info.isGrayscale()) { foundLines=LoadGrayImageAndFindLines(info, pano, imgNr, nrLines); } else { if(info.isColor()) { //colour images foundLines=LoadImageAndFindLines(info, pano, imgNr, nrLines); } else { std::cerr << "Image " << pano.getImage(imgNr).getFilename().c_str() << " has " << info.numBands() << " channels." << std::endl << "Linefind works only with grayscale or color images." << std::endl << "Skipping image." << std::endl; }; }; #ifndef HAS_PPL cout << "Found " << foundLines.size() << " vertical lines" << endl; #endif if(foundLines.size()>0) { for(CPVector::const_iterator cpIt=foundLines.begin(); cpIt!=foundLines.end(); cpIt++) { pano.addCtrlPoint(*cpIt); }; }; } #ifdef HAS_PPL );
CommandQueue* GetAssistantCommandQueue(const HuginBase::Panorama & pano, const wxString& ExePath, const wxString& project) { CommandQueue* commands=new CommandQueue(); wxString quotedProject(wxEscapeFilename(project)); //read main settings wxConfigBase* config = wxConfigBase::Get(); const bool runCeleste = config->Read(wxT("/Celeste/Auto"), HUGIN_CELESTE_AUTO) != 0; double celesteThreshold; config->Read(wxT("/Celeste/Threshold"), &celesteThreshold, HUGIN_CELESTE_THRESHOLD); const bool celesteSmallRadius = config->Read(wxT("/Celeste/Filter"), HUGIN_CELESTE_FILTER) == 0; const bool runLinefind = config->Read(wxT("/Assistant/Linefind"), HUGIN_ASS_LINEFIND) != 0; const bool runCPClean = config->Read(wxT("/Assistant/AutoCPClean"), HUGIN_ASS_AUTO_CPCLEAN) != 0; double scale; config->Read(wxT("/Assistant/panoDownsizeFactor"), &scale, HUGIN_ASS_PANO_DOWNSIZE_FACTOR); bool runicp = (pano.getNrOfCtrlPoints() == 0); if (!runicp) { //we check, if all images are connected //if not, we run also icpfind HuginGraph::ImageGraph graph(pano); runicp = !graph.IsConnected(); }; //build commandline for icpfind if (runicp) { //create cp find commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("icpfind")), wxT("-o ") + quotedProject + wxT(" ") + quotedProject, _("Searching for control points..."))); //building celeste command if (runCeleste) { wxString args; args << wxT("-t ") << wxStringFromCDouble(celesteThreshold) << wxT(" "); if (celesteSmallRadius) { args.Append(wxT("-r 1 ")); } args.Append(wxT("-o ") + quotedProject + wxT(" ") + quotedProject); commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("celeste_standalone")), args, _("Removing control points in clouds..."))); }; //building cpclean command if (runCPClean) { commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("cpclean")), wxT("-o ") + quotedProject + wxT(" ") + quotedProject, _("Statistically cleaning of control points..."))); }; }; //vertical line detector if (runLinefind) { const HuginBase::CPVector allCP = pano.getCtrlPoints(); bool hasVerticalLines = false; if (allCP.size() > 0) { for (size_t i = 0; i < allCP.size() && !hasVerticalLines; i++) { hasVerticalLines = (allCP[i].mode == HuginBase::ControlPoint::X); }; }; if (!hasVerticalLines) { commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("linefind")), wxT("--output=") + quotedProject + wxT(" ") + quotedProject, _("Searching for vertical lines..."))); }; }; //now optimise all commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("checkpto")), quotedProject)); commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("autooptimiser")), wxT("-a -m -l -s -o ") + quotedProject + wxT(" ") + quotedProject, _("Optimizing..."))); wxString panoModifyArgs; // if necessary scale down final pano if (scale <= 1.0) { panoModifyArgs << wxT("--canvas=") << hugin_utils::roundi(scale * 100) << wxT("% "); }; panoModifyArgs.Append(wxT("--crop=AUTO --output=") + quotedProject + wxT(" ") + quotedProject); commands->push_back(new NormalCommand(GetInternalProgram(ExePath, wxT("pano_modify")), panoModifyArgs, _("Searching for best crop..."))); return commands; };