unsigned int optimize(PanoramaData& pano, const char * userScript) { char * script = 0; unsigned int retval = 0; if (userScript == 0) { std::ostringstream scriptbuf; UIntSet allImg; fill_set(allImg,0, unsigned(pano.getNrOfImages()-1)); pano.printPanoramaScript(scriptbuf, pano.getOptimizeVector(), pano.getOptions(), allImg, true); script = strdup(scriptbuf.str().c_str()); } else { script = const_cast<char *>(userScript); } OptInfo opt; AlignInfo ainf; if (ParseScript( script, &ainf ) == 0) { if( CheckParams( &ainf ) == 0 ) { ainf.fcn = fcnPano; SetGlobalPtr( &ainf ); opt.numVars = ainf.numParam; opt.numData = ainf.numPts; opt.SetVarsToX = SetLMParams; opt.SetXToVars = SetAlignParams; opt.fcn = ainf.fcn; *opt.message = 0; RunLMOptimizer( &opt ); ainf.data = opt.message; // get results from align info. #ifdef DEBUG_WRITE_OPTIM_OUTPUT fullPath path; StringtoFullPath(&path, DEBUG_WRITE_OPTIM_OUTPUT_FILE ); ainf.data = opt.message; WriteResults( script, &path, &ainf, distSquared, 0); #endif pano.updateVariables( GetAlignInfoVariables(ainf) ); pano.updateCtrlPointErrors( GetAlignInfoCtrlPoints(ainf) ); } else { std::cerr << "Bad params" << std::endl; retval = 2; } DisposeAlignInfo( &ainf ); } else { std::cerr << "Bad params" << std::endl; retval = 1; } if (! userScript) { free(script); } return retval; }
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; };
/** run control point detector on selected images, and add control points */ void ImagesPanel::CPGenerate(wxCommandEvent & e) { HuginBase::UIntSet selImg = m_images_tree->GetSelectedImages(); //if only one image is selected, run detector on all images, except for linefind wxString progName = cpdetector_config.settings[m_CPDetectorChoice->GetSelection()].GetProg().Lower(); if ((selImg.size() == 0) || (selImg.size() == 1 && progName.Find(wxT("linefind")) == wxNOT_FOUND)) { // add all images. selImg.clear(); fill_set(selImg, 0, m_pano->getNrOfImages() - 1); } if (selImg.empty()) { return; } RunCPGenerator(cpdetector_config.settings[m_CPDetectorChoice->GetSelection()], selImg); };
int main(int argc, char * argv[]) { struct cmd_options opts = parse_cmd_options(argc, argv); FILE * fin = fopen(opts.infname, "r"); handle_fopen_error(fin, argv[0], "error opening input file"); FILE * fout = fopen(opts.outfname, "w"); handle_fopen_error(fout, argv[0], "error opening output file"); int64_t orig_width = 0, orig_height = 0; size_t entriesn = get_orig_dimensions(&orig_width, &orig_height, fin); fseek(fin, 0, SEEK_SET); struct point_set set = {}; set.ratio.x = get_ratio(opts.width, orig_width); set.ratio.y = get_ratio(opts.height, orig_height); size_t alloc_size = MAX(set.ratio.x, set.ratio.y) * entriesn; set.vec = calloc(alloc_size, sizeof *set.vec); if (set.vec == NULL) { fprintf(stderr, "%s: not enough memory\n", argv[0]); return EXIT_FAILURE; } fill_set(&set, fin); fclose(fin); for (size_t i = 0; i < set.size; i++) { fprintf(fout, "%.100Lg %.100Lg\n", set.vec[i].x, set.vec[i].y); } // kernel will take a better care of this: // free(set.vec); // free(opts.infname); // free(opts.outfname); // fclose(fout); // so don't mind the valgrind "leaks" return EXIT_SUCCESS; }
void calcCtrlPointErrors (PanoramaData& pano) { if(pano.getNrOfImages()>0 && pano.getNrOfCtrlPoints()>0) { char * p=setlocale(LC_ALL,NULL); #ifndef ANDROID char * oldlocale=strdup(p); #else char * oldlocale=""; #endif setlocale(LC_ALL,"C"); UIntSet allImg; std::ostringstream scriptbuf; fill_set(allImg,0, unsigned(pano.getNrOfImages()-1)); //create temporary non-empty optimize vector OptimizeVector optVec; std::set<std::string> opt; opt.insert("y"); for(unsigned int i=0;i<pano.getNrOfImages();i++) { optVec.push_back(opt); }; pano.printPanoramaScript(scriptbuf, optVec, pano.getOptions(), allImg, true); char * script = 0; script = strdup(scriptbuf.str().c_str()); AlignInfo ainf; if (ParseScript( script, &ainf ) == 0) { if( CheckParams( &ainf ) == 0 ) { ainf.fcn = fcnPano; SetGlobalPtr( &ainf ); pano.updateCtrlPointErrors( GetAlignInfoCtrlPoints(ainf) ); } } setlocale(LC_ALL,oldlocale); free(oldlocale); }; }