Ask Your Question

Revision history [back]

Not a perfect solution, but I created my own simple geometric types that can be converted to and from the cv types. For example:

namespace nice {
template<typename _Tp> class NicePoint_

constexpr NicePoint_();
constexpr NicePoint_(_Tp _x, _Tp _y);

// Regular and move constructors
constexpr NicePoint_(const NicePoint_& rhs) = default;
NicePoint_(NicePoint_&& rhs) noexcept;

// Regular and move assignment
NicePoint_& operator=(const NicePoint_& rhs) = default;
NicePoint_& operator=(NicePoint_&& rhs) noexcept;

// Allow back-and-forth conversion to cv::Point_
NicePoint_(cv::Point_<_Tp>) noexcept;
operator cv::Point_<_Tp>() const noexcept;

// Dot product
_Tp dot(const NicePoint_ & pt) const;

// Dot product in double precision
double ddot(const NicePoint_ & pt) const;

// Cross product
double cross(const NicePoint_ & pt) const;

template<typename _U>
NicePoint_ scale(const _U &s) const
    return NicePoint_(x * s, y * s);

_Tp x, y; //< the point coordinates

typedef NicePoint_<int> Point2i;
typedef NicePoint_<float> Point2f;
typedef NicePoint_<double> Point2d;
typedef Point2i Point;
} // end of namespace nice