blender/extern/libmv/third_party/ssba/Geometry/v3d_distortion.h

98 lines
3.2 KiB
C
Raw Normal View History

Camera tracking integration =========================== Commiting camera tracking integration gsoc project into trunk. This commit includes: - Bundled version of libmv library (with some changes against official repo, re-sync with libmv repo a bit later) - New datatype ID called MovieClip which is optimized to work with movie clips (both of movie files and image sequences) and doing camera/motion tracking operations. - New editor called Clip Editor which is currently used for motion/tracking stuff only, but which can be easily extended to work with masks too. This editor supports: * Loading movie files/image sequences * Build proxies with different size for loaded movie clip, also supports building undistorted proxies to increase speed of playback in undistorted mode. * Manual lens distortion mode calibration using grid and grease pencil * Supervised 2D tracking using two different algorithms KLT and SAD. * Basic algorithm for feature detection * Camera motion solving. scene orientation - New constraints to "link" scene objects with solved motions from clip: * Follow Track (make object follow 2D motion of track with given name or parent object to reconstructed 3D position of track) * Camera Solver to make camera moving in the same way as reconstructed camera This commit NOT includes changes from tomato branch: - New nodes (they'll be commited as separated patch) - Automatic image offset guessing for image input node and image editor (need to do more tests and gather more feedback) - Code cleanup in libmv-capi. It's not so critical cleanup, just increasing readability and understanadability of code. Better to make this chaneg when Keir will finish his current patch. More details about this project can be found on this page: http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2011 Further development of small features would be done in trunk, bigger/experimental features would first be implemented in tomato branch.
2011-11-07 12:55:18 +00:00
// -*- C++ -*-
/*
Copyright (c) 2008 University of North Carolina at Chapel Hill
This file is part of SSBA (Simple Sparse Bundle Adjustment).
SSBA is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.
SSBA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
details.
You should have received a copy of the GNU Lesser General Public License along
with SSBA. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef V3D_DISTORTION_H
#define V3D_DISTORTION_H
#include "Math/v3d_linear.h"
#include "Math/v3d_linear_utils.h"
namespace V3D
{
struct StdDistortionFunction
{
double k1, k2, p1, p2;
StdDistortionFunction()
: k1(0), k2(0), p1(0), p2(0)
{ }
Vector2d operator()(Vector2d const& xu) const
{
double const r2 = xu[0]*xu[0] + xu[1]*xu[1];
double const r4 = r2*r2;
double const kr = 1 + k1*r2 + k2*r4;
Vector2d xd;
xd[0] = kr * xu[0] + 2*p1*xu[0]*xu[1] + p2*(r2 + 2*xu[0]*xu[0]);
xd[1] = kr * xu[1] + 2*p2*xu[0]*xu[1] + p1*(r2 + 2*xu[1]*xu[1]);
return xd;
}
Matrix2x2d derivativeWrtRadialParameters(Vector2d const& xu) const
{
double const r2 = xu[0]*xu[0] + xu[1]*xu[1];
double const r4 = r2*r2;
//double const kr = 1 + k1*r2 + k2*r4;
Matrix2x2d deriv;
deriv[0][0] = xu[0] * r2; // d xd/d k1
deriv[0][1] = xu[0] * r4; // d xd/d k2
deriv[1][0] = xu[1] * r2; // d yd/d k1
deriv[1][1] = xu[1] * r4; // d yd/d k2
return deriv;
}
Matrix2x2d derivativeWrtTangentialParameters(Vector2d const& xu) const
{
double const r2 = xu[0]*xu[0] + xu[1]*xu[1];
//double const r4 = r2*r2;
//double const kr = 1 + k1*r2 + k2*r4;
Matrix2x2d deriv;
deriv[0][0] = 2*xu[0]*xu[1]; // d xd/d p1
deriv[0][1] = r2 + 2*xu[0]*xu[0]; // d xd/d p2
deriv[1][0] = r2 + 2*xu[1]*xu[1]; // d yd/d p1
deriv[1][1] = deriv[0][0]; // d yd/d p2
return deriv;
}
Matrix2x2d derivativeWrtUndistortedPoint(Vector2d const& xu) const
{
double const r2 = xu[0]*xu[0] + xu[1]*xu[1];
double const r4 = r2*r2;
double const kr = 1 + k1*r2 + k2*r4;
double const dkr = 2*k1 + 4*k2*r2;
Matrix2x2d deriv;
deriv[0][0] = kr + xu[0] * xu[0] * dkr + 2*p1*xu[1] + 6*p2*xu[0]; // d xd/d xu
deriv[0][1] = xu[0] * xu[1] * dkr + 2*p1*xu[0] + 2*p2*xu[1]; // d xd/d yu
deriv[1][0] = deriv[0][1]; // d yd/d xu
deriv[1][1] = kr + xu[1] * xu[1] * dkr + 6*p1*xu[1] + 2*p2*xu[0]; // d yd/d yu
return deriv;
}
}; // end struct StdDistortionFunction
} // end namespace V3D
#endif