refactored opencv_stitching

This commit is contained in:
Alexey Spizhevoy 2011-08-16 12:36:11 +00:00
parent f1e8b43c7a
commit 78bb392088
6 changed files with 39 additions and 77 deletions

View File

@ -5,27 +5,14 @@ using namespace std;
using namespace cv;
CameraInfo CameraInfo::load(const string &path)
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; }
const CameraParams& CameraParams::operator =(const CameraParams &other)
{
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;
}
void CameraInfo::save(const string &path)
{
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;
}

View File

@ -45,14 +45,15 @@
#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__

View File

@ -49,21 +49,6 @@ using namespace std;
using namespace cv;
//////////////////////////////////////////////////////////////////////////////
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; }
const CameraParams& CameraParams::operator =(const CameraParams &other)
{
focal = other.focal;
R = other.R.clone();
t = other.t.clone();
return *this;
}
//////////////////////////////////////////////////////////////////////////////
struct IncDistance
@ -434,7 +419,7 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
const int num_images = static_cast<int>(pathes.size());
set<pair<int,int> > span_tree_edges;
DjSets comps(num_images);
DisjointSets comps(num_images);
for (int i = 0; i < num_images; ++i)
{
@ -442,11 +427,11 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
{
if (pairwise_matches[i*num_images + j].confidence < conf_threshold)
continue;
int comp1 = comps.find(i);
int comp2 = comps.find(j);
int comp1 = comps.findSetByElem(i);
int comp2 = comps.findSetByElem(j);
if (comp1 != comp2)
{
comps.merge(comp1, comp2);
comps.mergeSets(comp1, comp2);
span_tree_edges.insert(make_pair(i, j));
}
}
@ -478,7 +463,7 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
for (size_t i = 0; i < comps.size.size(); ++i)
{
if (comps.size[comps.find(i)] == 1)
if (comps.size[comps.findSetByElem(i)] == 1)
{
string name = pathes[i];
size_t prefix_len = name.find_last_of("/\\");
@ -497,17 +482,17 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
{
const int num_images = static_cast<int>(features.size());
DjSets comps(num_images);
DisjointSets comps(num_images);
for (int i = 0; i < num_images; ++i)
{
for (int j = 0; j < num_images; ++j)
{
if (pairwise_matches[i*num_images + j].confidence < conf_threshold)
continue;
int comp1 = comps.find(i);
int comp2 = comps.find(j);
int comp1 = comps.findSetByElem(i);
int comp2 = comps.findSetByElem(j);
if (comp1 != comp2)
comps.merge(comp1, comp2);
comps.mergeSets(comp1, comp2);
}
}
@ -516,7 +501,7 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
vector<int> indices;
vector<int> indices_removed;
for (int i = 0; i < num_images; ++i)
if (comps.find(i) == max_comp)
if (comps.findSetByElem(i) == max_comp)
indices.push_back(i);
else
indices_removed.push_back(i);
@ -569,7 +554,7 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
}
}
DjSets comps(num_images);
DisjointSets comps(num_images);
span_tree.create(num_images);
vector<int> span_tree_powers(num_images, 0);
@ -577,11 +562,11 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
sort(edges.begin(), edges.end(), greater<GraphEdge>());
for (size_t i = 0; i < edges.size(); ++i)
{
int comp1 = comps.find(edges[i].from);
int comp2 = comps.find(edges[i].to);
int comp1 = comps.findSetByElem(edges[i].from);
int comp2 = comps.findSetByElem(edges[i].to);
if (comp1 != comp2)
{
comps.merge(comp1, comp2);
comps.mergeSets(comp1, comp2);
span_tree.addEdge(edges[i].from, edges[i].to, edges[i].weight);
span_tree.addEdge(edges[i].to, edges[i].from, edges[i].weight);
span_tree_powers[edges[i].from]++;

View File

@ -45,18 +45,7 @@
#include "precomp.hpp"
#include "matchers.hpp"
#include "util.hpp"
struct CameraParams
{
CameraParams();
CameraParams(const CameraParams& other);
const CameraParams& operator =(const CameraParams& other);
double focal; // Focal length
cv::Mat R; // Rotation
cv::Mat t; // Translation
};
#include "camera.hpp"
class Estimator
{

View File

@ -44,7 +44,7 @@
using namespace std;
using namespace cv;
void DjSets::create(int n)
void DisjointSets::createOneElemSets(int n)
{
rank_.assign(n, 0);
size.assign(n, 1);
@ -54,7 +54,7 @@ void DjSets::create(int n)
}
int DjSets::find(int elem)
int DisjointSets::findSetByElem(int elem)
{
int set = elem;
while (set != parent[set])
@ -70,7 +70,7 @@ int DjSets::find(int elem)
}
int DjSets::merge(int set1, int set2)
int DisjointSets::mergeSets(int set1, int set2)
{
if (rank_[set1] < rank_[set2])
{

View File

@ -57,14 +57,14 @@
#define LOGLN(msg) LOG(msg << std::endl)
class DjSets
class DisjointSets
{
public:
DjSets(int n = 0) { create(n); }
DisjointSets(int elem_count = 0) { createOneElemSets(elem_count); }
void create(int n);
int find(int elem);
int merge(int set1, int set2);
void createOneElemSets(int elem_count);
int findSetByElem(int elem);
int mergeSets(int set1, int set2);
std::vector<int> parent;
std::vector<int> size;