00001
00002
00030 #include <hugin_basic.h>
00031
00032 #include <vigra/error.hxx>
00033 #include <vigra/impex.hxx>
00034
00035 #include <vigra_ext/ransac.h>
00036 #include <vigra_ext/VigQuotientEstimator.h>
00037 #include <vigra_ext/Pyramid.h>
00038 #include <vigra_ext/Interpolators.h>
00039 #include <vigra_ext/impexalpha.hxx>
00040 #include <algorithms/point_sampler/PointSampler.h>
00041
00042 using namespace std;
00043 using namespace vigra;
00044 using namespace vigra_ext;
00045 using namespace AppBase;
00046 using namespace HuginBase;
00047
00048 template<class ImageType>
00049 std::vector<ImageType *> loadImagesPyr(std::vector<std::string> files, int pyrLevel, int verbose)
00050 {
00051 typedef typename ImageType::value_type PixelType;
00052 std::vector<ImageType *> srcImgs;
00053 for (size_t i=0; i < files.size(); i++) {
00054 ImageType * tImg = new ImageType();
00055 ImageType * tImg2 = new ImageType();
00056 vigra::ImageImportInfo info(files[i].c_str());
00057 tImg->resize(info.size());
00058 if (verbose)
00059 std::cout << "loading: " << files[i] << std::endl;
00060
00061 if (info.numExtraBands() == 1) {
00062
00063 vigra::BImage mask(info.size());
00064 vigra::importImageAlpha(info, vigra::destImage(*tImg), vigra::destImage(mask));
00065 } else {
00066 vigra::importImage(info, vigra::destImage(*tImg));
00067 }
00068 float div = 1;
00069 if (strcmp(info.getPixelType(), "UINT8") == 0) {
00070 div = 255;
00071 } else if (strcmp(info.getPixelType(), "UINT16") == 0) {
00072 div = (1<<16)-1;
00073 }
00074
00075 if (pyrLevel) {
00076 ImageType * swap;
00077
00078 if (verbose > 0) {
00079 std::cout << "downscaling: ";
00080 }
00081 for (int l=pyrLevel; l > 0; l--) {
00082 if (verbose > 0) {
00083 std::cout << tImg->size().x << "x" << tImg->size().y << " " << std::flush;
00084 }
00085 reduceToNextLevel(*tImg, *tImg2);
00086 swap = tImg;
00087 tImg = tImg2;
00088 tImg2 = swap;
00089 }
00090 if (verbose > 0)
00091 std::cout << std::endl;
00092 }
00093 if (div > 1) {
00094 div = 1/div;
00095 transformImage(vigra::srcImageRange(*tImg), vigra::destImage(*tImg),
00096 vigra::functor::Arg1()*vigra::functor::Param(div));
00097 }
00098 srcImgs.push_back(tImg);
00099 delete tImg2;
00100 }
00101 return srcImgs;
00102 }
00103
00104
00105
00106 void loadImgsAndExtractPoints(Panorama pano, int nPoints, int pyrLevel, bool randomPoints, AppBase::ProgressDisplay& progress, std::vector<vigra_ext::PointPairRGB> & points, int verbose)
00107 {
00108
00109 std::vector<std::string> files;
00110 for (size_t i=0; i < pano.getNrOfImages(); i++)
00111 files.push_back(pano.getImage(i).getFilename());
00112
00113 std::vector<vigra::FRGBImage*> images;
00114
00115
00116 images = loadImagesPyr<vigra::FRGBImage>(files, pyrLevel, verbose);
00117
00118 progress.startSubtask("Sampling points",0.0);
00119 if(randomPoints)
00120 points = RandomPointSampler(pano, &progress, images, nPoints).execute().getResultPoints();
00121 else
00122 points = AllPointSampler(pano, &progress, images, nPoints).execute().getResultPoints();
00123 progress.finishSubtask();
00124 }