refactored opencv_stitching
authorAlexey Spizhevoy <no@email>
Tue, 16 Aug 2011 12:36:11 +0000 (12:36 +0000)
committerAlexey Spizhevoy <no@email>
Tue, 16 Aug 2011 12:36:11 +0000 (12:36 +0000)
modules/stitching/camera.cpp
modules/stitching/camera.hpp
modules/stitching/motion_estimators.cpp
modules/stitching/motion_estimators.hpp
modules/stitching/util.cpp
modules/stitching/util.hpp

index a81776a..3c295e7 100644 (file)
@@ -5,27 +5,14 @@ using namespace std;
 using namespace cv;
 
 
-CameraInfo CameraInfo::load(const string &path)
-{
-    FileStorage fs(path, FileStorage::READ);
-    CV_Assert(fs.isOpened());
-
-    CameraInfo cam;
-    if (!fs["R"].isNone())
-        fs["R"] >> cam.R;
-    if (!fs["K"].isNone())
-        fs["K"] >> cam.K;
-    return cam;
-}
+CameraParams::CameraParams() : focal(1), R(Mat::eye(3, 3, CV_64F)), t(Mat::zeros(3, 1, CV_64F)) {}
 
+CameraParams::CameraParams(const CameraParams &other) { *this = other; }
 
-void CameraInfo::save(const string &path)
+const CameraParams& CameraParams::operator =(const CameraParams &other)
 {
-    FileStorage fs(path, FileStorage::WRITE);
-    CV_Assert(fs.isOpened());
-
-    if (!R.empty())
-        fs << "R" << R;
-    if (!K.empty())
-        fs << "K" << K;
+    focal = other.focal;
+    R = other.R.clone();
+    t = other.t.clone();
+    return *this;
 }
index 9d18a60..15ce898 100644 (file)
 #include "precomp.hpp"
 
 
-class CameraInfo
+struct CameraParams
 {
-public:
-    static CameraInfo load(const std::string &path);
-    void save(const std::string &path);
+    CameraParams();
+    CameraParams(const CameraParams& other);
+    const CameraParams& operator =(const CameraParams& other);
 
-    cv::Mat R;
-    cv::Mat K;
+    double focal; // Focal length
+    cv::Mat R; // Rotation
+    cv::Mat t; // Translation
 };
 
 #endif // #ifndef __OPENCV_CAMERA_HPP__
index 8387bd8..40e70ed 100644 (file)
@@ -51,21 +51,6 @@ using namespace cv;
 \r
 //////////////////////////////////////////////////////////////////////////////\r
 \r
-CameraParams::CameraParams() : focal(1), R(Mat::eye(3, 3, CV_64F)), t(Mat::zeros(3, 1, CV_64F)) {}\r
-\r
-CameraParams::CameraParams(const CameraParams &other) { *this = other; }\r
-\r
-const CameraParams& CameraParams::operator =(const CameraParams &other)\r
-{\r
-    focal = other.focal;\r
-    R = other.R.clone();\r
-    t = other.t.clone();\r
-    return *this;\r
-}\r
-\r
-\r
-//////////////////////////////////////////////////////////////////////////////\r
-\r
 struct IncDistance\r
 {\r
     IncDistance(vector<int> &dists) : dists(&dists[0]) {}\r
@@ -434,7 +419,7 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
 \r
     const int num_images = static_cast<int>(pathes.size());\r
     set<pair<int,int> > span_tree_edges;\r
-    DjSets comps(num_images);\r
+    DisjointSets comps(num_images);\r
 \r
     for (int i = 0; i < num_images; ++i)\r
     {\r
@@ -442,11 +427,11 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
         {\r
             if (pairwise_matches[i*num_images + j].confidence < conf_threshold)\r
                 continue;\r
-            int comp1 = comps.find(i);\r
-            int comp2 = comps.find(j);\r
+            int comp1 = comps.findSetByElem(i);\r
+            int comp2 = comps.findSetByElem(j);\r
             if (comp1 != comp2)\r
             {\r
-                comps.merge(comp1, comp2);\r
+                comps.mergeSets(comp1, comp2);\r
                 span_tree_edges.insert(make_pair(i, j));\r
             }\r
         }\r
@@ -478,7 +463,7 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
 \r
     for (size_t i = 0; i < comps.size.size(); ++i)\r
     {\r
-        if (comps.size[comps.find(i)] == 1)\r
+        if (comps.size[comps.findSetByElem(i)] == 1)\r
         {\r
             string name = pathes[i];\r
             size_t prefix_len = name.find_last_of("/\\");\r
@@ -497,17 +482,17 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features,  vector<Match
 {\r
     const int num_images = static_cast<int>(features.size());\r
 \r
-    DjSets comps(num_images);\r
+    DisjointSets comps(num_images);\r
     for (int i = 0; i < num_images; ++i)\r
     {\r
         for (int j = 0; j < num_images; ++j)\r
         {\r
             if (pairwise_matches[i*num_images + j].confidence < conf_threshold)\r
                 continue;\r
-            int comp1 = comps.find(i);\r
-            int comp2 = comps.find(j);\r
+            int comp1 = comps.findSetByElem(i);\r
+            int comp2 = comps.findSetByElem(j);\r
             if (comp1 != comp2) \r
-                comps.merge(comp1, comp2);\r
+                comps.mergeSets(comp1, comp2);\r
         }\r
     }\r
 \r
@@ -516,7 +501,7 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features,  vector<Match
     vector<int> indices;\r
     vector<int> indices_removed;\r
     for (int i = 0; i < num_images; ++i)\r
-        if (comps.find(i) == max_comp)\r
+        if (comps.findSetByElem(i) == max_comp)\r
             indices.push_back(i);    \r
         else\r
             indices_removed.push_back(i);\r
@@ -569,7 +554,7 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
         }\r
     }\r
 \r
-    DjSets comps(num_images);\r
+    DisjointSets comps(num_images);\r
     span_tree.create(num_images);\r
     vector<int> span_tree_powers(num_images, 0);\r
 \r
@@ -577,11 +562,11 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
     sort(edges.begin(), edges.end(), greater<GraphEdge>());\r
     for (size_t i = 0; i < edges.size(); ++i)\r
     {\r
-        int comp1 = comps.find(edges[i].from);\r
-        int comp2 = comps.find(edges[i].to);\r
+        int comp1 = comps.findSetByElem(edges[i].from);\r
+        int comp2 = comps.findSetByElem(edges[i].to);\r
         if (comp1 != comp2)\r
         {\r
-            comps.merge(comp1, comp2);\r
+            comps.mergeSets(comp1, comp2);\r
             span_tree.addEdge(edges[i].from, edges[i].to, edges[i].weight);\r
             span_tree.addEdge(edges[i].to, edges[i].from, edges[i].weight);\r
             span_tree_powers[edges[i].from]++;\r
index bb121b5..4618563 100644 (file)
 #include "precomp.hpp"\r
 #include "matchers.hpp"\r
 #include "util.hpp"\r
-\r
-struct CameraParams\r
-{\r
-    CameraParams();\r
-    CameraParams(const CameraParams& other);\r
-    const CameraParams& operator =(const CameraParams& other);\r
-\r
-    double focal; // Focal length\r
-    cv::Mat R; // Rotation\r
-    cv::Mat t; // Translation\r
-};\r
-\r
+#include "camera.hpp"\r
 \r
 class Estimator\r
 {\r
index 6cba9e3..9020271 100644 (file)
@@ -44,7 +44,7 @@
 using namespace std;\r
 using namespace cv;\r
 \r
-void DjSets::create(int n) \r
+void DisjointSets::createOneElemSets(int n)\r
 {\r
     rank_.assign(n, 0);\r
     size.assign(n, 1);\r
@@ -54,7 +54,7 @@ void DjSets::create(int n)
 }\r
 \r
 \r
-int DjSets::find(int elem) \r
+int DisjointSets::findSetByElem(int elem)\r
 {\r
     int set = elem;\r
     while (set != parent[set])\r
@@ -70,7 +70,7 @@ int DjSets::find(int elem)
 }\r
 \r
 \r
-int DjSets::merge(int set1, int set2) \r
+int DisjointSets::mergeSets(int set1, int set2)\r
 {\r
     if (rank_[set1] < rank_[set2]) \r
     {\r
index 4c2db0d..265a20b 100644 (file)
 #define LOGLN(msg) LOG(msg << std::endl)\r
 \r
 \r
-class DjSets\r
+class DisjointSets\r
 {\r
 public:\r
-    DjSets(int n = 0) { create(n); }\r
+    DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); }\r
 \r
-    void create(int n);\r
-    int find(int elem);\r
-    int merge(int set1, int set2);\r
+    void createOneElemSets(int elem_count);\r
+    int findSetByElem(int elem);\r
+    int mergeSets(int set1, int set2);\r
 \r
     std::vector<int> parent;\r
     std::vector<int> size;\r