Commits

Anonymous committed 98f974a Merge

Merge branch 'master' of bitbucket.org:davll/vfx

  • Participants
  • Parent commits 1c415fb, ceb9cbb

Comments (0)

Files changed (9)

File project2/photomerge/source-1/GaussianFilter.cpp

   {
     inline float gaussianWeight(float x, float sigma)
     {
-      float pi = 3.14159265358979;
+      float pi = 3.14159265358979f;
       float s2 = sigma * sigma;
-      float rsq = 1.0 / ( std::sqrt(pi + pi) * sigma );
+      float rsq = 1.0f / ( std::sqrt(pi + pi) * sigma );
       return rsq * std::exp( - (x * x) / (s2 + s2) );
     }
   }
     : m_Sigma(_sigma), m_Kernel(NULL), m_KernelSize(0)
   {
     int khs = 0;
-    while(gaussianWeight(khs, _sigma) >= 0.001)
+    while(gaussianWeight((float)khs, _sigma) >= 0.001f)
       khs = khs + 1;
     
     m_KernelSize = 2 * khs + 1;
     float sum = 0.0;
     for(int i = 0; i < m_KernelSize; ++i)
     {
-      float w = gaussianWeight( i - khs , _sigma);
+      float w = gaussianWeight( float(i - khs) , _sigma);
       m_Kernel[i] = w, sum += w;
     }
     

File project2/photomerge/source-1/ImageData.h

     ptr->refcount = 1;
     ptr->width = w;
     ptr->height = h;
-    ptr->row = row;
+    ptr->row = (int)row;
     
     // Make sure the data is aligned
     ptr->offset = 0 + align - offsetof(ImageData<T>, bytes) % align;

File project2/photomerge/source-1/ImagePixel.h

   
   inline Byte pixelY(float c)
   {
-    return ( c * 255 );
+    return static_cast<Byte>( c * 255 );
   }
   
   inline Byte pixelA(PixARGB c)

File project2/photomerge/source-1/alignment.cpp

       const int w = sourceImages[i].width();
       const int h = sourceImages[i].height();
       
-      float bound[4][2] = { { 0, 0 }, { w, 0 }, { w, h }, { 0, h } };
+      float bound[4][2] = { 
+        { 0, 0 }, { (float)w, 0 }, 
+        { (float)w, (float)h }, { 0, (float)h } 
+      };
       
       float s = std::sin(th[i]), c = std::cos(th[i]);
       float rot[2][2] = { { c, s }, { -s, c } };
         {
           float vx = rot[0][0] * (x-tx[i]) + rot[0][1] * (y-ty[i]);
           float vy = rot[1][0] * (x-tx[i]) + rot[1][1] * (y-ty[i]);
-          int ix = vx, iy = vy;
+          int ix = (int)vx, iy = (int)vy;
           
           if( ix >= 0 && iy >= 0&& ix < w && iy < h )
             pDst[(x-x_min)+(y-y_min)*rd] = pSrc[ ix + iy * rs ];

File project2/photomerge/source-1/feature.cpp

   
   const int FEATURE_RANSAC_SAMPLES = 2;
   const float FEATURE_RANSAC_THRESHOLD = 9.0f;
-  const float FEATURE_RANSAC_SUCESSS_PROBABILITY = 0.99;
-  const float FEATURE_RANSAC_INLIER_PROBABILITY = 0.6;
+  const float FEATURE_RANSAC_SUCESSS_PROBABILITY = 0.99f;
+  const float FEATURE_RANSAC_INLIER_PROBABILITY = 0.6f;
   
   struct Features
   {
           if(pLv[x] == 255)
             continue;
           
-          const float sc = std::pow(0.5, levels - pLv[x] - 1);
+          const float sc = 1.0f / float( 1 << (levels - pLv[x] - 1) );
           const float *py_d = pyramid[pLv[x]].data();
           const int py_row = pyramid[pLv[x]].row();
           const float px = x * sc, py = y * sc;
           
           // Emit Feature Point
           featureLv.push_back(pLv[x]);
-          featureX.push_back(x);
-          featureY.push_back(y);
+          featureX.push_back((float)x);
+          featureY.push_back((float)y);
           featureOri.push_back(pOr[x]);
           for(int i = 0; i < FEATURE_DESC_SIZE; ++i)
             featureDesc[i].push_back(desc[i]);
     
     // Finalize
     feats.levels = levels;
-    feats.count = featureLv.size();
+    feats.count = (int)featureLv.size();
     feats.level.assign( featureLv.begin(), featureLv.end() );
     feats.orient.assign( featureOri.begin(), featureOri.end() );
     feats.x.assign( featureX.begin(), featureX.end() );
       
       int lv = *itL;
       
-      int x = *itX, y = *itY, sc = feats.levels - lv - 1;
+      int x = (int)*itX, y = (int)*itY, sc = feats.levels - lv - 1;
       
       int siz = FEATURE_DESC_WINDOW_SIZE / 2;
       float cor[4][2] = {
           data.y2.push_back( feats[second].y[f2] );
         }
         
-        data.count = data.x1.size();
+        data.count = (int)data.x1.size();
         
         matchList.push_back(data);
       }
   }
   
   std::vector<ImageMatchingPair> 
-  featureDetectionAndMatching(int numImages, const ColorImage* images,
-                              bool dump)
+  featureDetectionAndMatching(int numImages, const ColorImage* images)
   {
     std::vector<Features> features(numImages);
     
       std::printf("Image %d: %d features.\n", i, (int)features[i].count);
     }
     
-    if(dump)
-      for(int i = 0; i < numImages; ++i)
-      {
-        char buf[128];
-        std::sprintf(buf, "feature-%d.jpg", i);
-        outputFeatureMap(buf, images[i], features[i]);
-      }
+    //if(dump)
+    //  for(int i = 0; i < numImages; ++i)
+    //  {
+    //    char buf[128];
+    //    std::sprintf(buf, "feature-%d.jpg", i);
+    //    outputFeatureMap(buf, images[i], features[i]);
+    //  }
     
     // ANN matching
     std::vector<ImageMatchingPair> pairs = matchFeatures(features, 2);
     
+    return pairs;
+  }
+
+  void featureRANSAC(std::vector<ImageMatchingPair>& matches)
+  {
     // RANSAC
-    for(std::vector<ImageMatchingPair>::iterator it = pairs.begin();
-        it != pairs.end(); ++it )
+    for(std::vector<ImageMatchingPair>::iterator it = matches.begin();
+        it != matches.end(); ++it )
     {
       non_ransac(*it);
     }
     
     // Sort Matching List
-    std::sort(pairs.begin(), pairs.end(), _comparator);
+    std::sort(matches.begin(), matches.end(), _comparator);
     
     // Remove Invalid Matching
-    for(int i = pairs.size()-1; i >= 0; --i)
+    for(int i = (int)matches.size()-1; i >= 0; --i)
     {
-      if(pairs[i].count <= FEATURE_RANSAC_SAMPLES)
-        pairs.pop_back();
+      if(matches[i].count <= FEATURE_RANSAC_SAMPLES)
+        matches.pop_back();
     }
-    
-    if(dump)
+  }
+
+  void outputFeatureResult(int numImages, const ColorImage* images, 
+                           const std::vector<ImageMatchingPair>& matches)
+  {
+    int n = (int)matches.size();
+    for(int i = 0; i < n; ++i)
     {
-      int n = pairs.size();
-      for(int i = 0; i < n; ++i)
-      {
-        const int id0 = pairs[i].first, id1 = pairs[i].second;
-        const int w0 = images[id0].width(), h0 = images[id0].height();
-        const int w1 = images[id1].width(), h1 = images[id1].height();
-        const int tw = std::max(w0, w1);
-        const int th = h0 + h1;
+      const int id0 = matches[i].first, id1 = matches[i].second;
+      const int w0 = images[id0].width(), h0 = images[id0].height();
+      const int w1 = images[id1].width(), h1 = images[id1].height();
+      const int tw = std::max(w0, w1);
+      const int th = h0 + h1;
         
-        ColorImage tmp = ImageCreator::createColorImage(tw, th);
+      ColorImage tmp = ImageCreator::createColorImage(tw, th);
         
-        for(int y = 0; y < h0; ++y)
-        {
-          const PixARGB* pSrc0 = images[id0].data() + y * images[id0].row();
-          PixARGB* pDst = tmp.data() + y * tmp.row();
+      for(int y = 0; y < h0; ++y)
+      {
+        const PixARGB* pSrc0 = images[id0].data() + y * images[id0].row();
+        PixARGB* pDst = tmp.data() + y * tmp.row();
           
-          for(int x = 0; x < w0; ++x)
-            pDst[x] = pSrc0[x];
-        }
+        for(int x = 0; x < w0; ++x)
+          pDst[x] = pSrc0[x];
+      }
         
-        for(int y = 0; y < h1; ++y)
-        {
-          const PixARGB* pSrc1 = images[id1].data() + y * images[id1].row();
-          PixARGB* pDst = tmp.data() + (y+h0) * tmp.row();
+      for(int y = 0; y < h1; ++y)
+      {
+        const PixARGB* pSrc1 = images[id1].data() + y * images[id1].row();
+        PixARGB* pDst = tmp.data() + (y+h0) * tmp.row();
           
-          for(int x = 0; x < w0; ++x)
-            pDst[x] = pSrc1[x];
-        }
+        for(int x = 0; x < w0; ++x)
+          pDst[x] = pSrc1[x];
+      }
         
-        for(int k = 0; k < pairs[i].count; ++k)
-        {
-          int x0 = pairs[i].x1[k];
-          int y0 = pairs[i].y1[k];
-          int x1 = pairs[i].x2[k];
-          int y1 = h0 + pairs[i].y2[k];
+      for(int k = 0; k < matches[i].count; ++k)
+      {
+        int x0 = (int)matches[i].x1[k];
+        int y0 = (int)matches[i].y1[k];
+        int x1 = (int)matches[i].x2[k];
+        int y1 = h0 + (int)matches[i].y2[k];
           
-          ImageTool::line(tmp, x0, y0, x1, y1, 0xff0000);
-        }
-        
-        char buf[128];
-        std::sprintf(buf, "matching-%d-%d.jpg", id0, id1);
-        ImageCreator::saveToJpeg(buf, tmp);
+        ImageTool::line(tmp, x0, y0, x1, y1, 0xff0000);
       }
+        
+      char buf[128];
+      std::sprintf(buf, "matching-%d-%d.jpg", id0, id1);
+      ImageCreator::saveToJpeg(buf, tmp);
     }
-    
-    return pairs;
   }
   
 }

File project2/photomerge/source-1/feature.h

     // Translation (relative to first)
     float tx;
     float ty;
+    float th; // theta
   };
   
   std::vector<ImageMatchingPair> 
-  featureDetectionAndMatching(int numImages, const ColorImage* images, 
-                              bool dump);
+  featureDetectionAndMatching(int numImages, const ColorImage* images);
   
+  void featureRANSAC(std::vector<ImageMatchingPair>& matches);
+  
+  void outputFeatureResult(int numImages, const ColorImage* images, 
+                           const std::vector<ImageMatchingPair>& matches);
+
 }

File project2/photomerge/source-1/main.cpp

   };
 #endif
   
-#if 1
+#if 0
   ColorImage imgs[] = {
     ImageCreator::loadFromJpeg("../images/_grail/input/grail00.jpg"),
     ImageCreator::loadFromJpeg("../images/_grail/input/grail01.jpg"),
   };
 #endif
   
+#if 0
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8709.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8710.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8711.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8712.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8713.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8714.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8715.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8716.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8717.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8718.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8719.JPG")
+  };
+#endif
+
+#if 0
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/dk_1/DSCN1557.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_1/DSCN1558.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_1/DSCN1559.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_1/DSCN1560.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_1/DSCN1561.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_1/DSCN1562.JPG")
+  };
+#endif
+
+#if 0
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/dk_2/DSCN1566.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_2/DSCN1567.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_2/DSCN1568.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_2/DSCN1569.JPG")
+  };
+#endif
+
+#if 0
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1571.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1572.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1573.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1575.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1576.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1577.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1578.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1579.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1580.JPG")
+  };
+#endif
+
 #if 1
-  
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1571.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1572.JPG"),
+    ImageCreator::loadFromJpeg("../images/dk_3/DSCN1573.JPG")
+  };
 #endif
   
+#if 0
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030467.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030468.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030469.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030470.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030471.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030472.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030473.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030474.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030475.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030476.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030477.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030478.JPG")
+  };
+#endif
+
+#if 0
+  ColorImage imgs[] = {
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030467.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030468.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030469.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030470.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030471.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030472.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030473.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030474.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030475.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030476.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030477.JPG"),
+    ImageCreator::loadFromJpeg("../images/_lake/input/P1030478.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8709.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8710.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8711.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8712.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8713.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8714.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8715.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8716.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8717.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8718.JPG"),
+    ImageCreator::loadFromJpeg("../images/_csie/input/IMG_8719.JPG")
+  };
+#endif
+
   int num = sizeof(imgs)/sizeof(imgs[0]);
-  auto matches = featureDetectionAndMatching(num, imgs, true);
+  auto matches = featureDetectionAndMatching(num, imgs);
   
+  featureRANSAC(matches);
+
   auto result = produceResult(num, imgs, matches);
   
   ImageCreator::saveToJpeg("result.jpg", result);

File project2/photomerge/source-1/warping.cpp

+#include "warping.h"
+
+#include <cmath>
+
+namespace vfx
+{
+  
+  const float FILM_WIDTH = 36.0f; // mm
+
+  void cylindrical_warp(int numImages, 
+                        ColorImage* images, 
+                        const std::vector<float>& focalLengthes)
+  {
+    //std::vector<float> theta0(numImages);
+    //for(int i = 0; i < numImages; ++i)
+    //  theta0[i] = std::atan2(FILM_WIDTH * 0.5f, focalLengthes[i]);
+    
+    for(int i = 0; i < numImages; ++i)
+    {
+      const int w = images[i].width(), h = images[i].height();
+      float f = focalLengthes[i] * images[i].width() / FILM_WIDTH;
+      float xc1 = images[i].width() * 0.5f;
+      float yc1 = images[i].height() * 0.5f;
+      
+      ColorImage dst = ImageCreator::createColorImage(w, h);
+
+    }
+
+  }
+
+}

File project2/photomerge/source-1/warping.h

+#pragma once
+
+#include "Image.h"
+#include "feature.h"
+
+namespace vfx
+{
+
+}