mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
merged
This commit is contained in:
commit
a3430ef3de
@ -19,6 +19,13 @@ namespace dlib
|
||||
class point_rotator
|
||||
{
|
||||
public:
|
||||
point_rotator (
|
||||
)
|
||||
{
|
||||
sin_angle = 0;
|
||||
cos_angle = 1;
|
||||
}
|
||||
|
||||
point_rotator (
|
||||
const double& angle
|
||||
)
|
||||
@ -47,6 +54,18 @@ namespace dlib
|
||||
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:
|
||||
double sin_angle;
|
||||
double cos_angle;
|
||||
@ -57,6 +76,16 @@ namespace dlib
|
||||
class point_transform
|
||||
{
|
||||
public:
|
||||
|
||||
point_transform (
|
||||
)
|
||||
{
|
||||
sin_angle = 0;
|
||||
cos_angle = 1;
|
||||
translate.x() = 0;
|
||||
translate.y() = 0;
|
||||
}
|
||||
|
||||
point_transform (
|
||||
const double& angle,
|
||||
const dlib::vector<double,2>& translate_
|
||||
@ -90,6 +119,20 @@ namespace dlib
|
||||
const dlib::vector<double,2> get_b(
|
||||
) 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:
|
||||
double sin_angle;
|
||||
double cos_angle;
|
||||
@ -101,6 +144,15 @@ namespace dlib
|
||||
class point_transform_affine
|
||||
{
|
||||
public:
|
||||
|
||||
point_transform_affine (
|
||||
)
|
||||
{
|
||||
m = identity_matrix<double>(2);
|
||||
b.x() = 0;
|
||||
b.y() = 0;
|
||||
}
|
||||
|
||||
point_transform_affine (
|
||||
const matrix<double,2,2>& m_,
|
||||
const dlib::vector<double,2>& b_
|
||||
@ -121,6 +173,18 @@ namespace dlib
|
||||
const dlib::vector<double,2>& get_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:
|
||||
matrix<double,2,2> m;
|
||||
dlib::vector<double,2> b;
|
||||
@ -175,6 +239,13 @@ namespace dlib
|
||||
class point_transform_projective
|
||||
{
|
||||
public:
|
||||
|
||||
point_transform_projective (
|
||||
)
|
||||
{
|
||||
m = identity_matrix<double>(3);
|
||||
}
|
||||
|
||||
point_transform_projective (
|
||||
const matrix<double,3,3>& m_
|
||||
) :m(m_)
|
||||
@ -208,6 +279,15 @@ namespace dlib
|
||||
const matrix<double,3,3>& get_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:
|
||||
matrix<double,3,3> m;
|
||||
|
@ -20,6 +20,15 @@ namespace dlib
|
||||
applies an affine transformation to them.
|
||||
!*/
|
||||
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 (
|
||||
const matrix<double,2,2>& m,
|
||||
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 (
|
||||
@ -104,6 +119,14 @@ namespace dlib
|
||||
|
||||
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 (
|
||||
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 (
|
||||
@ -186,6 +215,15 @@ namespace dlib
|
||||
translates them.
|
||||
!*/
|
||||
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 (
|
||||
const double& angle,
|
||||
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
|
||||
@ -236,6 +280,15 @@ namespace dlib
|
||||
rotates them around the origin by a given angle.
|
||||
!*/
|
||||
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 (
|
||||
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>
|
||||
|
@ -648,6 +648,14 @@ namespace
|
||||
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();
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user