26
26
namespace imageproc
27
27
{
28
28
29
+ template <size_t N, typename T> class HomographicTransform ;
30
+
29
31
template <size_t N, typename T>
30
- class HomographicTransform
32
+ class HomographicTransformBase
31
33
{
34
+ public:
32
35
typedef VecNT<N, T> Vec;
33
36
typedef VecNT<(N+1 )*(N+1 ), T> Mat;
34
- public:
35
- explicit HomographicTransform (Mat const & mat) : m_mat(mat) {}
36
37
37
- HomographicTransform inv () const ;
38
+ explicit HomographicTransformBase (Mat const & mat) : m_mat(mat) {}
39
+
40
+ HomographicTransform<N, T> inv () const ;
38
41
39
42
Vec operator ()(Vec const & from) const ;
40
43
@@ -43,19 +46,42 @@ class HomographicTransform
43
46
Mat m_mat;
44
47
};
45
48
49
+
50
+ template <size_t N, typename T>
51
+ class HomographicTransform : public HomographicTransformBase <N, T>
52
+ {
53
+ public:
54
+ explicit HomographicTransform (Mat const & mat) : HomographicTransformBase<N, T>(mat) {}
55
+ };
56
+
57
+
58
+ /* * An optimized, both in terms of API and performance, 1D version. */
59
+ template <typename T>
60
+ class HomographicTransform <1 , T> : public HomographicTransformBase<1 , T>
61
+ {
62
+ public:
63
+ explicit HomographicTransform (Mat const & mat) : HomographicTransformBase<1, T>(mat) {}
64
+
65
+ T operator ()(T from) const ;
66
+
67
+ // Prevent it's shadowing by the above one.
68
+ using HomographicTransformBase<1 , T>::operator ();
69
+ };
70
+
71
+
46
72
template <size_t N, typename T>
47
73
HomographicTransform<N, T>
48
- HomographicTransform <N, T>::inv() const
74
+ HomographicTransformBase <N, T>::inv() const
49
75
{
50
76
MatrixCalc<T, 4 *(N+1 )*(N+1 ), N+1 > mc;
51
77
Mat inv_mat;
52
78
mc (N+1 , N+1 , m_mat).inv ().write (inv_mat);
53
- return HomographicTransform (inv_mat);
79
+ return HomographicTransform<N, T> (inv_mat);
54
80
}
55
81
56
82
template <size_t N, typename T>
57
- typename HomographicTransform <N, T>::Vec
58
- HomographicTransform <N, T>::operator ()(Vec const & from) const
83
+ typename HomographicTransformBase <N, T>::Vec
84
+ HomographicTransformBase <N, T>::operator ()(Vec const & from) const
59
85
{
60
86
MatrixCalc<T, N+1 , 1 > mc;
61
87
VecNT<N+1 , T> const hsrc (from, T (1 ));
@@ -66,6 +92,15 @@ HomographicTransform<N, T>::operator()(Vec const& from) const
66
92
return res;
67
93
}
68
94
95
+ template <typename T>
96
+ T
97
+ HomographicTransform<1 , T>::operator ()(T from) const
98
+ {
99
+ // Optimized version for 1D case.
100
+ T const * m = mat ();
101
+ return (from * m[0 ] + m[2 ]) / (from * m[1 ] + m[3 ]);
102
+ }
103
+
69
104
} // namespace imageproc
70
105
71
106
#endif
0 commit comments