This commit is contained in:
Davis King 2014-04-10 21:20:40 -04:00
commit a3430ef3de
3 changed files with 155 additions and 0 deletions

View File

@ -19,6 +19,13 @@ namespace dlib
class point_rotator class point_rotator
{ {
public: public:
point_rotator (
)
{
sin_angle = 0;
cos_angle = 1;
}
point_rotator ( point_rotator (
const double& angle const double& angle
) )
@ -47,6 +54,18 @@ namespace dlib
return temp; return temp;
} }
inline friend void serialize (const point_rotator& item, std::ostream& out)
{
serialize(item.sin_angle, out);
serialize(item.cos_angle, out);
}
inline friend void deserialize (point_rotator& item, std::istream& in)
{
deserialize(item.sin_angle, in);
deserialize(item.cos_angle, in);
}
private: private:
double sin_angle; double sin_angle;
double cos_angle; double cos_angle;
@ -57,6 +76,16 @@ namespace dlib
class point_transform class point_transform
{ {
public: public:
point_transform (
)
{
sin_angle = 0;
cos_angle = 1;
translate.x() = 0;
translate.y() = 0;
}
point_transform ( point_transform (
const double& angle, const double& angle,
const dlib::vector<double,2>& translate_ const dlib::vector<double,2>& translate_
@ -90,6 +119,20 @@ namespace dlib
const dlib::vector<double,2> get_b( const dlib::vector<double,2> get_b(
) const { return translate; } ) const { return translate; }
inline friend void serialize (const point_transform& item, std::ostream& out)
{
serialize(item.sin_angle, out);
serialize(item.cos_angle, out);
serialize(item.translate, out);
}
inline friend void deserialize (point_transform& item, std::istream& in)
{
deserialize(item.sin_angle, in);
deserialize(item.cos_angle, in);
deserialize(item.translate, in);
}
private: private:
double sin_angle; double sin_angle;
double cos_angle; double cos_angle;
@ -101,6 +144,15 @@ namespace dlib
class point_transform_affine class point_transform_affine
{ {
public: public:
point_transform_affine (
)
{
m = identity_matrix<double>(2);
b.x() = 0;
b.y() = 0;
}
point_transform_affine ( point_transform_affine (
const matrix<double,2,2>& m_, const matrix<double,2,2>& m_,
const dlib::vector<double,2>& b_ const dlib::vector<double,2>& b_
@ -121,6 +173,18 @@ namespace dlib
const dlib::vector<double,2>& get_b( const dlib::vector<double,2>& get_b(
) const { return b; } ) const { return b; }
inline friend void serialize (const point_transform_affine& item, std::ostream& out)
{
serialize(item.m, out);
serialize(item.b, out);
}
inline friend void deserialize (point_transform_affine& item, std::istream& in)
{
deserialize(item.m, in);
deserialize(item.b, in);
}
private: private:
matrix<double,2,2> m; matrix<double,2,2> m;
dlib::vector<double,2> b; dlib::vector<double,2> b;
@ -175,6 +239,13 @@ namespace dlib
class point_transform_projective class point_transform_projective
{ {
public: public:
point_transform_projective (
)
{
m = identity_matrix<double>(3);
}
point_transform_projective ( point_transform_projective (
const matrix<double,3,3>& m_ const matrix<double,3,3>& m_
) :m(m_) ) :m(m_)
@ -208,6 +279,15 @@ namespace dlib
const matrix<double,3,3>& get_m( const matrix<double,3,3>& get_m(
) const { return m; } ) const { return m; }
inline friend void serialize (const point_transform_projective& item, std::ostream& out)
{
serialize(item.m, out);
}
inline friend void deserialize (point_transform_projective& item, std::istream& in)
{
deserialize(item.m, in);
}
private: private:
matrix<double,3,3> m; matrix<double,3,3> m;

View File

@ -20,6 +20,15 @@ namespace dlib
applies an affine transformation to them. applies an affine transformation to them.
!*/ !*/
public: public:
point_transform_affine (
);
/*!
ensures
- This object will perform the identity transform. That is, given a point
as input it will return the same point as output.
!*/
point_transform_affine ( point_transform_affine (
const matrix<double,2,2>& m, const matrix<double,2,2>& m,
const dlib::vector<double,2>& b const dlib::vector<double,2>& b
@ -57,6 +66,12 @@ namespace dlib
}; };
void serialize (const point_transform_affine& item, std::ostream& out);
void deserialize (point_transform_affine& item, std::istream& in);
/*!
provides serialization support
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
point_transform_affine inv ( point_transform_affine inv (
@ -104,6 +119,14 @@ namespace dlib
public: public:
point_transform_projective (
);
/*!
ensures
- This object will perform the identity transform. That is, given a point
as input it will return the same point as output.
!*/
point_transform_projective ( point_transform_projective (
const matrix<double,3,3>& m const matrix<double,3,3>& m
); );
@ -145,6 +168,12 @@ namespace dlib
}; };
void serialize (const point_transform_projective& item, std::ostream& out);
void deserialize (point_transform_projective& item, std::istream& in);
/*!
provides serialization support
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
point_transform_projective inv ( point_transform_projective inv (
@ -186,6 +215,15 @@ namespace dlib
translates them. translates them.
!*/ !*/
public: public:
point_transform (
);
/*!
ensures
- This object will perform the identity transform. That is, given a point
as input it will return the same point as output.
!*/
point_transform ( point_transform (
const double& angle, const double& angle,
const dlib::vector<double,2>& translate const dlib::vector<double,2>& translate
@ -226,6 +264,12 @@ namespace dlib
}; };
void serialize (const point_transform& item, std::ostream& out);
void deserialize (point_transform& item, std::istream& in);
/*!
provides serialization support
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
class point_rotator class point_rotator
@ -236,6 +280,15 @@ namespace dlib
rotates them around the origin by a given angle. rotates them around the origin by a given angle.
!*/ !*/
public: public:
point_rotator (
);
/*!
ensures
- This object will perform the identity transform. That is, given a point
as input it will return the same point as output.
!*/
point_rotator ( point_rotator (
const double& angle const double& angle
); );
@ -267,6 +320,12 @@ namespace dlib
!*/ !*/
}; };
void serialize (const point_rotator& item, std::ostream& out);
void deserialize (point_rotator& item, std::istream& in);
/*!
provides serialization support
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T> template <typename T>

View File

@ -648,6 +648,14 @@ namespace
DLIB_TEST(length(t(tinv(from[i]))-from[i]) < 1e-14); DLIB_TEST(length(t(tinv(from[i]))-from[i]) < 1e-14);
} }
ostringstream sout;
serialize(t, sout);
istringstream sin(sout.str());
point_transform_affine t2;
DLIB_TEST(length(t2(point(2,3)) - point(2,3)) < 1e-14);
deserialize(t2, sin);
DLIB_TEST(max(abs(t2.get_m()-t.get_m())) < 1e-14);
DLIB_TEST(max(abs(t2.get_b()-t.get_b())) < 1e-14);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
@ -706,6 +714,14 @@ namespace
dlog << LINFO << " errors: mean/max: " << rs.mean() << " " << rs.max(); dlog << LINFO << " errors: mean/max: " << rs.mean() << " " << rs.max();
pass_rate.add(0); pass_rate.add(0);
} }
ostringstream sout;
serialize(tran, sout);
istringstream sin(sout.str());
point_transform_projective tran3;
DLIB_TEST(length(tran3(point(2,3)) - point(2,3)) < 1e-14);
deserialize(tran3, sin);
DLIB_TEST(max(abs(tran3.get_m()-tran.get_m())) < 1e-14);
} }
dlog << LINFO << " pass_rate.mean(): "<< pass_rate.mean(); dlog << LINFO << " pass_rate.mean(): "<< pass_rate.mean();