Remove all using directives for STL namespace and members

Made all STL usages explicit to be able automatically find all usages of
particular class or function.
This commit is contained in:
Andrey Kamaev
2013-02-24 20:14:01 +04:00
parent f783f34e0b
commit 2a6fb2867e
310 changed files with 5744 additions and 5964 deletions

View File

@@ -42,7 +42,6 @@
#include "precomp.hpp"
using namespace std;
using namespace cv;
namespace {
@@ -79,8 +78,8 @@ void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, boo
v1 = -(h[0] * h[1] + h[3] * h[4]) / d1;
v2 = (h[0] * h[0] + h[3] * h[3] - h[1] * h[1] - h[4] * h[4]) / d2;
if (v1 < v2) std::swap(v1, v2);
if (v1 > 0 && v2 > 0) f1 = sqrt(std::abs(d1) > std::abs(d2) ? v1 : v2);
else if (v1 > 0) f1 = sqrt(v1);
if (v1 > 0 && v2 > 0) f1 = std::sqrt(std::abs(d1) > std::abs(d2) ? v1 : v2);
else if (v1 > 0) f1 = std::sqrt(v1);
else f1_ok = false;
f0_ok = true;
@@ -89,19 +88,19 @@ void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, boo
v1 = -h[2] * h[5] / d1;
v2 = (h[5] * h[5] - h[2] * h[2]) / d2;
if (v1 < v2) std::swap(v1, v2);
if (v1 > 0 && v2 > 0) f0 = sqrt(std::abs(d1) > std::abs(d2) ? v1 : v2);
else if (v1 > 0) f0 = sqrt(v1);
if (v1 > 0 && v2 > 0) f0 = std::sqrt(std::abs(d1) > std::abs(d2) ? v1 : v2);
else if (v1 > 0) f0 = std::sqrt(v1);
else f0_ok = false;
}
void estimateFocal(const vector<ImageFeatures> &features, const vector<MatchesInfo> &pairwise_matches,
vector<double> &focals)
void estimateFocal(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
std::vector<double> &focals)
{
const int num_images = static_cast<int>(features.size());
focals.resize(num_images);
vector<double> all_focals;
std::vector<double> all_focals;
for (int i = 0; i < num_images; ++i)
{
@@ -114,7 +113,7 @@ void estimateFocal(const vector<ImageFeatures> &features, const vector<MatchesIn
bool f0ok, f1ok;
focalsFromHomography(m.H, f0, f1, f0ok, f1ok);
if (f0ok && f1ok)
all_focals.push_back(sqrt(f0 * f1));
all_focals.push_back(std::sqrt(f0 * f1));
}
}
@@ -143,16 +142,16 @@ void estimateFocal(const vector<ImageFeatures> &features, const vector<MatchesIn
}
bool calibrateRotatingCamera(const vector<Mat> &Hs, Mat &K)
bool calibrateRotatingCamera(const std::vector<Mat> &Hs, Mat &K)
{
int m = static_cast<int>(Hs.size());
CV_Assert(m >= 1);
vector<Mat> Hs_(m);
std::vector<Mat> Hs_(m);
for (int i = 0; i < m; ++i)
{
CV_Assert(Hs[i].size() == Size(3, 3) && Hs[i].type() == CV_64F);
Hs_[i] = Hs[i] / pow(determinant(Hs[i]), 1./3.);
Hs_[i] = Hs[i] / std::pow(determinant(Hs[i]), 1./3.);
}
const int idx_map[3][3] = {{0, 1, 2}, {1, 3, 4}, {2, 4, 5}};

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
using namespace std;
namespace cv {
namespace detail {
@@ -62,7 +60,7 @@ Ptr<Blender> Blender::createDefault(int type, bool try_gpu)
}
void Blender::prepare(const vector<Point> &corners, const vector<Size> &sizes)
void Blender::prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes)
{
prepare(resultRoi(corners, sizes));
}
@@ -155,8 +153,8 @@ void FeatherBlender::blend(Mat &dst, Mat &dst_mask)
}
Rect FeatherBlender::createWeightMaps(const vector<Mat> &masks, const vector<Point> &corners,
vector<Mat> &weight_maps)
Rect FeatherBlender::createWeightMaps(const std::vector<Mat> &masks, const std::vector<Point> &corners,
std::vector<Mat> &weight_maps)
{
weight_maps.resize(masks.size());
for (size_t i = 0; i < masks.size(); ++i)
@@ -178,7 +176,7 @@ Rect FeatherBlender::createWeightMaps(const vector<Mat> &masks, const vector<Poi
Rect roi(corners[i].x - dst_roi.x, corners[i].y - dst_roi.y,
weight_maps[i].cols, weight_maps[i].rows);
Mat tmp = weights_sum(roi);
tmp.setTo(1, tmp < numeric_limits<float>::epsilon());
tmp.setTo(1, tmp < std::numeric_limits<float>::epsilon());
divide(weight_maps[i], tmp, weight_maps[i]);
}
@@ -205,8 +203,8 @@ void MultiBandBlender::prepare(Rect dst_roi)
dst_roi_final_ = dst_roi;
// Crop unnecessary bands
double max_len = static_cast<double>(max(dst_roi.width, dst_roi.height));
num_bands_ = min(actual_num_bands_, static_cast<int>(ceil(log(max_len) / log(2.0))));
double max_len = static_cast<double>(std::max(dst_roi.width, dst_roi.height));
num_bands_ = std::min(actual_num_bands_, static_cast<int>(ceil(std::log(max_len) / std::log(2.0))));
// Add border to the final image, to ensure sizes are divided by (1 << num_bands_)
dst_roi.width += ((1 << num_bands_) - dst_roi.width % (1 << num_bands_)) % (1 << num_bands_);
@@ -240,10 +238,10 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
// Keep source image in memory with small border
int gap = 3 * (1 << num_bands_);
Point tl_new(max(dst_roi_.x, tl.x - gap),
max(dst_roi_.y, tl.y - gap));
Point br_new(min(dst_roi_.br().x, tl.x + img.cols + gap),
min(dst_roi_.br().y, tl.y + img.rows + gap));
Point tl_new(std::max(dst_roi_.x, tl.x - gap),
std::max(dst_roi_.y, tl.y - gap));
Point br_new(std::min(dst_roi_.br().x, tl.x + img.cols + gap),
std::min(dst_roi_.br().y, tl.y + img.rows + gap));
// Ensure coordinates of top-left, bottom-right corners are divided by (1 << num_bands_).
// After that scale between layers is exactly 2.
@@ -258,8 +256,8 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
height += ((1 << num_bands_) - height % (1 << num_bands_)) % (1 << num_bands_);
br_new.x = tl_new.x + width;
br_new.y = tl_new.y + height;
int dy = max(br_new.y - dst_roi_.br().y, 0);
int dx = max(br_new.x - dst_roi_.br().x, 0);
int dy = std::max(br_new.y - dst_roi_.br().y, 0);
int dx = std::max(br_new.x - dst_roi_.br().x, 0);
tl_new.x -= dx; br_new.x -= dx;
tl_new.y -= dy; br_new.y -= dy;
@@ -272,7 +270,7 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
Mat img_with_border;
copyMakeBorder(img, img_with_border, top, bottom, left, right,
BORDER_REFLECT);
vector<Mat> src_pyr_laplace;
std::vector<Mat> src_pyr_laplace;
if (can_use_gpu_ && img_with_border.depth() == CV_16S)
createLaplacePyrGpu(img_with_border, num_bands_, src_pyr_laplace);
else
@@ -280,7 +278,7 @@ void MultiBandBlender::feed(const Mat &img, const Mat &mask, Point tl)
// Create the weight map Gaussian pyramid
Mat weight_map;
vector<Mat> weight_pyr_gauss(num_bands_ + 1);
std::vector<Mat> weight_pyr_gauss(num_bands_ + 1);
if(weight_type_ == CV_32F)
{
@@ -432,7 +430,7 @@ void createWeightMap(const Mat &mask, float sharpness, Mat &weight)
}
void createLaplacePyr(const Mat &img, int num_levels, vector<Mat> &pyr)
void createLaplacePyr(const Mat &img, int num_levels, std::vector<Mat> &pyr)
{
#ifdef HAVE_TEGRA_OPTIMIZATION
if(tegra::createLaplacePyr(img, num_levels, pyr))
@@ -489,12 +487,12 @@ void createLaplacePyr(const Mat &img, int num_levels, vector<Mat> &pyr)
}
void createLaplacePyrGpu(const Mat &img, int num_levels, vector<Mat> &pyr)
void createLaplacePyrGpu(const Mat &img, int num_levels, std::vector<Mat> &pyr)
{
#ifdef HAVE_OPENCV_GPU
pyr.resize(num_levels + 1);
vector<gpu::GpuMat> gpu_pyr(num_levels + 1);
std::vector<gpu::GpuMat> gpu_pyr(num_levels + 1);
gpu_pyr[0].upload(img);
for (int i = 0; i < num_levels; ++i)
gpu::pyrDown(gpu_pyr[i], gpu_pyr[i + 1]);
@@ -516,7 +514,7 @@ void createLaplacePyrGpu(const Mat &img, int num_levels, vector<Mat> &pyr)
}
void restoreImageFromLaplacePyr(vector<Mat> &pyr)
void restoreImageFromLaplacePyr(std::vector<Mat> &pyr)
{
if (pyr.empty())
return;
@@ -529,13 +527,13 @@ void restoreImageFromLaplacePyr(vector<Mat> &pyr)
}
void restoreImageFromLaplacePyrGpu(vector<Mat> &pyr)
void restoreImageFromLaplacePyrGpu(std::vector<Mat> &pyr)
{
#ifdef HAVE_OPENCV_GPU
if (pyr.empty())
return;
vector<gpu::GpuMat> gpu_pyr(pyr.size());
std::vector<gpu::GpuMat> gpu_pyr(pyr.size());
for (size_t i = 0; i < pyr.size(); ++i)
gpu_pyr[i].upload(pyr[i]);

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
using namespace std;
namespace cv {
namespace detail {

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
using namespace std;
namespace cv {
namespace detail {
@@ -60,18 +58,18 @@ Ptr<ExposureCompensator> ExposureCompensator::createDefault(int type)
}
void ExposureCompensator::feed(const vector<Point> &corners, const vector<Mat> &images,
const vector<Mat> &masks)
void ExposureCompensator::feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<Mat> &masks)
{
vector<pair<Mat,uchar> > level_masks;
std::vector<std::pair<Mat,uchar> > level_masks;
for (size_t i = 0; i < masks.size(); ++i)
level_masks.push_back(make_pair(masks[i], 255));
level_masks.push_back(std::make_pair(masks[i], 255));
feed(corners, images, level_masks);
}
void GainCompensator::feed(const vector<Point> &corners, const vector<Mat> &images,
const vector<pair<Mat,uchar> > &masks)
void GainCompensator::feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<std::pair<Mat,uchar> > &masks)
{
LOGLN("Exposure compensation...");
#if ENABLE_LOG
@@ -102,7 +100,7 @@ void GainCompensator::feed(const vector<Point> &corners, const vector<Mat> &imag
submask2 = masks[j].first(Rect(roi.tl() - corners[j], roi.br() - corners[j]));
intersect = (submask1 == masks[i].second) & (submask2 == masks[j].second);
N(i, j) = N(j, i) = max(1, countNonZero(intersect));
N(i, j) = N(j, i) = std::max(1, countNonZero(intersect));
double Isum1 = 0, Isum2 = 0;
for (int y = 0; y < roi.height; ++y)
@@ -113,8 +111,8 @@ void GainCompensator::feed(const vector<Point> &corners, const vector<Mat> &imag
{
if (intersect(y, x))
{
Isum1 += sqrt(static_cast<double>(sqr(r1[x].x) + sqr(r1[x].y) + sqr(r1[x].z)));
Isum2 += sqrt(static_cast<double>(sqr(r2[x].x) + sqr(r2[x].y) + sqr(r2[x].z)));
Isum1 += std::sqrt(static_cast<double>(sqr(r1[x].x) + sqr(r1[x].y) + sqr(r1[x].z)));
Isum2 += std::sqrt(static_cast<double>(sqr(r2[x].x) + sqr(r2[x].y) + sqr(r2[x].z)));
}
}
}
@@ -153,26 +151,26 @@ void GainCompensator::apply(int index, Point /*corner*/, Mat &image, const Mat &
}
vector<double> GainCompensator::gains() const
std::vector<double> GainCompensator::gains() const
{
vector<double> gains_vec(gains_.rows);
std::vector<double> gains_vec(gains_.rows);
for (int i = 0; i < gains_.rows; ++i)
gains_vec[i] = gains_(i, 0);
return gains_vec;
}
void BlocksGainCompensator::feed(const vector<Point> &corners, const vector<Mat> &images,
const vector<pair<Mat,uchar> > &masks)
void BlocksGainCompensator::feed(const std::vector<Point> &corners, const std::vector<Mat> &images,
const std::vector<std::pair<Mat,uchar> > &masks)
{
CV_Assert(corners.size() == images.size() && images.size() == masks.size());
const int num_images = static_cast<int>(images.size());
vector<Size> bl_per_imgs(num_images);
vector<Point> block_corners;
vector<Mat> block_images;
vector<pair<Mat,uchar> > block_masks;
std::vector<Size> bl_per_imgs(num_images);
std::vector<Point> block_corners;
std::vector<Mat> block_images;
std::vector<std::pair<Mat,uchar> > block_masks;
// Construct blocks for gain compensator
for (int img_idx = 0; img_idx < num_images; ++img_idx)
@@ -187,12 +185,12 @@ void BlocksGainCompensator::feed(const vector<Point> &corners, const vector<Mat>
for (int bx = 0; bx < bl_per_img.width; ++bx)
{
Point bl_tl(bx * bl_width, by * bl_height);
Point bl_br(min(bl_tl.x + bl_width, images[img_idx].cols),
min(bl_tl.y + bl_height, images[img_idx].rows));
Point bl_br(std::min(bl_tl.x + bl_width, images[img_idx].cols),
std::min(bl_tl.y + bl_height, images[img_idx].rows));
block_corners.push_back(corners[img_idx] + bl_tl);
block_images.push_back(images[img_idx](Rect(bl_tl, bl_br)));
block_masks.push_back(make_pair(masks[img_idx].first(Rect(bl_tl, bl_br)),
block_masks.push_back(std::make_pair(masks[img_idx].first(Rect(bl_tl, bl_br)),
masks[img_idx].second));
}
}
@@ -200,7 +198,7 @@ void BlocksGainCompensator::feed(const vector<Point> &corners, const vector<Mat>
GainCompensator compensator;
compensator.feed(block_corners, block_images, block_masks);
vector<double> gains = compensator.gains();
std::vector<double> gains = compensator.gains();
gain_maps_.resize(num_images);
Mat_<float> ker(1, 3);

View File

@@ -42,7 +42,6 @@
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::detail;
@@ -72,8 +71,8 @@ struct MatchPairsBody
: matcher(other.matcher), features(other.features),
pairwise_matches(other.pairwise_matches), near_pairs(other.near_pairs) {}
MatchPairsBody(FeaturesMatcher &_matcher, const vector<ImageFeatures> &_features,
vector<MatchesInfo> &_pairwise_matches, vector<pair<int,int> > &_near_pairs)
MatchPairsBody(FeaturesMatcher &_matcher, const std::vector<ImageFeatures> &_features,
std::vector<MatchesInfo> &_pairwise_matches, std::vector<std::pair<int,int> > &_near_pairs)
: matcher(_matcher), features(_features),
pairwise_matches(_pairwise_matches), near_pairs(_near_pairs) {}
@@ -107,9 +106,9 @@ struct MatchPairsBody
}
FeaturesMatcher &matcher;
const vector<ImageFeatures> &features;
vector<MatchesInfo> &pairwise_matches;
vector<pair<int,int> > &near_pairs;
const std::vector<ImageFeatures> &features;
std::vector<MatchesInfo> &pairwise_matches;
std::vector<std::pair<int,int> > &near_pairs;
private:
void operator =(const MatchPairsBody&);
@@ -118,7 +117,7 @@ private:
//////////////////////////////////////////////////////////////////////////////
typedef set<pair<int,int> > MatchesSet;
typedef std::set<std::pair<int,int> > MatchesSet;
// These two classes are aimed to find features matches only, not to
// estimate homography
@@ -146,7 +145,7 @@ private:
float match_conf_;
GpuMat descriptors1_, descriptors2_;
GpuMat train_idx_, distance_, all_dist_;
vector< vector<DMatch> > pair_matches;
std::vector< std::vector<DMatch> > pair_matches;
};
#endif
@@ -173,7 +172,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
}
FlannBasedMatcher matcher(indexParams, searchParams);
vector< vector<DMatch> > pair_matches;
std::vector< std::vector<DMatch> > pair_matches;
MatchesSet matches;
// Find 1->2 matches
@@ -187,7 +186,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
if (m0.distance < (1.f - match_conf_) * m1.distance)
{
matches_info.matches.push_back(m0);
matches.insert(make_pair(m0.queryIdx, m0.trainIdx));
matches.insert(std::make_pair(m0.queryIdx, m0.trainIdx));
}
}
LOG("\n1->2 matches: " << matches_info.matches.size() << endl);
@@ -202,7 +201,7 @@ void CpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
const DMatch& m0 = pair_matches[i][0];
const DMatch& m1 = pair_matches[i][1];
if (m0.distance < (1.f - match_conf_) * m1.distance)
if (matches.find(make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
if (matches.find(std::make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
matches_info.matches.push_back(DMatch(m0.trainIdx, m0.queryIdx, m0.distance));
}
LOG("1->2 & 2->1 matches: " << matches_info.matches.size() << endl);
@@ -235,7 +234,7 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
if (m0.distance < (1.f - match_conf_) * m1.distance)
{
matches_info.matches.push_back(m0);
matches.insert(make_pair(m0.queryIdx, m0.trainIdx));
matches.insert(std::make_pair(m0.queryIdx, m0.trainIdx));
}
}
@@ -250,7 +249,7 @@ void GpuMatcher::match(const ImageFeatures &features1, const ImageFeatures &feat
const DMatch& m0 = pair_matches[i][0];
const DMatch& m1 = pair_matches[i][1];
if (m0.distance < (1.f - match_conf_) * m1.distance)
if (matches.find(make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
if (matches.find(std::make_pair(m0.trainIdx, m0.queryIdx)) == matches.end())
matches_info.matches.push_back(DMatch(m0.trainIdx, m0.queryIdx, m0.distance));
}
}
@@ -262,7 +261,7 @@ void GpuMatcher::collectGarbage()
train_idx_.release();
distance_.release();
all_dist_.release();
vector< vector<DMatch> >().swap(pair_matches);
std::vector< std::vector<DMatch> >().swap(pair_matches);
}
#endif
@@ -279,9 +278,9 @@ void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features)
}
void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features, const vector<Rect> &rois)
void FeaturesFinder::operator ()(const Mat &image, ImageFeatures &features, const std::vector<Rect> &rois)
{
vector<ImageFeatures> roi_features(rois.size());
std::vector<ImageFeatures> roi_features(rois.size());
size_t total_kps_count = 0;
int total_descriptors_height = 0;
@@ -499,7 +498,7 @@ const MatchesInfo& MatchesInfo::operator =(const MatchesInfo &other)
//////////////////////////////////////////////////////////////////////////////
void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<MatchesInfo> &pairwise_matches,
void FeaturesMatcher::operator ()(const std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
const Mat &mask)
{
const int num_images = static_cast<int>(features.size());
@@ -509,11 +508,11 @@ void FeaturesMatcher::operator ()(const vector<ImageFeatures> &features, vector<
if (mask_.empty())
mask_ = Mat::ones(num_images, num_images, CV_8U);
vector<pair<int,int> > near_pairs;
std::vector<std::pair<int,int> > near_pairs;
for (int i = 0; i < num_images - 1; ++i)
for (int j = i + 1; j < num_images; ++j)
if (features[i].keypoints.size() > 0 && features[j].keypoints.size() > 0 && mask_(i, j))
near_pairs.push_back(make_pair(i, j));
near_pairs.push_back(std::make_pair(i, j));
pairwise_matches.resize(num_images * num_images);
MatchPairsBody body(*this, features, pairwise_matches, near_pairs);
@@ -574,7 +573,7 @@ void BestOf2NearestMatcher::match(const ImageFeatures &features1, const ImageFea
// Find pair-wise motion
matches_info.H = findHomography(src_points, dst_points, matches_info.inliers_mask, CV_RANSAC);
if (std::abs(determinant(matches_info.H)) < numeric_limits<double>::epsilon())
if (std::abs(determinant(matches_info.H)) < std::numeric_limits<double>::epsilon())
return;
// Find number of inliers

View File

@@ -42,7 +42,6 @@
#include "precomp.hpp"
using namespace std;
using namespace cv;
using namespace cv::detail;
@@ -50,7 +49,7 @@ namespace {
struct IncDistance
{
IncDistance(vector<int> &vdists) : dists(&vdists[0]) {}
IncDistance(std::vector<int> &vdists) : dists(&vdists[0]) {}
void operator ()(const GraphEdge &edge) { dists[edge.to] = dists[edge.from] + 1; }
int* dists;
};
@@ -58,7 +57,7 @@ struct IncDistance
struct CalcRotation
{
CalcRotation(int _num_images, const vector<MatchesInfo> &_pairwise_matches, vector<CameraParams> &_cameras)
CalcRotation(int _num_images, const std::vector<MatchesInfo> &_pairwise_matches, std::vector<CameraParams> &_cameras)
: num_images(_num_images), pairwise_matches(&_pairwise_matches[0]), cameras(&_cameras[0]) {}
void operator ()(const GraphEdge &edge)
@@ -101,8 +100,8 @@ void calcDeriv(const Mat &err1, const Mat &err2, double h, Mat res)
namespace cv {
namespace detail {
void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, const vector<MatchesInfo> &pairwise_matches,
vector<CameraParams> &cameras)
void HomographyBasedEstimator::estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
std::vector<CameraParams> &cameras)
{
LOGLN("Estimating rotations...");
#if ENABLE_LOG
@@ -113,11 +112,11 @@ void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, c
#if 0
// Robustly estimate focal length from rotating cameras
vector<Mat> Hs;
std::vector<Mat> Hs;
for (int iter = 0; iter < 100; ++iter)
{
int len = 2 + rand()%(pairwise_matches.size() - 1);
vector<int> subset;
std::vector<int> subset;
selectRandomSubset(len, pairwise_matches.size(), subset);
Hs.clear();
for (size_t i = 0; i < subset.size(); ++i)
@@ -135,7 +134,7 @@ void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, c
if (!is_focals_estimated_)
{
// Estimate focal length and set it for all cameras
vector<double> focals;
std::vector<double> focals;
estimateFocal(features, pairwise_matches, focals);
cameras.assign(num_images, CameraParams());
for (int i = 0; i < num_images; ++i)
@@ -152,7 +151,7 @@ void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, c
// Restore global motion
Graph span_tree;
vector<int> span_tree_centers;
std::vector<int> span_tree_centers;
findMaxSpanningTree(num_images, pairwise_matches, span_tree, span_tree_centers);
span_tree.walkBreadthFirst(span_tree_centers[0], CalcRotation(num_images, pairwise_matches, cameras));
@@ -169,9 +168,9 @@ void HomographyBasedEstimator::estimate(const vector<ImageFeatures> &features, c
//////////////////////////////////////////////////////////////////////////////
void BundleAdjusterBase::estimate(const vector<ImageFeatures> &features,
const vector<MatchesInfo> &pairwise_matches,
vector<CameraParams> &cameras)
void BundleAdjusterBase::estimate(const std::vector<ImageFeatures> &features,
const std::vector<MatchesInfo> &pairwise_matches,
std::vector<CameraParams> &cameras)
{
LOG_CHAT("Bundle adjustment");
#if ENABLE_LOG
@@ -192,7 +191,7 @@ void BundleAdjusterBase::estimate(const vector<ImageFeatures> &features,
{
const MatchesInfo& matches_info = pairwise_matches_[i * num_images_ + j];
if (matches_info.confidence > conf_thresh_)
edges_.push_back(make_pair(i, j));
edges_.push_back(std::make_pair(i, j));
}
}
@@ -242,14 +241,14 @@ void BundleAdjusterBase::estimate(const vector<ImageFeatures> &features,
}
LOGLN_CHAT("");
LOGLN_CHAT("Bundle adjustment, final RMS error: " << sqrt(err.dot(err) / total_num_matches_));
LOGLN_CHAT("Bundle adjustment, final RMS error: " << std::sqrt(err.dot(err) / total_num_matches_));
LOGLN_CHAT("Bundle adjustment, iterations done: " << iter);
obtainRefinedCameraParams(cameras);
// Normalize motion to center image
Graph span_tree;
vector<int> span_tree_centers;
std::vector<int> span_tree_centers;
findMaxSpanningTree(num_images_, pairwise_matches, span_tree, span_tree_centers);
Mat R_inv = cameras[span_tree_centers[0]].R.inv();
for (int i = 0; i < num_images_; ++i)
@@ -261,7 +260,7 @@ void BundleAdjusterBase::estimate(const vector<ImageFeatures> &features,
//////////////////////////////////////////////////////////////////////////////
void BundleAdjusterReproj::setUpInitialCameraParams(const vector<CameraParams> &cameras)
void BundleAdjusterReproj::setUpInitialCameraParams(const std::vector<CameraParams> &cameras)
{
cam_params_.create(num_images_ * 7, 1, CV_64F);
SVD svd;
@@ -287,7 +286,7 @@ void BundleAdjusterReproj::setUpInitialCameraParams(const vector<CameraParams> &
}
void BundleAdjusterReproj::obtainRefinedCameraParams(vector<CameraParams> &cameras) const
void BundleAdjusterReproj::obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const
{
for (int i = 0; i < num_images_; ++i)
{
@@ -442,7 +441,7 @@ void BundleAdjusterReproj::calcJacobian(Mat &jac)
//////////////////////////////////////////////////////////////////////////////
void BundleAdjusterRay::setUpInitialCameraParams(const vector<CameraParams> &cameras)
void BundleAdjusterRay::setUpInitialCameraParams(const std::vector<CameraParams> &cameras)
{
cam_params_.create(num_images_ * 4, 1, CV_64F);
SVD svd;
@@ -465,7 +464,7 @@ void BundleAdjusterRay::setUpInitialCameraParams(const vector<CameraParams> &cam
}
void BundleAdjusterRay::obtainRefinedCameraParams(vector<CameraParams> &cameras) const
void BundleAdjusterRay::obtainRefinedCameraParams(std::vector<CameraParams> &cameras) const
{
for (int i = 0; i < num_images_; ++i)
{
@@ -537,17 +536,17 @@ void BundleAdjusterRay::calcError(Mat &err)
double x1 = H1(0,0)*p1.x + H1(0,1)*p1.y + H1(0,2);
double y1 = H1(1,0)*p1.x + H1(1,1)*p1.y + H1(1,2);
double z1 = H1(2,0)*p1.x + H1(2,1)*p1.y + H1(2,2);
double len = sqrt(x1*x1 + y1*y1 + z1*z1);
double len = std::sqrt(x1*x1 + y1*y1 + z1*z1);
x1 /= len; y1 /= len; z1 /= len;
Point2f p2 = features2.keypoints[m.trainIdx].pt;
double x2 = H2(0,0)*p2.x + H2(0,1)*p2.y + H2(0,2);
double y2 = H2(1,0)*p2.x + H2(1,1)*p2.y + H2(1,2);
double z2 = H2(2,0)*p2.x + H2(2,1)*p2.y + H2(2,2);
len = sqrt(x2*x2 + y2*y2 + z2*z2);
len = std::sqrt(x2*x2 + y2*y2 + z2*z2);
x2 /= len; y2 /= len; z2 /= len;
double mult = sqrt(f1 * f2);
double mult = std::sqrt(f1 * f2);
err.at<double>(3 * match_idx, 0) = mult * (x1 - x2);
err.at<double>(3 * match_idx + 1, 0) = mult * (y1 - y2);
err.at<double>(3 * match_idx + 2, 0) = mult * (z1 - z2);
@@ -583,7 +582,7 @@ void BundleAdjusterRay::calcJacobian(Mat &jac)
//////////////////////////////////////////////////////////////////////////////
void waveCorrect(vector<Mat> &rmats, WaveCorrectKind kind)
void waveCorrect(std::vector<Mat> &rmats, WaveCorrectKind kind)
{
LOGLN("Wave correcting...");
#if ENABLE_LOG
@@ -654,14 +653,14 @@ void waveCorrect(vector<Mat> &rmats, WaveCorrectKind kind)
//////////////////////////////////////////////////////////////////////////////
string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwise_matches,
std::string matchesGraphAsString(std::vector<std::string> &pathes, std::vector<MatchesInfo> &pairwise_matches,
float conf_threshold)
{
stringstream str;
std::stringstream str;
str << "graph matches_graph{\n";
const int num_images = static_cast<int>(pathes.size());
set<pair<int,int> > span_tree_edges;
std::set<std::pair<int,int> > span_tree_edges;
DisjointSets comps(num_images);
for (int i = 0; i < num_images; ++i)
@@ -675,25 +674,25 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
if (comp1 != comp2)
{
comps.mergeSets(comp1, comp2);
span_tree_edges.insert(make_pair(i, j));
span_tree_edges.insert(std::make_pair(i, j));
}
}
}
for (set<pair<int,int> >::const_iterator itr = span_tree_edges.begin();
for (std::set<std::pair<int,int> >::const_iterator itr = span_tree_edges.begin();
itr != span_tree_edges.end(); ++itr)
{
pair<int,int> edge = *itr;
std::pair<int,int> edge = *itr;
if (span_tree_edges.find(edge) != span_tree_edges.end())
{
string name_src = pathes[edge.first];
std::string name_src = pathes[edge.first];
size_t prefix_len = name_src.find_last_of("/\\");
if (prefix_len != string::npos) prefix_len++; else prefix_len = 0;
if (prefix_len != std::string::npos) prefix_len++; else prefix_len = 0;
name_src = name_src.substr(prefix_len, name_src.size() - prefix_len);
string name_dst = pathes[edge.second];
std::string name_dst = pathes[edge.second];
prefix_len = name_dst.find_last_of("/\\");
if (prefix_len != string::npos) prefix_len++; else prefix_len = 0;
if (prefix_len != std::string::npos) prefix_len++; else prefix_len = 0;
name_dst = name_dst.substr(prefix_len, name_dst.size() - prefix_len);
int pos = edge.first*num_images + edge.second;
@@ -708,9 +707,9 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
{
if (comps.size[comps.findSetByElem((int)i)] == 1)
{
string name = pathes[i];
std::string name = pathes[i];
size_t prefix_len = name.find_last_of("/\\");
if (prefix_len != string::npos) prefix_len++; else prefix_len = 0;
if (prefix_len != std::string::npos) prefix_len++; else prefix_len = 0;
name = name.substr(prefix_len, name.size() - prefix_len);
str << "\"" << name << "\";\n";
}
@@ -720,7 +719,7 @@ string matchesGraphAsString(vector<string> &pathes, vector<MatchesInfo> &pairwis
return str.str();
}
vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<MatchesInfo> &pairwise_matches,
std::vector<int> leaveBiggestComponent(std::vector<ImageFeatures> &features, std::vector<MatchesInfo> &pairwise_matches,
float conf_threshold)
{
const int num_images = static_cast<int>(features.size());
@@ -739,18 +738,18 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
}
}
int max_comp = static_cast<int>(max_element(comps.size.begin(), comps.size.end()) - comps.size.begin());
int max_comp = static_cast<int>(std::max_element(comps.size.begin(), comps.size.end()) - comps.size.begin());
vector<int> indices;
vector<int> indices_removed;
std::vector<int> indices;
std::vector<int> indices_removed;
for (int i = 0; i < num_images; ++i)
if (comps.findSetByElem(i) == max_comp)
indices.push_back(i);
else
indices_removed.push_back(i);
vector<ImageFeatures> features_subset;
vector<MatchesInfo> pairwise_matches_subset;
std::vector<ImageFeatures> features_subset;
std::vector<MatchesInfo> pairwise_matches_subset;
for (size_t i = 0; i < indices.size(); ++i)
{
features_subset.push_back(features[indices[i]]);
@@ -779,11 +778,11 @@ vector<int> leaveBiggestComponent(vector<ImageFeatures> &features, vector<Match
}
void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_matches,
Graph &span_tree, vector<int> &centers)
void findMaxSpanningTree(int num_images, const std::vector<MatchesInfo> &pairwise_matches,
Graph &span_tree, std::vector<int> &centers)
{
Graph graph(num_images);
vector<GraphEdge> edges;
std::vector<GraphEdge> edges;
// Construct images graph and remember its edges
for (int i = 0; i < num_images; ++i)
@@ -800,10 +799,10 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
DisjointSets comps(num_images);
span_tree.create(num_images);
vector<int> span_tree_powers(num_images, 0);
std::vector<int> span_tree_powers(num_images, 0);
// Find maximum spanning tree
sort(edges.begin(), edges.end(), greater<GraphEdge>());
sort(edges.begin(), edges.end(), std::greater<GraphEdge>());
for (size_t i = 0; i < edges.size(); ++i)
{
int comp1 = comps.findSetByElem(edges[i].from);
@@ -819,20 +818,20 @@ void findMaxSpanningTree(int num_images, const vector<MatchesInfo> &pairwise_mat
}
// Find spanning tree leafs
vector<int> span_tree_leafs;
std::vector<int> span_tree_leafs;
for (int i = 0; i < num_images; ++i)
if (span_tree_powers[i] == 1)
span_tree_leafs.push_back(i);
// Find maximum distance from each spanning tree vertex
vector<int> max_dists(num_images, 0);
vector<int> cur_dists;
std::vector<int> max_dists(num_images, 0);
std::vector<int> cur_dists;
for (size_t i = 0; i < span_tree_leafs.size(); ++i)
{
cur_dists.assign(num_images, 0);
span_tree.walkBreadthFirst(span_tree_leafs[i], IncDistance(cur_dists));
for (int j = 0; j < num_images; ++j)
max_dists[j] = max(max_dists[j], cur_dists[j]);
max_dists[j] = std::max(max_dists[j], cur_dists[j]);
}
// Find min-max distance

View File

@@ -43,13 +43,11 @@
#include "precomp.hpp"
#include <map>
using namespace std;
namespace cv {
namespace detail {
void PairwiseSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners,
vector<Mat> &masks)
void PairwiseSeamFinder::find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks)
{
LOGLN("Finding seams...");
if (src.size() == 0)
@@ -85,8 +83,8 @@ void PairwiseSeamFinder::run()
}
void VoronoiSeamFinder::find(const vector<Size> &sizes, const vector<Point> &corners,
vector<Mat> &masks)
void VoronoiSeamFinder::find(const std::vector<Size> &sizes, const std::vector<Point> &corners,
std::vector<Mat> &masks)
{
LOGLN("Finding seams...");
if (sizes.size() == 0)
@@ -162,7 +160,7 @@ void VoronoiSeamFinder::findInPair(size_t first, size_t second, Rect roi)
DpSeamFinder::DpSeamFinder(CostFunction costFunc) : costFunc_(costFunc) {}
void DpSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners, vector<Mat> &masks)
void DpSeamFinder::find(const std::vector<Mat> &src, const std::vector<Point> &corners, std::vector<Mat> &masks)
{
LOGLN("Finding seams...");
#if ENABLE_LOG
@@ -172,14 +170,14 @@ void DpSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners, ve
if (src.size() == 0)
return;
vector<pair<size_t, size_t> > pairs;
std::vector<std::pair<size_t, size_t> > pairs;
for (size_t i = 0; i+1 < src.size(); ++i)
for (size_t j = i+1; j < src.size(); ++j)
pairs.push_back(make_pair(i, j));
pairs.push_back(std::make_pair(i, j));
sort(pairs.begin(), pairs.end(), ImagePairLess(src, corners));
reverse(pairs.begin(), pairs.end());
std::reverse(pairs.begin(), pairs.end());
for (size_t i = 0; i < pairs.size(); ++i)
{
@@ -271,11 +269,11 @@ void DpSeamFinder::findComponents()
for (int x = 0; x < unionSize_.width; ++x)
{
if (mask1_(y, x) && mask2_(y, x))
labels_(y, x) = numeric_limits<int>::max();
labels_(y, x) = std::numeric_limits<int>::max();
else if (mask1_(y, x))
labels_(y, x) = numeric_limits<int>::max()-1;
labels_(y, x) = std::numeric_limits<int>::max()-1;
else if (mask2_(y, x))
labels_(y, x) = numeric_limits<int>::max()-2;
labels_(y, x) = std::numeric_limits<int>::max()-2;
else
labels_(y, x) = 0;
}
@@ -285,19 +283,19 @@ void DpSeamFinder::findComponents()
{
for (int x = 0; x < unionSize_.width; ++x)
{
if (labels_(y, x) >= numeric_limits<int>::max()-2)
if (labels_(y, x) >= std::numeric_limits<int>::max()-2)
{
if (labels_(y, x) == numeric_limits<int>::max())
if (labels_(y, x) == std::numeric_limits<int>::max())
states_.push_back(INTERS);
else if (labels_(y, x) == numeric_limits<int>::max()-1)
else if (labels_(y, x) == std::numeric_limits<int>::max()-1)
states_.push_back(FIRST);
else if (labels_(y, x) == numeric_limits<int>::max()-2)
else if (labels_(y, x) == std::numeric_limits<int>::max()-2)
states_.push_back(SECOND);
floodFill(labels_, Point(x, y), ++ncomps_);
tls_.push_back(Point(x, y));
brs_.push_back(Point(x+1, y+1));
contours_.push_back(vector<Point>());
contours_.push_back(std::vector<Point>());
}
if (labels_(y, x))
@@ -325,14 +323,14 @@ void DpSeamFinder::findEdges()
{
// find edges between components
map<pair<int, int>, int> wedges; // weighted edges
std::map<std::pair<int, int>, int> wedges; // weighted edges
for (int ci = 0; ci < ncomps_-1; ++ci)
{
for (int cj = ci+1; cj < ncomps_; ++cj)
{
wedges[make_pair(ci, cj)] = 0;
wedges[make_pair(cj, ci)] = 0;
wedges[std::make_pair(ci, cj)] = 0;
wedges[std::make_pair(cj, ci)] = 0;
}
}
@@ -346,26 +344,26 @@ void DpSeamFinder::findEdges()
if (x > 0 && labels_(y, x-1) && labels_(y, x-1) != l)
{
wedges[make_pair(ci, labels_(y, x-1)-1)]++;
wedges[make_pair(labels_(y, x-1)-1, ci)]++;
wedges[std::make_pair(ci, labels_(y, x-1)-1)]++;
wedges[std::make_pair(labels_(y, x-1)-1, ci)]++;
}
if (y > 0 && labels_(y-1, x) && labels_(y-1, x) != l)
{
wedges[make_pair(ci, labels_(y-1, x)-1)]++;
wedges[make_pair(labels_(y-1, x)-1, ci)]++;
wedges[std::make_pair(ci, labels_(y-1, x)-1)]++;
wedges[std::make_pair(labels_(y-1, x)-1, ci)]++;
}
if (x < unionSize_.width-1 && labels_(y, x+1) && labels_(y, x+1) != l)
{
wedges[make_pair(ci, labels_(y, x+1)-1)]++;
wedges[make_pair(labels_(y, x+1)-1, ci)]++;
wedges[std::make_pair(ci, labels_(y, x+1)-1)]++;
wedges[std::make_pair(labels_(y, x+1)-1, ci)]++;
}
if (y < unionSize_.height-1 && labels_(y+1, x) && labels_(y+1, x) != l)
{
wedges[make_pair(ci, labels_(y+1, x)-1)]++;
wedges[make_pair(labels_(y+1, x)-1, ci)]++;
wedges[std::make_pair(ci, labels_(y+1, x)-1)]++;
wedges[std::make_pair(labels_(y+1, x)-1, ci)]++;
}
}
}
@@ -376,11 +374,11 @@ void DpSeamFinder::findEdges()
{
for (int cj = ci+1; cj < ncomps_; ++cj)
{
map<pair<int, int>, int>::iterator itr = wedges.find(make_pair(ci, cj));
std::map<std::pair<int, int>, int>::iterator itr = wedges.find(std::make_pair(ci, cj));
if (itr != wedges.end() && itr->second > 0)
edges_.insert(itr->first);
itr = wedges.find(make_pair(cj, ci));
itr = wedges.find(std::make_pair(cj, ci));
if (itr != wedges.end() && itr->second > 0)
edges_.insert(itr->first);
}
@@ -402,7 +400,7 @@ void DpSeamFinder::resolveConflicts(
int c1 = 0, c2 = 0;
hasConflict = false;
for (set<pair<int, int> >::iterator itr = edges_.begin(); itr != edges_.end(); ++itr)
for (std::set<std::pair<int, int> >::iterator itr = edges_.begin(); itr != edges_.end(); ++itr)
{
c1 = itr->first;
c2 = itr->second;
@@ -436,7 +434,7 @@ void DpSeamFinder::resolveConflicts(
Point p1, p2;
if (getSeamTips(c1, c2, p1, p2))
{
vector<Point> seam;
std::vector<Point> seam;
bool isHorizontalSeam;
if (estimateSeam(image1, image2, tl1, tl2, c1, p1, p2, seam, isHorizontalSeam))
@@ -456,8 +454,8 @@ void DpSeamFinder::resolveConflicts(
int x0 = tls_[c[i]].x, x1 = brs_[c[i]].x;
int y0 = tls_[c[i]].y, y1 = brs_[c[i]].y;
tls_[c[i]] = Point(numeric_limits<int>::max(), numeric_limits<int>::max());
brs_[c[i]] = Point(numeric_limits<int>::min(), numeric_limits<int>::min());
tls_[c[i]] = Point(std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
brs_[c[i]] = Point(std::numeric_limits<int>::min(), std::numeric_limits<int>::min());
contours_[c[i]].clear();
for (int y = y0; y < y1; ++y)
@@ -483,8 +481,8 @@ void DpSeamFinder::resolveConflicts(
// remove edges
edges_.erase(make_pair(c1, c2));
edges_.erase(make_pair(c2, c1));
edges_.erase(std::make_pair(c1, c2));
edges_.erase(std::make_pair(c2, c1));
}
}
@@ -543,9 +541,9 @@ void DpSeamFinder::computeGradients(const Mat &image1, const Mat &image2)
bool DpSeamFinder::hasOnlyOneNeighbor(int comp)
{
set<pair<int, int> >::iterator begin, end;
begin = lower_bound(edges_.begin(), edges_.end(), make_pair(comp, numeric_limits<int>::min()));
end = upper_bound(edges_.begin(), edges_.end(), make_pair(comp, numeric_limits<int>::max()));
std::set<std::pair<int, int> >::iterator begin, end;
begin = lower_bound(edges_.begin(), edges_.end(), std::make_pair(comp, std::numeric_limits<int>::min()));
end = upper_bound(edges_.begin(), edges_.end(), std::make_pair(comp, std::numeric_limits<int>::max()));
return ++begin == end;
}
@@ -579,7 +577,7 @@ bool DpSeamFinder::getSeamTips(int comp1, int comp2, Point &p1, Point &p2)
// find special points
vector<Point> specialPoints;
std::vector<Point> specialPoints;
int l2 = comp2+1;
for (size_t i = 0; i < contours_[comp1].size(); ++i)
@@ -603,15 +601,15 @@ bool DpSeamFinder::getSeamTips(int comp1, int comp2, Point &p1, Point &p2)
// find clusters
vector<int> labels;
std::vector<int> labels;
cv::partition(specialPoints, labels, ClosePoints(10));
int nlabels = *max_element(labels.begin(), labels.end()) + 1;
int nlabels = *std::max_element(labels.begin(), labels.end()) + 1;
if (nlabels < 2)
return false;
vector<Point> sum(nlabels);
vector<vector<Point> > points(nlabels);
std::vector<Point> sum(nlabels);
std::vector<std::vector<Point> > points(nlabels);
for (size_t i = 0; i < specialPoints.size(); ++i)
{
@@ -622,7 +620,7 @@ bool DpSeamFinder::getSeamTips(int comp1, int comp2, Point &p1, Point &p2)
// select two most distant clusters
int idx[2] = {-1,-1};
double maxDist = -numeric_limits<double>::max();
double maxDist = -std::numeric_limits<double>::max();
for (int i = 0; i < nlabels-1; ++i)
{
@@ -653,7 +651,7 @@ bool DpSeamFinder::getSeamTips(int comp1, int comp2, Point &p1, Point &p2)
double cy = cvRound(sum[idx[i]].y / size);
size_t closest = points[idx[i]].size();
double minDist = numeric_limits<double>::max();
double minDist = std::numeric_limits<double>::max();
for (size_t j = 0; j < points[idx[i]].size(); ++j)
{
@@ -781,7 +779,7 @@ void DpSeamFinder::computeCosts(
bool DpSeamFinder::estimateSeam(
const Mat &image1, const Mat &image2, Point tl1, Point tl2, int comp,
Point p1, Point p2, vector<Point> &seam, bool &isHorizontal)
Point p1, Point p2, std::vector<Point> &seam, bool &isHorizontal)
{
CV_Assert(states_[comp] & INTERS);
@@ -822,7 +820,7 @@ bool DpSeamFinder::estimateSeam(
cost(src) = 0.f;
int nsteps;
pair<float, int> steps[3];
std::pair<float, int> steps[3];
if (isHorizontal)
{
@@ -837,16 +835,16 @@ bool DpSeamFinder::estimateSeam(
if (labels_(y + roi.y, x + roi.x) == l)
{
if (reachable(y, x-1))
steps[nsteps++] = make_pair(cost(y, x-1) + costH(y, x-1), 1);
steps[nsteps++] = std::make_pair(cost(y, x-1) + costH(y, x-1), 1);
if (y > 0 && reachable(y-1, x-1))
steps[nsteps++] = make_pair(cost(y-1, x-1) + costH(y-1, x-1) + costV(y-1, x), 2);
steps[nsteps++] = std::make_pair(cost(y-1, x-1) + costH(y-1, x-1) + costV(y-1, x), 2);
if (y < roi.height-1 && reachable(y+1, x-1))
steps[nsteps++] = make_pair(cost(y+1, x-1) + costH(y+1, x-1) + costV(y, x), 3);
steps[nsteps++] = std::make_pair(cost(y+1, x-1) + costH(y+1, x-1) + costV(y, x), 3);
}
if (nsteps)
{
pair<float, int> opt = *min_element(steps, steps + nsteps);
std::pair<float, int> opt = *min_element(steps, steps + nsteps);
cost(y, x) = opt.first;
control(y, x) = (uchar)opt.second;
reachable(y, x) = 255;
@@ -867,16 +865,16 @@ bool DpSeamFinder::estimateSeam(
if (labels_(y + roi.y, x + roi.x) == l)
{
if (reachable(y-1, x))
steps[nsteps++] = make_pair(cost(y-1, x) + costV(y-1, x), 1);
steps[nsteps++] = std::make_pair(cost(y-1, x) + costV(y-1, x), 1);
if (x > 0 && reachable(y-1, x-1))
steps[nsteps++] = make_pair(cost(y-1, x-1) + costV(y-1, x-1) + costH(y, x-1), 2);
steps[nsteps++] = std::make_pair(cost(y-1, x-1) + costV(y-1, x-1) + costH(y, x-1), 2);
if (x < roi.width-1 && reachable(y-1, x+1))
steps[nsteps++] = make_pair(cost(y-1, x+1) + costV(y-1, x+1) + costH(y, x), 3);
steps[nsteps++] = std::make_pair(cost(y-1, x+1) + costV(y-1, x+1) + costH(y, x), 3);
}
if (nsteps)
{
pair<float, int> opt = *min_element(steps, steps + nsteps);
std::pair<float, int> opt = *min_element(steps, steps + nsteps);
cost(y, x) = opt.first;
control(y, x) = (uchar)opt.second;
reachable(y, x) = 255;
@@ -914,7 +912,7 @@ bool DpSeamFinder::estimateSeam(
}
if (!swapped)
reverse(seam.begin(), seam.end());
std::reverse(seam.begin(), seam.end());
CV_Assert(seam.front() == p1);
CV_Assert(seam.back() == p2);
@@ -923,7 +921,7 @@ bool DpSeamFinder::estimateSeam(
void DpSeamFinder::updateLabelsUsingSeam(
int comp1, int comp2, const vector<Point> &seam, bool isHorizontalSeam)
int comp1, int comp2, const std::vector<Point> &seam, bool isHorizontalSeam)
{
Mat_<int> mask = Mat::zeros(brs_[comp1].y - tls_[comp1].y,
brs_[comp1].x - tls_[comp1].x, CV_32S);
@@ -1001,13 +999,13 @@ void DpSeamFinder::updateLabelsUsingSeam(
// find new components connected with the second component and
// with other components except the ones we are working with
map<int, int> connect2;
map<int, int> connectOther;
std::map<int, int> connect2;
std::map<int, int> connectOther;
for (int i = 1; i <= ncomps; ++i)
{
connect2.insert(make_pair(i, 0));
connectOther.insert(make_pair(i, 0));
connect2.insert(std::make_pair(i, 0));
connectOther.insert(std::make_pair(i, 0));
}
for (size_t i = 0; i < contours_[comp1].size(); ++i)
@@ -1032,9 +1030,9 @@ void DpSeamFinder::updateLabelsUsingSeam(
}
}
vector<int> isAdjComp(ncomps + 1, 0);
std::vector<int> isAdjComp(ncomps + 1, 0);
for (map<int, int>::iterator itr = connect2.begin(); itr != connect2.end(); ++itr)
for (std::map<int, int>::iterator itr = connect2.begin(); itr != connect2.end(); ++itr)
{
double len = static_cast<double>(contours_[comp1].size());
isAdjComp[itr->first] = itr->second / len > 0.05 && connectOther.find(itr->first)->second / len < 0.1;
@@ -1057,7 +1055,7 @@ public:
~Impl() {}
void find(const vector<Mat> &src, const vector<Point> &corners, vector<Mat> &masks);
void find(const std::vector<Mat> &src, const std::vector<Point> &corners, std::vector<Mat> &masks);
void findInPair(size_t first, size_t second, Rect roi);
private:
@@ -1067,15 +1065,15 @@ private:
const Mat &dy1, const Mat &dy2, const Mat &mask1, const Mat &mask2,
GCGraph<float> &graph);
vector<Mat> dx_, dy_;
std::vector<Mat> dx_, dy_;
int cost_type_;
float terminal_cost_;
float bad_region_penalty_;
};
void GraphCutSeamFinder::Impl::find(const vector<Mat> &src, const vector<Point> &corners,
vector<Mat> &masks)
void GraphCutSeamFinder::Impl::find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks)
{
// Compute gradients
dx_.resize(src.size());
@@ -1311,16 +1309,16 @@ GraphCutSeamFinder::GraphCutSeamFinder(int cost_type, float terminal_cost, float
GraphCutSeamFinder::~GraphCutSeamFinder() {}
void GraphCutSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners,
vector<Mat> &masks)
void GraphCutSeamFinder::find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks)
{
impl_->find(src, corners, masks);
}
#ifdef HAVE_OPENCV_GPU
void GraphCutSeamFinderGpu::find(const vector<Mat> &src, const vector<Point> &corners,
vector<Mat> &masks)
void GraphCutSeamFinderGpu::find(const std::vector<Mat> &src, const std::vector<Point> &corners,
std::vector<Mat> &masks)
{
// Compute gradients
dx_.resize(src.size());

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
using namespace std;
namespace cv {
Stitcher Stitcher::createDefault(bool try_use_gpu)
@@ -90,11 +88,11 @@ Stitcher Stitcher::createDefault(bool try_use_gpu)
Stitcher::Status Stitcher::estimateTransform(InputArray images)
{
return estimateTransform(images, vector<vector<Rect> >());
return estimateTransform(images, std::vector<std::vector<Rect> >());
}
Stitcher::Status Stitcher::estimateTransform(InputArray images, const vector<vector<Rect> > &rois)
Stitcher::Status Stitcher::estimateTransform(InputArray images, const std::vector<std::vector<Rect> > &rois)
{
images.getMatVector(imgs_);
rois_ = rois;
@@ -113,7 +111,7 @@ Stitcher::Status Stitcher::estimateTransform(InputArray images, const vector<vec
Stitcher::Status Stitcher::composePanorama(OutputArray pano)
{
return composePanorama(vector<Mat>(), pano);
return composePanorama(std::vector<Mat>(), pano);
}
@@ -121,7 +119,7 @@ Stitcher::Status Stitcher::composePanorama(InputArray images, OutputArray pano)
{
LOGLN("Warping images (auxiliary)... ");
vector<Mat> imgs;
std::vector<Mat> imgs;
images.getMatVector(imgs);
if (!imgs.empty())
{
@@ -137,8 +135,8 @@ Stitcher::Status Stitcher::composePanorama(InputArray images, OutputArray pano)
seam_est_imgs_[i] = img.clone();
}
vector<Mat> seam_est_imgs_subset;
vector<Mat> imgs_subset;
std::vector<Mat> seam_est_imgs_subset;
std::vector<Mat> imgs_subset;
for (size_t i = 0; i < indices_.size(); ++i)
{
@@ -156,11 +154,11 @@ Stitcher::Status Stitcher::composePanorama(InputArray images, OutputArray pano)
int64 t = getTickCount();
#endif
vector<Point> corners(imgs_.size());
vector<Mat> masks_warped(imgs_.size());
vector<Mat> images_warped(imgs_.size());
vector<Size> sizes(imgs_.size());
vector<Mat> masks(imgs_.size());
std::vector<Point> corners(imgs_.size());
std::vector<Mat> masks_warped(imgs_.size());
std::vector<Mat> images_warped(imgs_.size());
std::vector<Size> sizes(imgs_.size());
std::vector<Mat> masks(imgs_.size());
// Prepare image masks
for (size_t i = 0; i < imgs_.size(); ++i)
@@ -186,7 +184,7 @@ Stitcher::Status Stitcher::composePanorama(InputArray images, OutputArray pano)
w->warp(masks[i], K, cameras_[i].R, INTER_NEAREST, BORDER_CONSTANT, masks_warped[i]);
}
vector<Mat> images_warped_f(imgs_.size());
std::vector<Mat> images_warped_f(imgs_.size());
for (size_t i = 0; i < imgs_.size(); ++i)
images_warped[i].convertTo(images_warped_f[i], CV_32F);
@@ -227,7 +225,7 @@ Stitcher::Status Stitcher::composePanorama(InputArray images, OutputArray pano)
if (!is_compose_scale_set)
{
if (compose_resol_ > 0)
compose_scale = min(1.0, sqrt(compose_resol_ * 1e6 / full_img.size().area()));
compose_scale = std::min(1.0, std::sqrt(compose_resol_ * 1e6 / full_img.size().area()));
is_compose_scale_set = true;
// Compute relative scales
@@ -325,7 +323,7 @@ Stitcher::Status Stitcher::stitch(InputArray images, OutputArray pano)
}
Stitcher::Status Stitcher::stitch(InputArray images, const vector<vector<Rect> > &rois, OutputArray pano)
Stitcher::Status Stitcher::stitch(InputArray images, const std::vector<std::vector<Rect> > &rois, OutputArray pano)
{
Status status = estimateTransform(images, rois);
if (status != OK)
@@ -372,14 +370,14 @@ Stitcher::Status Stitcher::matchImages()
{
if (!is_work_scale_set)
{
work_scale_ = min(1.0, sqrt(registr_resol_ * 1e6 / full_img.size().area()));
work_scale_ = std::min(1.0, std::sqrt(registr_resol_ * 1e6 / full_img.size().area()));
is_work_scale_set = true;
}
resize(full_img, img, Size(), work_scale_, work_scale_);
}
if (!is_seam_scale_set)
{
seam_scale_ = min(1.0, sqrt(seam_est_resol_ * 1e6 / full_img.size().area()));
seam_scale_ = std::min(1.0, std::sqrt(seam_est_resol_ * 1e6 / full_img.size().area()));
seam_work_aspect_ = seam_scale_ / work_scale_;
is_seam_scale_set = true;
}
@@ -388,7 +386,7 @@ Stitcher::Status Stitcher::matchImages()
(*features_finder_)(img, features_[i]);
else
{
vector<Rect> rois(rois_[i].size());
std::vector<Rect> rois(rois_[i].size());
for (size_t j = 0; j < rois_[i].size(); ++j)
{
Point tl(cvRound(rois_[i][j].x * work_scale_), cvRound(rois_[i][j].y * work_scale_));
@@ -421,9 +419,9 @@ Stitcher::Status Stitcher::matchImages()
// Leave only images we are sure are from the same panorama
indices_ = detail::leaveBiggestComponent(features_, pairwise_matches_, (float)conf_thresh_);
vector<Mat> seam_est_imgs_subset;
vector<Mat> imgs_subset;
vector<Size> full_img_sizes_subset;
std::vector<Mat> seam_est_imgs_subset;
std::vector<Mat> imgs_subset;
std::vector<Size> full_img_sizes_subset;
for (size_t i = 0; i < indices_.size(); ++i)
{
imgs_subset.push_back(imgs_[indices_[i]]);
@@ -461,7 +459,7 @@ void Stitcher::estimateCameraParams()
(*bundle_adjuster_)(features_, pairwise_matches_, cameras_);
// Find median focal length and use it as final image scale
vector<double> focals;
std::vector<double> focals;
for (size_t i = 0; i < cameras_.size(); ++i)
{
LOGLN("Camera #" << indices_[i] + 1 << ":\n" << cameras_[i].K());
@@ -476,7 +474,7 @@ void Stitcher::estimateCameraParams()
if (do_wave_correct_)
{
vector<Mat> rmats;
std::vector<Mat> rmats;
for (size_t i = 0; i < cameras_.size(); ++i)
rmats.push_back(cameras_[i].R);
detail::waveCorrect(rmats, wave_correct_kind_);

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
using namespace std;
namespace cv {
namespace detail {
@@ -102,10 +100,10 @@ void Graph::addEdge(int from, int to, float weight)
bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi)
{
int x_tl = max(tl1.x, tl2.x);
int y_tl = max(tl1.y, tl2.y);
int x_br = min(tl1.x + sz1.width, tl2.x + sz2.width);
int y_br = min(tl1.y + sz1.height, tl2.y + sz2.height);
int x_tl = std::max(tl1.x, tl2.x);
int y_tl = std::max(tl1.y, tl2.y);
int x_br = std::min(tl1.x + sz1.width, tl2.x + sz2.width);
int y_br = std::min(tl1.y + sz1.height, tl2.y + sz2.height);
if (x_tl < x_br && y_tl < y_br)
{
roi = Rect(x_tl, y_tl, x_br - x_tl, y_br - y_tl);
@@ -115,44 +113,44 @@ bool overlapRoi(Point tl1, Point tl2, Size sz1, Size sz2, Rect &roi)
}
Rect resultRoi(const vector<Point> &corners, const vector<Mat> &images)
Rect resultRoi(const std::vector<Point> &corners, const std::vector<Mat> &images)
{
vector<Size> sizes(images.size());
std::vector<Size> sizes(images.size());
for (size_t i = 0; i < images.size(); ++i)
sizes[i] = images[i].size();
return resultRoi(corners, sizes);
}
Rect resultRoi(const vector<Point> &corners, const vector<Size> &sizes)
Rect resultRoi(const std::vector<Point> &corners, const std::vector<Size> &sizes)
{
CV_Assert(sizes.size() == corners.size());
Point tl(numeric_limits<int>::max(), numeric_limits<int>::max());
Point br(numeric_limits<int>::min(), numeric_limits<int>::min());
Point tl(std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
Point br(std::numeric_limits<int>::min(), std::numeric_limits<int>::min());
for (size_t i = 0; i < corners.size(); ++i)
{
tl.x = min(tl.x, corners[i].x);
tl.y = min(tl.y, corners[i].y);
br.x = max(br.x, corners[i].x + sizes[i].width);
br.y = max(br.y, corners[i].y + sizes[i].height);
tl.x = std::min(tl.x, corners[i].x);
tl.y = std::min(tl.y, corners[i].y);
br.x = std::max(br.x, corners[i].x + sizes[i].width);
br.y = std::max(br.y, corners[i].y + sizes[i].height);
}
return Rect(tl, br);
}
Point resultTl(const vector<Point> &corners)
Point resultTl(const std::vector<Point> &corners)
{
Point tl(numeric_limits<int>::max(), numeric_limits<int>::max());
Point tl(std::numeric_limits<int>::max(), std::numeric_limits<int>::max());
for (size_t i = 0; i < corners.size(); ++i)
{
tl.x = min(tl.x, corners[i].x);
tl.y = min(tl.y, corners[i].y);
tl.x = std::min(tl.x, corners[i].x);
tl.y = std::min(tl.y, corners[i].y);
}
return tl;
}
void selectRandomSubset(int count, int size, vector<int> &subset)
void selectRandomSubset(int count, int size, std::vector<int> &subset)
{
subset.clear();
for (int i = 0; i < size; ++i)

View File

@@ -42,8 +42,6 @@
#include "precomp.hpp"
using namespace std;
namespace cv {
namespace detail {
@@ -138,28 +136,28 @@ Rect PlaneWarper::warpRoi(Size src_size, const Mat &K, const Mat &R, const Mat &
void PlaneWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
{
float tl_uf = numeric_limits<float>::max();
float tl_vf = numeric_limits<float>::max();
float br_uf = -numeric_limits<float>::max();
float br_vf = -numeric_limits<float>::max();
float tl_uf = std::numeric_limits<float>::max();
float tl_vf = std::numeric_limits<float>::max();
float br_uf = -std::numeric_limits<float>::max();
float br_vf = -std::numeric_limits<float>::max();
float u, v;
projector_.mapForward(0, 0, u, v);
tl_uf = min(tl_uf, u); tl_vf = min(tl_vf, v);
br_uf = max(br_uf, u); br_vf = max(br_vf, v);
tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
projector_.mapForward(0, static_cast<float>(src_size.height - 1), u, v);
tl_uf = min(tl_uf, u); tl_vf = min(tl_vf, v);
br_uf = max(br_uf, u); br_vf = max(br_vf, v);
tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
projector_.mapForward(static_cast<float>(src_size.width - 1), 0, u, v);
tl_uf = min(tl_uf, u); tl_vf = min(tl_vf, v);
br_uf = max(br_uf, u); br_vf = max(br_vf, v);
tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
projector_.mapForward(static_cast<float>(src_size.width - 1), static_cast<float>(src_size.height - 1), u, v);
tl_uf = min(tl_uf, u); tl_vf = min(tl_vf, v);
br_uf = max(br_uf, u); br_vf = max(br_vf, v);
tl_uf = std::min(tl_uf, u); tl_vf = std::min(tl_vf, v);
br_uf = std::max(br_uf, u); br_vf = std::max(br_vf, v);
dst_tl.x = static_cast<int>(tl_uf);
dst_tl.y = static_cast<int>(tl_vf);
@@ -186,8 +184,8 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b
float y_ = projector_.k[4] * y / z + projector_.k[5];
if (x_ > 0.f && x_ < src_size.width && y_ > 0.f && y_ < src_size.height)
{
tl_uf = min(tl_uf, 0.f); tl_vf = min(tl_vf, static_cast<float>(CV_PI * projector_.scale));
br_uf = max(br_uf, 0.f); br_vf = max(br_vf, static_cast<float>(CV_PI * projector_.scale));
tl_uf = std::min(tl_uf, 0.f); tl_vf = std::min(tl_vf, static_cast<float>(CV_PI * projector_.scale));
br_uf = std::max(br_uf, 0.f); br_vf = std::max(br_vf, static_cast<float>(CV_PI * projector_.scale));
}
}
@@ -200,8 +198,8 @@ void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_b
float y_ = projector_.k[4] * y / z + projector_.k[5];
if (x_ > 0.f && x_ < src_size.width && y_ > 0.f && y_ < src_size.height)
{
tl_uf = min(tl_uf, 0.f); tl_vf = min(tl_vf, static_cast<float>(0));
br_uf = max(br_uf, 0.f); br_vf = max(br_vf, static_cast<float>(0));
tl_uf = std::min(tl_uf, 0.f); tl_vf = std::min(tl_vf, static_cast<float>(0));
br_uf = std::max(br_uf, 0.f); br_vf = std::max(br_vf, static_cast<float>(0));
}
}
@@ -314,8 +312,8 @@ void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Poin
float y_ = projector_.k[4] * y / z + projector_.k[5];
if (x_ > 0.f && x_ < src_size.width && y_ > 0.f && y_ < src_size.height)
{
tl_uf = min(tl_uf, 0.f); tl_vf = min(tl_vf, static_cast<float>(CV_PI * projector_.scale));
br_uf = max(br_uf, 0.f); br_vf = max(br_vf, static_cast<float>(CV_PI * projector_.scale));
tl_uf = std::min(tl_uf, 0.f); tl_vf = std::min(tl_vf, static_cast<float>(CV_PI * projector_.scale));
br_uf = std::max(br_uf, 0.f); br_vf = std::max(br_vf, static_cast<float>(CV_PI * projector_.scale));
}
}
@@ -328,8 +326,8 @@ void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Poin
float y_ = projector_.k[4] * y / z + projector_.k[5];
if (x_ > 0.f && x_ < src_size.width && y_ > 0.f && y_ < src_size.height)
{
tl_uf = min(tl_uf, 0.f); tl_vf = min(tl_vf, static_cast<float>(0));
br_uf = max(br_uf, 0.f); br_vf = max(br_vf, static_cast<float>(0));
tl_uf = std::min(tl_uf, 0.f); tl_vf = std::min(tl_vf, static_cast<float>(0));
br_uf = std::max(br_uf, 0.f); br_vf = std::max(br_vf, static_cast<float>(0));
}
}