PointSampler.cpp

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #include "PointSampler.h"
00025 
00026 #include <algorithms/basic/CalculateOptimalScale.h>
00027 #include <algorithms/nona/FitPanorama.h>
00028 #include <algorithms/nona/CenterHorizontally.h>
00029 
00030 namespace HuginBase
00031 {
00032 
00033 bool PointSampler::runAlgorithm()
00034 {
00035     // is this correct? how much progress requierd?
00036     AppBase::ProgressReporter* progRep = 
00037         AppBase::ProgressReporterAdaptor::newProgressReporter(getProgressDisplay(), 2.0); 
00038     
00039     sampleAndExtractPoints(*progRep);
00040     
00041     delete progRep;
00042 
00043     if(hasProgressDisplay())
00044     {
00045         if(getProgressDisplay()->wasCancelled())
00046             cancelAlgorithm();
00047     }
00048 
00049     return wasCancelled();
00050 }
00051 
00052 
00053 
00054 void PointSampler::sampleAndExtractPoints(AppBase::ProgressReporter & progress)
00055 {
00056     PanoramaData& pano = *(o_panorama.getNewCopy()); // don't forget to delete!
00057     std::vector<vigra::FRGBImage*>& images = o_images;
00058     int& nPoints = o_numPoints;
00059     std::vector<vigra_ext::PointPairRGB>& points = o_resultPoints;
00060     
00061     std::vector<vigra::FImage *> lapImgs;
00062     std::vector<vigra::Size2D> origsize;
00063     std::vector<SrcPanoImage> srcDescr;
00064     
00065     // convert to interpolating images
00066     typedef vigra_ext::ImageInterpolator<vigra::FRGBImage::const_traverser, vigra::FRGBImage::ConstAccessor, vigra_ext::interp_cubic> InterpolImg;
00067     std::vector<InterpolImg> interpolImages;
00068     
00069     vigra_ext::interp_cubic interp;
00070     // adjust sizes in panorama
00071     for (unsigned i=0; i < pano.getNrOfImages(); i++)
00072     {
00073         SrcPanoImage simg = pano.getSrcImage(i);
00074         origsize.push_back(simg.getSize());
00075         simg.resize(images[i]->size());
00076         srcDescr.push_back(simg);
00077         pano.setSrcImage(i, simg);
00078         interpolImages.push_back(InterpolImg(srcImageRange(*(images[i])), interp, false));
00079         
00080         vigra::FImage * lap = new vigra::FImage(images[i]->size());
00081         vigra::laplacianOfGaussian(srcImageRange(*(images[i]), vigra::GreenAccessor<vigra::RGBValue<float> >()), destImage(*lap), 1);
00082         lapImgs.push_back(lap);
00083     }
00084     
00085     
00086     // extract the overlapping points.
00087 //    PanoramaOptions opts = pano.getOptions();
00088 //    double scale = CalculateOptimalScale::calcOptimalPanoScale(pano.getSrcImage(0),opts);
00089 //    opts.setWidth(utils::roundi(opts.getWidth()*scale), true);    
00090 //    pano.setOptions(opts);
00091     // center panorama and do fit to get minimum of black/unused space around panorama
00092     CenterHorizontally(pano).run();
00093     PanoramaOptions opts = pano.getOptions();
00094     CalculateFitPanorama fitPano(pano);
00095     fitPano.run();
00096     opts.setHFOV(fitPano.getResultHorizontalFOV());
00097     opts.setHeight(roundi(fitPano.getResultHeight()));
00098     pano.setOptions(opts);
00099     SetWidthOptimal(pano).run();
00100     
00101     // if random points.
00102     // extract random points.
00103     // need to get the maximum gray value here..
00104     
00105     std::vector<std::multimap<double, vigra_ext::PointPairRGB> > radiusHist(10);
00106     
00107     unsigned nGoodPoints = 0;
00108     unsigned nBadPoints = 0;
00109     
00110     
00111     // call the samplePoints method of this class
00112     progress.setMessage("sampling points");
00113     samplePoints(interpolImages,
00114                  lapImgs,
00115                  srcDescr,
00116                  pano.getOptions(),
00117                  1/255.0,
00118                  250/255.0,
00119                  radiusHist,
00120                  nGoodPoints,
00121                  nBadPoints,
00122                  progress);
00123         
00124     // select points with low laplacian of gaussian values.
00125     progress.setMessage("extracting good points");
00126     sampleRadiusUniform(radiusHist, nPoints, points, progress);
00127     
00128     // scale point coordinates to fit into original panorama.
00129     for (size_t i=0; i < points.size(); i++) {
00130         double scaleF1 = origsize[points[i].imgNr1].x / (float) images[points[i].imgNr1]->size().x;
00131         double scaleF2 = origsize[points[i].imgNr2].x / (float) images[points[i].imgNr2]->size().x;
00132         points[i].p1.x = points[i].p1.x * scaleF1;
00133         points[i].p1.y = points[i].p1.y * scaleF1;
00134         points[i].p2.x = points[i].p2.x * scaleF2;
00135         points[i].p2.y = points[i].p2.y * scaleF2;
00136     }
00137 
00138     for (size_t i=0; i < images.size(); i++) {
00139         delete images[i];
00140         delete lapImgs[i];
00141     }
00142     
00143     delete &pano; // deleting the NewCopy
00144 }
00145 
00146 
00147 
00149 void PointSampler::extractPoints(PanoramaData& pano, std::vector<vigra::FRGBImage*> images, int nPoints,
00150                                  bool randomPoints, AppBase::ProgressReporter& progress,
00151                                  std::vector<vigra_ext::PointPairRGB>& points)
00152 {
00153     PointSampler* sampler = (randomPoints)? (PointSampler*) new RandomPointSampler(pano, NULL, images, nPoints)
00154                                           : (PointSampler*) new AllPointSampler(pano, NULL, images, nPoints);
00155     
00156     sampler->sampleAndExtractPoints(progress);
00157     points = sampler->getResultPoints();
00158     
00159     delete sampler;
00160 }
00161 
00162 
00163 }; // namespace
00164 

Generated on 5 Dec 2014 for Hugintrunk by  doxygen 1.4.7