Normalize line endings and whitespace
This commit is contained in:

committed by
Andrey Kamaev

parent
69020da607
commit
04384a71e4
@@ -1,198 +1,198 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename _Tp> static inline bool
|
||||
decomposeCholesky(_Tp* A, size_t astep, int m)
|
||||
{
|
||||
if (!Cholesky(A, astep, m, 0, 0, 0))
|
||||
return false;
|
||||
astep /= sizeof(A[0]);
|
||||
for (int i = 0; i < m; ++i)
|
||||
A[i*astep + i] = (_Tp)(1./A[i*astep + i]);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, bool &f1_ok)
|
||||
{
|
||||
CV_Assert(H.type() == CV_64F && H.size() == Size(3, 3));
|
||||
|
||||
const double* h = reinterpret_cast<const double*>(H.data);
|
||||
|
||||
double d1, d2; // Denominators
|
||||
double v1, v2; // Focal squares value candidates
|
||||
|
||||
f1_ok = true;
|
||||
d1 = h[6] * h[7];
|
||||
d2 = (h[7] - h[6]) * (h[7] + h[6]);
|
||||
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);
|
||||
else f1_ok = false;
|
||||
|
||||
f0_ok = true;
|
||||
d1 = h[0] * h[3] + h[1] * h[4];
|
||||
d2 = h[0] * h[0] + h[1] * h[1] - h[3] * h[3] - h[4] * h[4];
|
||||
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);
|
||||
else f0_ok = false;
|
||||
}
|
||||
|
||||
|
||||
void estimateFocal(const vector<ImageFeatures> &features, const vector<MatchesInfo> &pairwise_matches,
|
||||
vector<double> &focals)
|
||||
{
|
||||
const int num_images = static_cast<int>(features.size());
|
||||
focals.resize(num_images);
|
||||
|
||||
vector<double> all_focals;
|
||||
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
{
|
||||
for (int j = 0; j < num_images; ++j)
|
||||
{
|
||||
const MatchesInfo &m = pairwise_matches[i*num_images + j];
|
||||
if (m.H.empty())
|
||||
continue;
|
||||
double f0, f1;
|
||||
bool f0ok, f1ok;
|
||||
focalsFromHomography(m.H, f0, f1, f0ok, f1ok);
|
||||
if (f0ok && f1ok)
|
||||
all_focals.push_back(sqrt(f0 * f1));
|
||||
}
|
||||
}
|
||||
|
||||
if (static_cast<int>(all_focals.size()) >= num_images - 1)
|
||||
{
|
||||
double median;
|
||||
|
||||
sort(all_focals.begin(), all_focals.end());
|
||||
if (all_focals.size() % 2 == 1)
|
||||
median = all_focals[all_focals.size() / 2];
|
||||
else
|
||||
median = (all_focals[all_focals.size() / 2 - 1] + all_focals[all_focals.size() / 2]) * 0.5;
|
||||
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
focals[i] = median;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGLN("Can't estimate focal length, will use naive approach");
|
||||
double focals_sum = 0;
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
focals_sum += features[i].img_size.width + features[i].img_size.height;
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
focals[i] = focals_sum / num_images;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool calibrateRotatingCamera(const vector<Mat> &Hs, Mat &K)
|
||||
{
|
||||
int m = static_cast<int>(Hs.size());
|
||||
CV_Assert(m >= 1);
|
||||
|
||||
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.);
|
||||
}
|
||||
|
||||
const int idx_map[3][3] = {{0, 1, 2}, {1, 3, 4}, {2, 4, 5}};
|
||||
Mat_<double> A(6*m, 6);
|
||||
A.setTo(0);
|
||||
|
||||
int eq_idx = 0;
|
||||
for (int k = 0; k < m; ++k)
|
||||
{
|
||||
Mat_<double> H(Hs_[k]);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = i; j < 3; ++j, ++eq_idx)
|
||||
{
|
||||
for (int l = 0; l < 3; ++l)
|
||||
{
|
||||
for (int s = 0; s < 3; ++s)
|
||||
{
|
||||
int idx = idx_map[l][s];
|
||||
A(eq_idx, idx) += H(i,l) * H(j,s);
|
||||
}
|
||||
}
|
||||
A(eq_idx, idx_map[i][j]) -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mat_<double> wcoef;
|
||||
SVD::solveZ(A, wcoef);
|
||||
|
||||
Mat_<double> W(3,3);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = i; j < 3; ++j)
|
||||
W(i,j) = W(j,i) = wcoef(idx_map[i][j], 0) / wcoef(5,0);
|
||||
if (!decomposeCholesky(W.ptr<double>(), W.step, 3))
|
||||
return false;
|
||||
W(0,1) = W(0,2) = W(1,2) = 0;
|
||||
K = W.t();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
namespace {
|
||||
|
||||
template<typename _Tp> static inline bool
|
||||
decomposeCholesky(_Tp* A, size_t astep, int m)
|
||||
{
|
||||
if (!Cholesky(A, astep, m, 0, 0, 0))
|
||||
return false;
|
||||
astep /= sizeof(A[0]);
|
||||
for (int i = 0; i < m; ++i)
|
||||
A[i*astep + i] = (_Tp)(1./A[i*astep + i]);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
void focalsFromHomography(const Mat& H, double &f0, double &f1, bool &f0_ok, bool &f1_ok)
|
||||
{
|
||||
CV_Assert(H.type() == CV_64F && H.size() == Size(3, 3));
|
||||
|
||||
const double* h = reinterpret_cast<const double*>(H.data);
|
||||
|
||||
double d1, d2; // Denominators
|
||||
double v1, v2; // Focal squares value candidates
|
||||
|
||||
f1_ok = true;
|
||||
d1 = h[6] * h[7];
|
||||
d2 = (h[7] - h[6]) * (h[7] + h[6]);
|
||||
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);
|
||||
else f1_ok = false;
|
||||
|
||||
f0_ok = true;
|
||||
d1 = h[0] * h[3] + h[1] * h[4];
|
||||
d2 = h[0] * h[0] + h[1] * h[1] - h[3] * h[3] - h[4] * h[4];
|
||||
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);
|
||||
else f0_ok = false;
|
||||
}
|
||||
|
||||
|
||||
void estimateFocal(const vector<ImageFeatures> &features, const vector<MatchesInfo> &pairwise_matches,
|
||||
vector<double> &focals)
|
||||
{
|
||||
const int num_images = static_cast<int>(features.size());
|
||||
focals.resize(num_images);
|
||||
|
||||
vector<double> all_focals;
|
||||
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
{
|
||||
for (int j = 0; j < num_images; ++j)
|
||||
{
|
||||
const MatchesInfo &m = pairwise_matches[i*num_images + j];
|
||||
if (m.H.empty())
|
||||
continue;
|
||||
double f0, f1;
|
||||
bool f0ok, f1ok;
|
||||
focalsFromHomography(m.H, f0, f1, f0ok, f1ok);
|
||||
if (f0ok && f1ok)
|
||||
all_focals.push_back(sqrt(f0 * f1));
|
||||
}
|
||||
}
|
||||
|
||||
if (static_cast<int>(all_focals.size()) >= num_images - 1)
|
||||
{
|
||||
double median;
|
||||
|
||||
sort(all_focals.begin(), all_focals.end());
|
||||
if (all_focals.size() % 2 == 1)
|
||||
median = all_focals[all_focals.size() / 2];
|
||||
else
|
||||
median = (all_focals[all_focals.size() / 2 - 1] + all_focals[all_focals.size() / 2]) * 0.5;
|
||||
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
focals[i] = median;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOGLN("Can't estimate focal length, will use naive approach");
|
||||
double focals_sum = 0;
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
focals_sum += features[i].img_size.width + features[i].img_size.height;
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
focals[i] = focals_sum / num_images;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool calibrateRotatingCamera(const vector<Mat> &Hs, Mat &K)
|
||||
{
|
||||
int m = static_cast<int>(Hs.size());
|
||||
CV_Assert(m >= 1);
|
||||
|
||||
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.);
|
||||
}
|
||||
|
||||
const int idx_map[3][3] = {{0, 1, 2}, {1, 3, 4}, {2, 4, 5}};
|
||||
Mat_<double> A(6*m, 6);
|
||||
A.setTo(0);
|
||||
|
||||
int eq_idx = 0;
|
||||
for (int k = 0; k < m; ++k)
|
||||
{
|
||||
Mat_<double> H(Hs_[k]);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
for (int j = i; j < 3; ++j, ++eq_idx)
|
||||
{
|
||||
for (int l = 0; l < 3; ++l)
|
||||
{
|
||||
for (int s = 0; s < 3; ++s)
|
||||
{
|
||||
int idx = idx_map[l][s];
|
||||
A(eq_idx, idx) += H(i,l) * H(j,s);
|
||||
}
|
||||
}
|
||||
A(eq_idx, idx_map[i][j]) -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Mat_<double> wcoef;
|
||||
SVD::solveZ(A, wcoef);
|
||||
|
||||
Mat_<double> W(3,3);
|
||||
for (int i = 0; i < 3; ++i)
|
||||
for (int j = i; j < 3; ++j)
|
||||
W(i,j) = W(j,i) = wcoef(idx_map[i][j], 0) / wcoef(5,0);
|
||||
if (!decomposeCholesky(W.ptr<double>(), W.step, 3))
|
||||
return false;
|
||||
W(0,1) = W(0,2) = W(1,2) = 0;
|
||||
K = W.t();
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -63,7 +63,7 @@ const CameraParams& CameraParams::operator =(const CameraParams &other)
|
||||
return *this;
|
||||
}
|
||||
|
||||
Mat CameraParams::K() const
|
||||
Mat CameraParams::K() const
|
||||
{
|
||||
Mat_<double> k = Mat::eye(3, 3, CV_64F);
|
||||
k(0,0) = focal; k(0,2) = ppx;
|
||||
|
@@ -1,249 +1,249 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
Ptr<ExposureCompensator> ExposureCompensator::createDefault(int type)
|
||||
{
|
||||
if (type == NO)
|
||||
return new NoExposureCompensator();
|
||||
if (type == GAIN)
|
||||
return new GainCompensator();
|
||||
if (type == GAIN_BLOCKS)
|
||||
return new BlocksGainCompensator();
|
||||
CV_Error(CV_StsBadArg, "unsupported exposure compensation method");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ExposureCompensator::feed(const vector<Point> &corners, const vector<Mat> &images,
|
||||
const vector<Mat> &masks)
|
||||
{
|
||||
vector<pair<Mat,uchar> > level_masks;
|
||||
for (size_t i = 0; i < masks.size(); ++i)
|
||||
level_masks.push_back(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)
|
||||
{
|
||||
LOGLN("Exposure compensation...");
|
||||
#if ENABLE_LOG
|
||||
int64 t = getTickCount();
|
||||
#endif
|
||||
|
||||
CV_Assert(corners.size() == images.size() && images.size() == masks.size());
|
||||
|
||||
const int num_images = static_cast<int>(images.size());
|
||||
Mat_<int> N(num_images, num_images); N.setTo(0);
|
||||
Mat_<double> I(num_images, num_images); I.setTo(0);
|
||||
|
||||
//Rect dst_roi = resultRoi(corners, images);
|
||||
Mat subimg1, subimg2;
|
||||
Mat_<uchar> submask1, submask2, intersect;
|
||||
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
{
|
||||
for (int j = i; j < num_images; ++j)
|
||||
{
|
||||
Rect roi;
|
||||
if (overlapRoi(corners[i], corners[j], images[i].size(), images[j].size(), roi))
|
||||
{
|
||||
subimg1 = images[i](Rect(roi.tl() - corners[i], roi.br() - corners[i]));
|
||||
subimg2 = images[j](Rect(roi.tl() - corners[j], roi.br() - corners[j]));
|
||||
|
||||
submask1 = masks[i].first(Rect(roi.tl() - corners[i], roi.br() - corners[i]));
|
||||
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));
|
||||
|
||||
double Isum1 = 0, Isum2 = 0;
|
||||
for (int y = 0; y < roi.height; ++y)
|
||||
{
|
||||
const Point3_<uchar>* r1 = subimg1.ptr<Point3_<uchar> >(y);
|
||||
const Point3_<uchar>* r2 = subimg2.ptr<Point3_<uchar> >(y);
|
||||
for (int x = 0; x < roi.width; ++x)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
I(i, j) = Isum1 / N(i, j);
|
||||
I(j, i) = Isum2 / N(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double alpha = 0.01;
|
||||
double beta = 100;
|
||||
|
||||
Mat_<double> A(num_images, num_images); A.setTo(0);
|
||||
Mat_<double> b(num_images, 1); b.setTo(0);
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
{
|
||||
for (int j = 0; j < num_images; ++j)
|
||||
{
|
||||
b(i, 0) += beta * N(i, j);
|
||||
A(i, i) += beta * N(i, j);
|
||||
if (j == i) continue;
|
||||
A(i, i) += 2 * alpha * I(i, j) * I(i, j) * N(i, j);
|
||||
A(i, j) -= 2 * alpha * I(i, j) * I(j, i) * N(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
solve(A, b, gains_);
|
||||
|
||||
LOGLN("Exposure compensation, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||
}
|
||||
|
||||
|
||||
void GainCompensator::apply(int index, Point /*corner*/, Mat &image, const Mat &/*mask*/)
|
||||
{
|
||||
image *= gains_(index, 0);
|
||||
}
|
||||
|
||||
|
||||
vector<double> GainCompensator::gains() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
// Construct blocks for gain compensator
|
||||
for (int img_idx = 0; img_idx < num_images; ++img_idx)
|
||||
{
|
||||
Size bl_per_img((images[img_idx].cols + bl_width_ - 1) / bl_width_,
|
||||
(images[img_idx].rows + bl_height_ - 1) / bl_height_);
|
||||
int bl_width = (images[img_idx].cols + bl_per_img.width - 1) / bl_per_img.width;
|
||||
int bl_height = (images[img_idx].rows + bl_per_img.height - 1) / bl_per_img.height;
|
||||
bl_per_imgs[img_idx] = bl_per_img;
|
||||
for (int by = 0; by < bl_per_img.height; ++by)
|
||||
{
|
||||
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));
|
||||
|
||||
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)),
|
||||
masks[img_idx].second));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GainCompensator compensator;
|
||||
compensator.feed(block_corners, block_images, block_masks);
|
||||
vector<double> gains = compensator.gains();
|
||||
gain_maps_.resize(num_images);
|
||||
|
||||
Mat_<float> ker(1, 3);
|
||||
ker(0,0) = 0.25; ker(0,1) = 0.5; ker(0,2) = 0.25;
|
||||
|
||||
int bl_idx = 0;
|
||||
for (int img_idx = 0; img_idx < num_images; ++img_idx)
|
||||
{
|
||||
Size bl_per_img = bl_per_imgs[img_idx];
|
||||
gain_maps_[img_idx].create(bl_per_img);
|
||||
|
||||
for (int by = 0; by < bl_per_img.height; ++by)
|
||||
for (int bx = 0; bx < bl_per_img.width; ++bx, ++bl_idx)
|
||||
gain_maps_[img_idx](by, bx) = static_cast<float>(gains[bl_idx]);
|
||||
|
||||
sepFilter2D(gain_maps_[img_idx], gain_maps_[img_idx], CV_32F, ker, ker);
|
||||
sepFilter2D(gain_maps_[img_idx], gain_maps_[img_idx], CV_32F, ker, ker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlocksGainCompensator::apply(int index, Point /*corner*/, Mat &image, const Mat &/*mask*/)
|
||||
{
|
||||
CV_Assert(image.type() == CV_8UC3);
|
||||
|
||||
Mat_<float> gain_map;
|
||||
if (gain_maps_[index].size() == image.size())
|
||||
gain_map = gain_maps_[index];
|
||||
else
|
||||
resize(gain_maps_[index], gain_map, image.size(), 0, 0, INTER_LINEAR);
|
||||
|
||||
for (int y = 0; y < image.rows; ++y)
|
||||
{
|
||||
const float* gain_row = gain_map.ptr<float>(y);
|
||||
Point3_<uchar>* row = image.ptr<Point3_<uchar> >(y);
|
||||
for (int x = 0; x < image.cols; ++x)
|
||||
{
|
||||
row[x].x = saturate_cast<uchar>(row[x].x * gain_row[x]);
|
||||
row[x].y = saturate_cast<uchar>(row[x].y * gain_row[x]);
|
||||
row[x].z = saturate_cast<uchar>(row[x].z * gain_row[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
Ptr<ExposureCompensator> ExposureCompensator::createDefault(int type)
|
||||
{
|
||||
if (type == NO)
|
||||
return new NoExposureCompensator();
|
||||
if (type == GAIN)
|
||||
return new GainCompensator();
|
||||
if (type == GAIN_BLOCKS)
|
||||
return new BlocksGainCompensator();
|
||||
CV_Error(CV_StsBadArg, "unsupported exposure compensation method");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void ExposureCompensator::feed(const vector<Point> &corners, const vector<Mat> &images,
|
||||
const vector<Mat> &masks)
|
||||
{
|
||||
vector<pair<Mat,uchar> > level_masks;
|
||||
for (size_t i = 0; i < masks.size(); ++i)
|
||||
level_masks.push_back(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)
|
||||
{
|
||||
LOGLN("Exposure compensation...");
|
||||
#if ENABLE_LOG
|
||||
int64 t = getTickCount();
|
||||
#endif
|
||||
|
||||
CV_Assert(corners.size() == images.size() && images.size() == masks.size());
|
||||
|
||||
const int num_images = static_cast<int>(images.size());
|
||||
Mat_<int> N(num_images, num_images); N.setTo(0);
|
||||
Mat_<double> I(num_images, num_images); I.setTo(0);
|
||||
|
||||
//Rect dst_roi = resultRoi(corners, images);
|
||||
Mat subimg1, subimg2;
|
||||
Mat_<uchar> submask1, submask2, intersect;
|
||||
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
{
|
||||
for (int j = i; j < num_images; ++j)
|
||||
{
|
||||
Rect roi;
|
||||
if (overlapRoi(corners[i], corners[j], images[i].size(), images[j].size(), roi))
|
||||
{
|
||||
subimg1 = images[i](Rect(roi.tl() - corners[i], roi.br() - corners[i]));
|
||||
subimg2 = images[j](Rect(roi.tl() - corners[j], roi.br() - corners[j]));
|
||||
|
||||
submask1 = masks[i].first(Rect(roi.tl() - corners[i], roi.br() - corners[i]));
|
||||
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));
|
||||
|
||||
double Isum1 = 0, Isum2 = 0;
|
||||
for (int y = 0; y < roi.height; ++y)
|
||||
{
|
||||
const Point3_<uchar>* r1 = subimg1.ptr<Point3_<uchar> >(y);
|
||||
const Point3_<uchar>* r2 = subimg2.ptr<Point3_<uchar> >(y);
|
||||
for (int x = 0; x < roi.width; ++x)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
I(i, j) = Isum1 / N(i, j);
|
||||
I(j, i) = Isum2 / N(i, j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double alpha = 0.01;
|
||||
double beta = 100;
|
||||
|
||||
Mat_<double> A(num_images, num_images); A.setTo(0);
|
||||
Mat_<double> b(num_images, 1); b.setTo(0);
|
||||
for (int i = 0; i < num_images; ++i)
|
||||
{
|
||||
for (int j = 0; j < num_images; ++j)
|
||||
{
|
||||
b(i, 0) += beta * N(i, j);
|
||||
A(i, i) += beta * N(i, j);
|
||||
if (j == i) continue;
|
||||
A(i, i) += 2 * alpha * I(i, j) * I(i, j) * N(i, j);
|
||||
A(i, j) -= 2 * alpha * I(i, j) * I(j, i) * N(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
solve(A, b, gains_);
|
||||
|
||||
LOGLN("Exposure compensation, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||
}
|
||||
|
||||
|
||||
void GainCompensator::apply(int index, Point /*corner*/, Mat &image, const Mat &/*mask*/)
|
||||
{
|
||||
image *= gains_(index, 0);
|
||||
}
|
||||
|
||||
|
||||
vector<double> GainCompensator::gains() const
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
// Construct blocks for gain compensator
|
||||
for (int img_idx = 0; img_idx < num_images; ++img_idx)
|
||||
{
|
||||
Size bl_per_img((images[img_idx].cols + bl_width_ - 1) / bl_width_,
|
||||
(images[img_idx].rows + bl_height_ - 1) / bl_height_);
|
||||
int bl_width = (images[img_idx].cols + bl_per_img.width - 1) / bl_per_img.width;
|
||||
int bl_height = (images[img_idx].rows + bl_per_img.height - 1) / bl_per_img.height;
|
||||
bl_per_imgs[img_idx] = bl_per_img;
|
||||
for (int by = 0; by < bl_per_img.height; ++by)
|
||||
{
|
||||
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));
|
||||
|
||||
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)),
|
||||
masks[img_idx].second));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GainCompensator compensator;
|
||||
compensator.feed(block_corners, block_images, block_masks);
|
||||
vector<double> gains = compensator.gains();
|
||||
gain_maps_.resize(num_images);
|
||||
|
||||
Mat_<float> ker(1, 3);
|
||||
ker(0,0) = 0.25; ker(0,1) = 0.5; ker(0,2) = 0.25;
|
||||
|
||||
int bl_idx = 0;
|
||||
for (int img_idx = 0; img_idx < num_images; ++img_idx)
|
||||
{
|
||||
Size bl_per_img = bl_per_imgs[img_idx];
|
||||
gain_maps_[img_idx].create(bl_per_img);
|
||||
|
||||
for (int by = 0; by < bl_per_img.height; ++by)
|
||||
for (int bx = 0; bx < bl_per_img.width; ++bx, ++bl_idx)
|
||||
gain_maps_[img_idx](by, bx) = static_cast<float>(gains[bl_idx]);
|
||||
|
||||
sepFilter2D(gain_maps_[img_idx], gain_maps_[img_idx], CV_32F, ker, ker);
|
||||
sepFilter2D(gain_maps_[img_idx], gain_maps_[img_idx], CV_32F, ker, ker);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BlocksGainCompensator::apply(int index, Point /*corner*/, Mat &image, const Mat &/*mask*/)
|
||||
{
|
||||
CV_Assert(image.type() == CV_8UC3);
|
||||
|
||||
Mat_<float> gain_map;
|
||||
if (gain_maps_[index].size() == image.size())
|
||||
gain_map = gain_maps_[index];
|
||||
else
|
||||
resize(gain_maps_[index], gain_map, image.size(), 0, 0, INTER_LINEAR);
|
||||
|
||||
for (int y = 0; y < image.rows; ++y)
|
||||
{
|
||||
const float* gain_row = gain_map.ptr<float>(y);
|
||||
Point3_<uchar>* row = image.ptr<Point3_<uchar> >(y);
|
||||
for (int x = 0; x < image.cols; ++x)
|
||||
{
|
||||
row[x].x = saturate_cast<uchar>(row[x].x * gain_row[x]);
|
||||
row[x].y = saturate_cast<uchar>(row[x].y * gain_row[x]);
|
||||
row[x].z = saturate_cast<uchar>(row[x].z * gain_row[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,43 +1,43 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
@@ -1,83 +1,83 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_STITCHING_PRECOMP_H__
|
||||
#define __OPENCV_STITCHING_PRECOMP_H__
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <set>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#include "opencv2/stitching/stitcher.hpp"
|
||||
#include "opencv2/stitching/detail/autocalib.hpp"
|
||||
#include "opencv2/stitching/detail/blenders.hpp"
|
||||
#include "opencv2/stitching/detail/camera.hpp"
|
||||
#include "opencv2/stitching/detail/exposure_compensate.hpp"
|
||||
#include "opencv2/stitching/detail/matchers.hpp"
|
||||
#include "opencv2/stitching/detail/motion_estimators.hpp"
|
||||
#include "opencv2/stitching/detail/seam_finders.hpp"
|
||||
#include "opencv2/stitching/detail/util.hpp"
|
||||
#include "opencv2/stitching/detail/warpers.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
# include "opencv2/gpu/gpu.hpp"
|
||||
#endif
|
||||
|
||||
#include "../../imgproc/src/gcgraph.hpp"
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# include "opencv2/stitching/stitching_tegra.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_STITCHING_PRECOMP_H__
|
||||
#define __OPENCV_STITCHING_PRECOMP_H__
|
||||
|
||||
#ifdef HAVE_CVCONFIG_H
|
||||
#include "cvconfig.h"
|
||||
#endif
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
#include <set>
|
||||
#include <functional>
|
||||
#include <sstream>
|
||||
#include <cmath>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core/internal.hpp"
|
||||
#include "opencv2/stitching/stitcher.hpp"
|
||||
#include "opencv2/stitching/detail/autocalib.hpp"
|
||||
#include "opencv2/stitching/detail/blenders.hpp"
|
||||
#include "opencv2/stitching/detail/camera.hpp"
|
||||
#include "opencv2/stitching/detail/exposure_compensate.hpp"
|
||||
#include "opencv2/stitching/detail/matchers.hpp"
|
||||
#include "opencv2/stitching/detail/motion_estimators.hpp"
|
||||
#include "opencv2/stitching/detail/seam_finders.hpp"
|
||||
#include "opencv2/stitching/detail/util.hpp"
|
||||
#include "opencv2/stitching/detail/warpers.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include "opencv2/calib3d/calib3d.hpp"
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
# include "opencv2/gpu/gpu.hpp"
|
||||
#endif
|
||||
|
||||
#include "../../imgproc/src/gcgraph.hpp"
|
||||
|
||||
#ifdef HAVE_TEGRA_OPTIMIZATION
|
||||
# include "opencv2/stitching/stitching_tegra.hpp"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,175 +1,175 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
void DisjointSets::createOneElemSets(int n)
|
||||
{
|
||||
rank_.assign(n, 0);
|
||||
size.assign(n, 1);
|
||||
parent.resize(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
parent[i] = i;
|
||||
}
|
||||
|
||||
|
||||
int DisjointSets::findSetByElem(int elem)
|
||||
{
|
||||
int set = elem;
|
||||
while (set != parent[set])
|
||||
set = parent[set];
|
||||
int next;
|
||||
while (elem != parent[elem])
|
||||
{
|
||||
next = parent[elem];
|
||||
parent[elem] = set;
|
||||
elem = next;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
int DisjointSets::mergeSets(int set1, int set2)
|
||||
{
|
||||
if (rank_[set1] < rank_[set2])
|
||||
{
|
||||
parent[set1] = set2;
|
||||
size[set2] += size[set1];
|
||||
return set2;
|
||||
}
|
||||
if (rank_[set2] < rank_[set1])
|
||||
{
|
||||
parent[set2] = set1;
|
||||
size[set1] += size[set2];
|
||||
return set1;
|
||||
}
|
||||
parent[set1] = set2;
|
||||
rank_[set2]++;
|
||||
size[set2] += size[set1];
|
||||
return set2;
|
||||
}
|
||||
|
||||
|
||||
void Graph::addEdge(int from, int to, float weight)
|
||||
{
|
||||
edges_[from].push_back(GraphEdge(from, to, 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);
|
||||
if (x_tl < x_br && y_tl < y_br)
|
||||
{
|
||||
roi = Rect(x_tl, y_tl, x_br - x_tl, y_br - y_tl);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Rect resultRoi(const vector<Point> &corners, const vector<Mat> &images)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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());
|
||||
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);
|
||||
}
|
||||
return Rect(tl, br);
|
||||
}
|
||||
|
||||
|
||||
Point resultTl(const vector<Point> &corners)
|
||||
{
|
||||
Point tl(numeric_limits<int>::max(), 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);
|
||||
}
|
||||
return tl;
|
||||
}
|
||||
|
||||
|
||||
void selectRandomSubset(int count, int size, vector<int> &subset)
|
||||
{
|
||||
subset.clear();
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
if (randu<int>() % (size - i) < count)
|
||||
{
|
||||
subset.push_back(i);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int& stitchingLogLevel()
|
||||
{
|
||||
static int _log_level=1;
|
||||
return _log_level;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
void DisjointSets::createOneElemSets(int n)
|
||||
{
|
||||
rank_.assign(n, 0);
|
||||
size.assign(n, 1);
|
||||
parent.resize(n);
|
||||
for (int i = 0; i < n; ++i)
|
||||
parent[i] = i;
|
||||
}
|
||||
|
||||
|
||||
int DisjointSets::findSetByElem(int elem)
|
||||
{
|
||||
int set = elem;
|
||||
while (set != parent[set])
|
||||
set = parent[set];
|
||||
int next;
|
||||
while (elem != parent[elem])
|
||||
{
|
||||
next = parent[elem];
|
||||
parent[elem] = set;
|
||||
elem = next;
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
|
||||
int DisjointSets::mergeSets(int set1, int set2)
|
||||
{
|
||||
if (rank_[set1] < rank_[set2])
|
||||
{
|
||||
parent[set1] = set2;
|
||||
size[set2] += size[set1];
|
||||
return set2;
|
||||
}
|
||||
if (rank_[set2] < rank_[set1])
|
||||
{
|
||||
parent[set2] = set1;
|
||||
size[set1] += size[set2];
|
||||
return set1;
|
||||
}
|
||||
parent[set1] = set2;
|
||||
rank_[set2]++;
|
||||
size[set2] += size[set1];
|
||||
return set2;
|
||||
}
|
||||
|
||||
|
||||
void Graph::addEdge(int from, int to, float weight)
|
||||
{
|
||||
edges_[from].push_back(GraphEdge(from, to, 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);
|
||||
if (x_tl < x_br && y_tl < y_br)
|
||||
{
|
||||
roi = Rect(x_tl, y_tl, x_br - x_tl, y_br - y_tl);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Rect resultRoi(const vector<Point> &corners, const vector<Mat> &images)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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());
|
||||
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);
|
||||
}
|
||||
return Rect(tl, br);
|
||||
}
|
||||
|
||||
|
||||
Point resultTl(const vector<Point> &corners)
|
||||
{
|
||||
Point tl(numeric_limits<int>::max(), 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);
|
||||
}
|
||||
return tl;
|
||||
}
|
||||
|
||||
|
||||
void selectRandomSubset(int count, int size, vector<int> &subset)
|
||||
{
|
||||
subset.clear();
|
||||
for (int i = 0; i < size; ++i)
|
||||
{
|
||||
if (randu<int>() % (size - i) < count)
|
||||
{
|
||||
subset.push_back(i);
|
||||
count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int& stitchingLogLevel()
|
||||
{
|
||||
static int _log_level=1;
|
||||
return _log_level;
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
@@ -1,343 +1,343 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
void ProjectorBase::setCameraParams(const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
CV_Assert(K.size() == Size(3, 3) && K.type() == CV_32F);
|
||||
CV_Assert(R.size() == Size(3, 3) && R.type() == CV_32F);
|
||||
CV_Assert((T.size() == Size(1, 3) || T.size() == Size(3, 1)) && T.type() == CV_32F);
|
||||
|
||||
Mat_<float> K_(K);
|
||||
k[0] = K_(0,0); k[1] = K_(0,1); k[2] = K_(0,2);
|
||||
k[3] = K_(1,0); k[4] = K_(1,1); k[5] = K_(1,2);
|
||||
k[6] = K_(2,0); k[7] = K_(2,1); k[8] = K_(2,2);
|
||||
|
||||
Mat_<float> Rinv = R.t();
|
||||
rinv[0] = Rinv(0,0); rinv[1] = Rinv(0,1); rinv[2] = Rinv(0,2);
|
||||
rinv[3] = Rinv(1,0); rinv[4] = Rinv(1,1); rinv[5] = Rinv(1,2);
|
||||
rinv[6] = Rinv(2,0); rinv[7] = Rinv(2,1); rinv[8] = Rinv(2,2);
|
||||
|
||||
Mat_<float> R_Kinv = R * K.inv();
|
||||
r_kinv[0] = R_Kinv(0,0); r_kinv[1] = R_Kinv(0,1); r_kinv[2] = R_Kinv(0,2);
|
||||
r_kinv[3] = R_Kinv(1,0); r_kinv[4] = R_Kinv(1,1); r_kinv[5] = R_Kinv(1,2);
|
||||
r_kinv[6] = R_Kinv(2,0); r_kinv[7] = R_Kinv(2,1); r_kinv[8] = R_Kinv(2,2);
|
||||
|
||||
Mat_<float> K_Rinv = K * Rinv;
|
||||
k_rinv[0] = K_Rinv(0,0); k_rinv[1] = K_Rinv(0,1); k_rinv[2] = K_Rinv(0,2);
|
||||
k_rinv[3] = K_Rinv(1,0); k_rinv[4] = K_Rinv(1,1); k_rinv[5] = K_Rinv(1,2);
|
||||
k_rinv[6] = K_Rinv(2,0); k_rinv[7] = K_Rinv(2,1); k_rinv[8] = K_Rinv(2,2);
|
||||
|
||||
Mat_<float> T_(T.reshape(0, 3));
|
||||
t[0] = T_(0,0); t[1] = T_(1,0); t[2] = T_(2,0);
|
||||
}
|
||||
|
||||
|
||||
Point2f PlaneWarper::warpPoint(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
Point2f uv;
|
||||
projector_.mapForward(pt.x, pt.y, uv.x, uv.y);
|
||||
return uv;
|
||||
}
|
||||
|
||||
|
||||
Rect PlaneWarper::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
|
||||
ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
|
||||
|
||||
float x, y;
|
||||
for (int v = dst_tl.y; v <= dst_br.y; ++v)
|
||||
{
|
||||
for (int u = dst_tl.x; u <= dst_br.x; ++u)
|
||||
{
|
||||
projector_.mapBackward(static_cast<float>(u), static_cast<float>(v), x, y);
|
||||
xmap.at<float>(v - dst_tl.y, u - dst_tl.x) = x;
|
||||
ymap.at<float>(v - dst_tl.y, u - dst_tl.x) = y;
|
||||
}
|
||||
}
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
|
||||
Point PlaneWarper::warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
Mat &dst)
|
||||
{
|
||||
Mat xmap, ymap;
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, T, xmap, ymap);
|
||||
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
remap(src, dst, xmap, ymap, interp_mode, border_mode);
|
||||
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
|
||||
Rect PlaneWarper::warpRoi(Size src_size, const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
return Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1));
|
||||
}
|
||||
|
||||
|
||||
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 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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
dst_tl.x = static_cast<int>(tl_uf);
|
||||
dst_tl.y = static_cast<int>(tl_vf);
|
||||
dst_br.x = static_cast<int>(br_uf);
|
||||
dst_br.y = static_cast<int>(br_vf);
|
||||
}
|
||||
|
||||
|
||||
void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
detectResultRoiByBorder(src_size, dst_tl, dst_br);
|
||||
|
||||
float tl_uf = static_cast<float>(dst_tl.x);
|
||||
float tl_vf = static_cast<float>(dst_tl.y);
|
||||
float br_uf = static_cast<float>(dst_br.x);
|
||||
float br_vf = static_cast<float>(dst_br.y);
|
||||
|
||||
float x = projector_.rinv[1];
|
||||
float y = projector_.rinv[4];
|
||||
float z = projector_.rinv[7];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
x = projector_.rinv[1];
|
||||
y = -projector_.rinv[4];
|
||||
z = projector_.rinv[7];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
dst_tl.x = static_cast<int>(tl_uf);
|
||||
dst_tl.y = static_cast<int>(tl_vf);
|
||||
dst_br.x = static_cast<int>(br_uf);
|
||||
dst_br.y = static_cast<int>(br_vf);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap);
|
||||
}
|
||||
|
||||
Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpPlaneMaps(src_size, Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)),
|
||||
K, R, T, projector_.scale, xmap, ymap);
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, dst);
|
||||
}
|
||||
|
||||
|
||||
Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, T, d_xmap_, d_ymap_);
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
|
||||
Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpSphericalMaps(src_size, Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)),
|
||||
K, R, projector_.scale, xmap, ymap);
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
|
||||
Point SphericalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
|
||||
Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpCylindricalMaps(src_size, Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)),
|
||||
K, R, projector_.scale, xmap, ymap);
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
|
||||
Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
|
||||
return dst_roi.tl();
|
||||
}
|
||||
#endif
|
||||
|
||||
void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
detectResultRoiByBorder(src_size, dst_tl, dst_br);
|
||||
|
||||
float tl_uf = static_cast<float>(dst_tl.x);
|
||||
float tl_vf = static_cast<float>(dst_tl.y);
|
||||
float br_uf = static_cast<float>(dst_br.x);
|
||||
float br_vf = static_cast<float>(dst_br.y);
|
||||
|
||||
float x = projector_.rinv[0];
|
||||
float y = projector_.rinv[3];
|
||||
float z = projector_.rinv[6];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
x = projector_.rinv[0];
|
||||
y = -projector_.rinv[3];
|
||||
z = projector_.rinv[6];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
dst_tl.x = static_cast<int>(tl_uf);
|
||||
dst_tl.y = static_cast<int>(tl_vf);
|
||||
dst_br.x = static_cast<int>(br_uf);
|
||||
dst_br.y = static_cast<int>(br_vf);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#include "precomp.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace cv {
|
||||
namespace detail {
|
||||
|
||||
void ProjectorBase::setCameraParams(const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
CV_Assert(K.size() == Size(3, 3) && K.type() == CV_32F);
|
||||
CV_Assert(R.size() == Size(3, 3) && R.type() == CV_32F);
|
||||
CV_Assert((T.size() == Size(1, 3) || T.size() == Size(3, 1)) && T.type() == CV_32F);
|
||||
|
||||
Mat_<float> K_(K);
|
||||
k[0] = K_(0,0); k[1] = K_(0,1); k[2] = K_(0,2);
|
||||
k[3] = K_(1,0); k[4] = K_(1,1); k[5] = K_(1,2);
|
||||
k[6] = K_(2,0); k[7] = K_(2,1); k[8] = K_(2,2);
|
||||
|
||||
Mat_<float> Rinv = R.t();
|
||||
rinv[0] = Rinv(0,0); rinv[1] = Rinv(0,1); rinv[2] = Rinv(0,2);
|
||||
rinv[3] = Rinv(1,0); rinv[4] = Rinv(1,1); rinv[5] = Rinv(1,2);
|
||||
rinv[6] = Rinv(2,0); rinv[7] = Rinv(2,1); rinv[8] = Rinv(2,2);
|
||||
|
||||
Mat_<float> R_Kinv = R * K.inv();
|
||||
r_kinv[0] = R_Kinv(0,0); r_kinv[1] = R_Kinv(0,1); r_kinv[2] = R_Kinv(0,2);
|
||||
r_kinv[3] = R_Kinv(1,0); r_kinv[4] = R_Kinv(1,1); r_kinv[5] = R_Kinv(1,2);
|
||||
r_kinv[6] = R_Kinv(2,0); r_kinv[7] = R_Kinv(2,1); r_kinv[8] = R_Kinv(2,2);
|
||||
|
||||
Mat_<float> K_Rinv = K * Rinv;
|
||||
k_rinv[0] = K_Rinv(0,0); k_rinv[1] = K_Rinv(0,1); k_rinv[2] = K_Rinv(0,2);
|
||||
k_rinv[3] = K_Rinv(1,0); k_rinv[4] = K_Rinv(1,1); k_rinv[5] = K_Rinv(1,2);
|
||||
k_rinv[6] = K_Rinv(2,0); k_rinv[7] = K_Rinv(2,1); k_rinv[8] = K_Rinv(2,2);
|
||||
|
||||
Mat_<float> T_(T.reshape(0, 3));
|
||||
t[0] = T_(0,0); t[1] = T_(1,0); t[2] = T_(2,0);
|
||||
}
|
||||
|
||||
|
||||
Point2f PlaneWarper::warpPoint(const Point2f &pt, const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
Point2f uv;
|
||||
projector_.mapForward(pt.x, pt.y, uv.x, uv.y);
|
||||
return uv;
|
||||
}
|
||||
|
||||
|
||||
Rect PlaneWarper::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, Mat &xmap, Mat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
xmap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
|
||||
ymap.create(dst_br.y - dst_tl.y + 1, dst_br.x - dst_tl.x + 1, CV_32F);
|
||||
|
||||
float x, y;
|
||||
for (int v = dst_tl.y; v <= dst_br.y; ++v)
|
||||
{
|
||||
for (int u = dst_tl.x; u <= dst_br.x; ++u)
|
||||
{
|
||||
projector_.mapBackward(static_cast<float>(u), static_cast<float>(v), x, y);
|
||||
xmap.at<float>(v - dst_tl.y, u - dst_tl.x) = x;
|
||||
ymap.at<float>(v - dst_tl.y, u - dst_tl.x) = y;
|
||||
}
|
||||
}
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
|
||||
Point PlaneWarper::warp(const Mat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
Mat &dst)
|
||||
{
|
||||
Mat xmap, ymap;
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, T, xmap, ymap);
|
||||
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
remap(src, dst, xmap, ymap, interp_mode, border_mode);
|
||||
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
|
||||
Rect PlaneWarper::warpRoi(Size src_size, const Mat &K, const Mat &R, const Mat &T)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
return Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1));
|
||||
}
|
||||
|
||||
|
||||
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 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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
dst_tl.x = static_cast<int>(tl_uf);
|
||||
dst_tl.y = static_cast<int>(tl_vf);
|
||||
dst_br.x = static_cast<int>(br_uf);
|
||||
dst_br.y = static_cast<int>(br_vf);
|
||||
}
|
||||
|
||||
|
||||
void SphericalWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
detectResultRoiByBorder(src_size, dst_tl, dst_br);
|
||||
|
||||
float tl_uf = static_cast<float>(dst_tl.x);
|
||||
float tl_vf = static_cast<float>(dst_tl.y);
|
||||
float br_uf = static_cast<float>(dst_br.x);
|
||||
float br_vf = static_cast<float>(dst_br.y);
|
||||
|
||||
float x = projector_.rinv[1];
|
||||
float y = projector_.rinv[4];
|
||||
float z = projector_.rinv[7];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
x = projector_.rinv[1];
|
||||
y = -projector_.rinv[4];
|
||||
z = projector_.rinv[7];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
dst_tl.x = static_cast<int>(tl_uf);
|
||||
dst_tl.y = static_cast<int>(tl_vf);
|
||||
dst_br.x = static_cast<int>(br_uf);
|
||||
dst_br.y = static_cast<int>(br_vf);
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_OPENCV_GPU
|
||||
Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
return buildMaps(src_size, K, R, Mat::zeros(3, 1, CV_32F), xmap, ymap);
|
||||
}
|
||||
|
||||
Rect PlaneWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, const Mat &T, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R, T);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpPlaneMaps(src_size, Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)),
|
||||
K, R, T, projector_.scale, xmap, ymap);
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
return warp(src, K, R, Mat::zeros(3, 1, CV_32F), interp_mode, border_mode, dst);
|
||||
}
|
||||
|
||||
|
||||
Point PlaneWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, const Mat &T, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, T, d_xmap_, d_ymap_);
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
|
||||
Rect SphericalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpSphericalMaps(src_size, Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)),
|
||||
K, R, projector_.scale, xmap, ymap);
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
|
||||
Point SphericalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
|
||||
return dst_roi.tl();
|
||||
}
|
||||
|
||||
|
||||
Rect CylindricalWarperGpu::buildMaps(Size src_size, const Mat &K, const Mat &R, gpu::GpuMat &xmap, gpu::GpuMat &ymap)
|
||||
{
|
||||
projector_.setCameraParams(K, R);
|
||||
|
||||
Point dst_tl, dst_br;
|
||||
detectResultRoi(src_size, dst_tl, dst_br);
|
||||
|
||||
gpu::buildWarpCylindricalMaps(src_size, Rect(dst_tl, Point(dst_br.x + 1, dst_br.y + 1)),
|
||||
K, R, projector_.scale, xmap, ymap);
|
||||
|
||||
return Rect(dst_tl, dst_br);
|
||||
}
|
||||
|
||||
|
||||
Point CylindricalWarperGpu::warp(const gpu::GpuMat &src, const Mat &K, const Mat &R, int interp_mode, int border_mode,
|
||||
gpu::GpuMat &dst)
|
||||
{
|
||||
Rect dst_roi = buildMaps(src.size(), K, R, d_xmap_, d_ymap_);
|
||||
dst.create(dst_roi.height + 1, dst_roi.width + 1, src.type());
|
||||
gpu::remap(src, dst, d_xmap_, d_ymap_, interp_mode, border_mode);
|
||||
return dst_roi.tl();
|
||||
}
|
||||
#endif
|
||||
|
||||
void SphericalPortraitWarper::detectResultRoi(Size src_size, Point &dst_tl, Point &dst_br)
|
||||
{
|
||||
detectResultRoiByBorder(src_size, dst_tl, dst_br);
|
||||
|
||||
float tl_uf = static_cast<float>(dst_tl.x);
|
||||
float tl_vf = static_cast<float>(dst_tl.y);
|
||||
float br_uf = static_cast<float>(dst_br.x);
|
||||
float br_vf = static_cast<float>(dst_br.y);
|
||||
|
||||
float x = projector_.rinv[0];
|
||||
float y = projector_.rinv[3];
|
||||
float z = projector_.rinv[6];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
x = projector_.rinv[0];
|
||||
y = -projector_.rinv[3];
|
||||
z = projector_.rinv[6];
|
||||
if (y > 0.f)
|
||||
{
|
||||
float x_ = (projector_.k[0] * x + projector_.k[1] * y) / z + projector_.k[2];
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
dst_tl.x = static_cast<int>(tl_uf);
|
||||
dst_tl.y = static_cast<int>(tl_vf);
|
||||
dst_br.x = static_cast<int>(br_uf);
|
||||
dst_br.y = static_cast<int>(br_vf);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cv
|
||||
|
Reference in New Issue
Block a user