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

Generated on 3 May 2016 for Hugintrunk by  doxygen 1.4.7