Commit f62d7c79 authored by Davis King's avatar Davis King

Made it so you can compose point transform objects via operator *.

parent 8237b748
...@@ -190,6 +190,16 @@ namespace dlib ...@@ -190,6 +190,16 @@ namespace dlib
dlib::vector<double,2> b; dlib::vector<double,2> b;
}; };
// ----------------------------------------------------------------------------------------
inline point_transform_affine operator* (
const point_transform_affine& lhs,
const point_transform_affine& rhs
)
{
return point_transform_affine(lhs.get_m()*rhs.get_m(), lhs.get_m()*rhs.get_b()+lhs.get_b());
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
inline point_transform_affine inv ( inline point_transform_affine inv (
...@@ -358,6 +368,16 @@ namespace dlib ...@@ -358,6 +368,16 @@ namespace dlib
matrix<double,3,3> m; matrix<double,3,3> m;
}; };
// ----------------------------------------------------------------------------------------
inline point_transform_projective operator* (
const point_transform_projective& lhs,
const point_transform_projective& rhs
)
{
return point_transform_projective(lhs.get_m()*rhs.get_m());
}
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
inline point_transform_projective inv ( inline point_transform_projective inv (
......
...@@ -74,6 +74,18 @@ namespace dlib ...@@ -74,6 +74,18 @@ namespace dlib
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
point_transform_affine operator* (
const point_transform_affine& lhs,
const point_transform_affine& rhs
);
/*!
ensures
- returns a transformation TFORM(x) that is equivalent to lhs(rhs(x)). That
is, for all valid x: TFORM(x) == lhs(rhs(x)).
!*/
// ----------------------------------------------------------------------------------------
point_transform_affine inv ( point_transform_affine inv (
const point_transform_affine& trans const point_transform_affine& trans
); );
...@@ -197,6 +209,18 @@ namespace dlib ...@@ -197,6 +209,18 @@ namespace dlib
provides serialization support provides serialization support
!*/ !*/
// ----------------------------------------------------------------------------------------
point_transform_projective operator* (
const point_transform_projective& lhs,
const point_transform_projective& rhs
);
/*!
ensures
- returns a transformation TFORM(x) that is equivalent to lhs(rhs(x)). That
is, for all valid x: TFORM(x) == lhs(rhs(x)).
!*/
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
point_transform_projective inv ( point_transform_projective inv (
......
...@@ -646,6 +646,10 @@ namespace ...@@ -646,6 +646,10 @@ namespace
DLIB_TEST(length(t(from[i])-to[i]) < 1e-14); DLIB_TEST(length(t(from[i])-to[i]) < 1e-14);
DLIB_TEST(length(tinv(t(from[i]))-from[i]) < 1e-14); DLIB_TEST(length(tinv(t(from[i]))-from[i]) < 1e-14);
DLIB_TEST(length(t(tinv(from[i]))-from[i]) < 1e-14); DLIB_TEST(length(t(tinv(from[i]))-from[i]) < 1e-14);
point_transform_affine temp = t*inv(t);
DLIB_TEST(length(temp.get_b()) < 1e-14);
DLIB_TEST(max(abs(temp.get_m() - identity_matrix<double>(2))) < 1e-14);
} }
ostringstream sout; ostringstream sout;
...@@ -692,6 +696,11 @@ namespace ...@@ -692,6 +696,11 @@ namespace
to_points.push_back(tran(p) + (randm(2,1,rnd)-0.5)*error_rate); to_points.push_back(tran(p) + (randm(2,1,rnd)-0.5)*error_rate);
DLIB_TEST(length(traninv(tran(p))-p) <= 1e-5); DLIB_TEST(length(traninv(tran(p))-p) <= 1e-5);
DLIB_TEST(length(tran(traninv(p))-p) <= 1e-5); DLIB_TEST(length(tran(traninv(p))-p) <= 1e-5);
point_transform_projective temp = tran*traninv;
DLIB_TEST_MSG(max(abs(temp.get_m() - identity_matrix<double>(3))) < 1e-10, temp.get_m());
temp = traninv*tran;
DLIB_TEST_MSG(max(abs(temp.get_m() - identity_matrix<double>(3))) < 1e-10, temp.get_m());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment