From 72c93dabd33528e1cd5a6cfbf6e528b6e8293cb1 Mon Sep 17 00:00:00 2001 From: Kazuki MATSUDA Date: Sat, 20 Oct 2012 11:19:42 +0900 Subject: [PATCH] Add stream operators (Requested #2430) Add output stream operators (<<) for Rect, Size, Matx, Vec. I can't add operations for cv::KeyPoint. And putting together all operator<<. (Matx, Point_, Point3_, Vec, Size_, Rect_) --- .../core/include/opencv2/core/operations.hpp | 71 ++++++++++++++----- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index eb34bb4c06..3d2812ba52 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -3780,23 +3780,6 @@ struct CV_EXPORTS Formatted vector params; }; - -/** Writes a point to an output stream in Matlab notation - */ -template inline std::ostream& operator<<(std::ostream& out, const Point_<_Tp>& p) -{ - out << "[" << p.x << ", " << p.y << "]"; - return out; -} - -/** Writes a point to an output stream in Matlab notation - */ -template inline std::ostream& operator<<(std::ostream& out, const Point3_<_Tp>& p) -{ - out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; - return out; -} - static inline Formatted format(const Mat& mtx, const char* fmt, const vector& params=vector()) { @@ -3858,6 +3841,60 @@ template static inline std::ostream& operator << (std::ostream& ou } +/** Writes a Matx to an output stream. + */ +template inline std::ostream& operator<<(std::ostream& out, const Matx<_Tp, m, n>& matx) +{ + out << cv::Mat(matx); + return out; +} + +/** Writes a point to an output stream in Matlab notation + */ +template inline std::ostream& operator<<(std::ostream& out, const Point_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << "]"; + return out; +} + +/** Writes a point to an output stream in Matlab notation + */ +template inline std::ostream& operator<<(std::ostream& out, const Point3_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; + return out; +} + +/** Writes a Vec to an output stream. Format example : [10, 20, 30] + */ +template inline std::ostream& operator<<(std::ostream& out, const Vec<_Tp, n>& vec) +{ + out << "["; + for (int i = 0; i < n - 1; ++i) { + out << vec[i] << ", "; + } + out << vec[n-1] << "]"; + + return out; +} + +/** Writes a Size_ to an output stream. Format example : [640 x 480] + */ +template inline std::ostream& operator<<(std::ostream& out, const Size_<_Tp>& size) +{ + out << "[" << size.width << " x " << size.height << "]"; + return out; +} + +/** Writes a Rect_ to an output stream. Format example : [640 x 480 from (10, 20)] + */ +template inline std::ostream& operator<<(std::ostream& out, const Rect_<_Tp>& rect) +{ + out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; + return out; +} + + template inline Ptr<_Tp> Algorithm::create(const string& name) { return _create(name).ptr<_Tp>();