ExtractPoints.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00002 
00030 #include <hugin_basic.h>
00031 
00032 #include <vigra/error.hxx>
00033 #include <vigra/impex.hxx>
00034 
00035 #include <vigra_ext/Pyramid.h>
00036 #include <vigra_ext/impexalpha.hxx>
00037 #include <algorithms/point_sampler/PointSampler.h>
00038 
00039 using namespace std;
00040 using namespace vigra;
00041 using namespace vigra_ext;
00042 using namespace AppBase;
00043 using namespace HuginBase;
00044 
00045 template<class ImageType>
00046 std::vector<ImageType *> loadImagesPyr(std::vector<std::string> files, int pyrLevel, int verbose)
00047 {
00048     typedef typename ImageType::value_type PixelType;
00049     std::vector<ImageType *> srcImgs(files.size());
00050 #ifdef _WINDOWS
00051     // init vigra codec manager before threaded section
00052     // otherwise there could be sometimes race conditions
00053     // which results in exceptions
00054     std::string s = vigra::impexListExtensions();
00055 #endif
00056 #pragma omp parallel for schedule(dynamic)
00057     for (int i=0; i < files.size(); i++) {
00058         ImageType * tImg = new ImageType();
00059         ImageType * tImg2 = new ImageType();
00060         std::ostringstream buf;
00061         vigra::ImageImportInfo info(files[i].c_str());
00062         tImg->resize(info.size());
00063         if (verbose)
00064             buf << "loading: " << files[i] << std::endl;
00065         
00066         if (info.numExtraBands() == 1) {
00067             // dummy mask
00068             vigra::BImage mask(info.size());
00069             vigra::importImageAlpha(info, vigra::destImage(*tImg), vigra::destImage(mask));
00070         } else {
00071             vigra::importImage(info, vigra::destImage(*tImg));
00072         }
00073         float div = 1;
00074         if (strcmp(info.getPixelType(), "UINT8") == 0) {
00075             div = 255;
00076         } else if (strcmp(info.getPixelType(), "UINT16") == 0) {
00077             div = (1<<16)-1;
00078         }
00079         
00080         if (pyrLevel) {
00081             ImageType * swap;
00082             // create downscaled image
00083             if (verbose > 0) {
00084                 buf << "downscaling: ";
00085             }
00086             for (int l=pyrLevel; l > 0; l--) {
00087                 if (verbose > 0) {
00088                     buf << tImg->size().x << "x" << tImg->size().y << "  " << std::flush;
00089                 }
00090                 reduceToNextLevel(*tImg, *tImg2);
00091                 swap = tImg;
00092                 tImg = tImg2;
00093                 tImg2 = swap;
00094             }
00095             if (verbose > 0)
00096                 buf << std::endl;
00097         }
00098         if (div > 1) {
00099             div = 1/div;
00100             transformImage(vigra::srcImageRange(*tImg), vigra::destImage(*tImg),
00101                            vigra::functor::Arg1()*vigra::functor::Param(div));
00102         }
00103         srcImgs[i]=tImg;
00104         delete tImg2;
00105         if (verbose > 0)
00106         {
00107             std::cout << buf.str();
00108         };
00109     }
00110     return srcImgs;
00111 }
00112 
00113 
00114 // needs 2.0 progress steps
00115 void loadImgsAndExtractPoints(Panorama pano, int nPoints, int pyrLevel, bool randomPoints, AppBase::ProgressDisplay& progress, std::vector<vigra_ext::PointPairRGB> & points, int verbose)
00116 {
00117     // extract file names
00118     std::vector<std::string> files;
00119     for (size_t i=0; i < pano.getNrOfImages(); i++)
00120         files.push_back(pano.getImage(i).getFilename());
00121     
00122     std::vector<vigra::FRGBImage*> images;
00123     
00124     // try to load the images.
00125     images = loadImagesPyr<vigra::FRGBImage>(files, pyrLevel, verbose);
00126     
00127     progress.setMessage("Sampling points");
00128     if(randomPoints)
00129         points = RandomPointSampler(pano, &progress, images, nPoints).execute().getResultPoints();
00130     else
00131         points = AllPointSampler(pano, &progress, images, nPoints).execute().getResultPoints();
00132     progress.taskFinished();
00133 }

Generated on 28 Jul 2015 for Hugintrunk by  doxygen 1.4.7