1 #ifndef _LOCALAFFINEFRAME_HH_
2 #define _LOCALAFFINEFRAME_HH_
4 #include <bias_config.h>
7 #include <Base/Common/XMLBase.hh>
10 #include <Base/Math/Vector.hh>
11 #include <Base/Math/Vector2.hh>
12 #include <Base/Geometry/HomgPoint2D.hh>
13 #include <Base/Image/ImageBase.hh>
14 #include <Base/Math/Matrix.hh>
15 #include <Base/Math/Matrix2x2.hh>
16 #include <Base/Common/CompareFloatingPoint.hh>
17 #include <Geometry/HMatrix.hh>
20 #define LAF_DEFAULT_UNCERTAINTY 1e-10
42 for (
unsigned int i=0; i<6; i++) Cov_[i][i] = LAF_DEFAULT_UNCERTAINTY;
77 const double *pd = A_.GetData();
89 SetFromVector(affineparams,
99 *pd++ = affineparams[0];
100 *pd++ = affineparams[1];
101 *pd++ = affineparams[2];
102 *pd++ = affineparams[3];
103 t_[0] = affineparams[4];
104 t_[1] = affineparams[5];
136 M[0][2] = -offset[0];
137 M[1][2] = -offset[1];
144 BIASASSERT(affineTransform.
num_rows()==3);
145 BIASASSERT(affineTransform.
num_cols()==3);
146 BIASASSERT(fabs(affineTransform[2][0])<1e-8);
147 BIASASSERT(fabs(affineTransform[2][1])<1e-8);
148 BIASASSERT(
BIAS::Equal(affineTransform[2][2],1.0));
149 A_[0][0] = affineTransform[0][0];
150 A_[0][1] = affineTransform[0][1];
151 A_[1][0] = affineTransform[1][0];
152 A_[1][1] = affineTransform[1][1];
153 t_[0] = affineTransform[0][2];
154 t_[1] = affineTransform[1][2];
161 for (
unsigned int i=0; i<6; i++) Cov_[i][i] = LAF_DEFAULT_UNCERTAINTY;
177 for (
unsigned int x=0; x<4; x++) {
182 for (
unsigned int y=x; y<4; y++) {
183 Cov_[y][x] = Cov_[x][y] = 0.5*(cov[y][x]+cov[x][y]);
194 for (
unsigned int x=0; x<4; x++) {
200 Cov_[4][4] = cov[0][0];
201 Cov_[4][5] = Cov_[5][4] = 0.5*(cov[1][0] + cov[0][1]);
202 Cov_[5][5] = cov[1][1];
211 bool setDefaultCov =
false)
const;
226 const double& positionCovScale = 1.0,
227 const unsigned int linethickness=1)
const;
232 unsigned int x0=0,
unsigned int y0=0)
const {
234 for (
int x=-5; x<=5; x++) {
235 for (
int y=-5; y<=5; y++) {
238 l = LocalToGlobal(l);
240 if ((l[0]>x0) && (l[1]>y0) && (l[0]<x0+width) && (l[1]<y0+height))
244 return double(count)/121.0;
247 #ifdef BIAS_HAVE_XML2
249 virtual int XMLGetClassName(std::string& TopLevelTag,
250 double& Version)
const;
253 virtual int XMLOut(
const xmlNodePtr Node,
BIAS::XMLIO& XMLObject)
const;
256 virtual int XMLIn(
const xmlNodePtr Node,
BIAS::XMLIO& XMLObject);
274 friend BIASGeometry_EXPORT std::ostream&
operator<<(std::ostream& os,
277 friend BIASGeometry_EXPORT std::istream&
operator>>(std::istream& is,
283 BIASGeometry_EXPORT std::ostream&
operator<<(std::ostream& os,
287 BIASGeometry_EXPORT std::istream&
operator>>(std::istream& is,
int Invert(Matrix2x2< T > &result) const
analyticaly inverts matrix
class HomgPoint2D describes a point with 2 degrees of freedom in projective coordinates.
BIAS::Vector2< double > t_
original image position
const LocalAffineFrame & operator=(const LocalAffineFrame &FP)
Subscript num_cols() const
a 3x3 Matrix describing projective transformations between planes
affine transformation of 2D image plane which relates image coordinate system and local affine featur...
const BIAS::Matrix< double > & GetCov() const
return 6x6 covariance
HomgPoint2D & Homogenize()
homogenize class data member elements to W==1 by divison by W
void SetA(const BIAS::Matrix2x2< double > &A, const BIAS::Matrix< double > &cov=BIAS::Matrix< double >(4, 4, BIAS::MatrixZero))
return affine matrix
BIAS::HomgPoint2D GlobalToLocal(const BIAS::HomgPoint2D &x) const
tranform a point in the image coordinate system into the feature coordinate system ...
void SetDefaultCov()
sets default nonzero cov
BIAS::HomgPoint2D LocalToGlobal(const BIAS::HomgPoint2D &x) const
tranform a point in the feature coordinate system into the iamge coordinate system ...
BIAS::Matrix2x2< double > A_
"orientation + area(detA) of feature" affine matrix which transforms all pixels of the unit feature (...
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
void SetFromVector(const BIAS::Vector< double > &affineparams)
set from a 6-vector (a11,a12,a21,a22,tx,ty), default cov
void SetFromMatrix(const BIAS::Matrix< double > &affineTransform)
construct from homography-style affine matrix (last row 0,0,1)
LocalAffineFrame(const LocalAffineFrame &FP)
const BIAS::Matrix2x2< double > & GetA() const
return affine matrix
void SetFromVector(const BIAS::Vector< double > &affineparams, const BIAS::Matrix< double > &cov)
set from 6-vector (a11,a12,a21,a22,tx,ty) with cov
void SetT(const BIAS::Vector2< double > &T, const BIAS::Matrix< double > &cov=BIAS::Matrix< double >(2, 2, BIAS::MatrixZero))
return offset
T * GetData()
get the pointer to the data array of the matrix (for faster direct memeory access) ...
Base class with interface for xml output.
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
BIAS::Matrix< double > GetAsMatrix() const
returns matrix which transforms a point in feature coordinates into a point in image coordinates (Loc...
BIAS::Vector< double > GetAsVector() const
return a 6-vector (a11,a12,a21,a22,tx,ty)
double FractionInImage(unsigned int width, unsigned int height, unsigned int x0=0, unsigned int y0=0) const
returns fraction of square area [-1;1][-1;1], which is in the image (slow numeric sampling) ...
BIAS::Matrix< double > Cov_
6x6 covariance matrix of the 6 region parameters(a11,a12,a21,a22,tx,ty)
Subscript num_rows() const
BIAS::Matrix< double > GetAsInverseMatrix() const
returns matrix which transforms a point in image coordinates into a point in feature coordinates (Glo...
const BIAS::Vector2< double > & GetT() const
return offset
class BIASGeometryBase_EXPORT HomgPoint2D
BIASCommon_EXPORT std::istream & operator>>(std::istream &is, BIAS::TimeStamp &ts)
Standard input operator for TimeStamps.