Add stream operators (Requested #2430)
authorKazuki MATSUDA <matsuda.kazuki@facebook.com>
Sat, 20 Oct 2012 02:19:42 +0000 (11:19 +0900)
committerKazuki MATSUDA <matsuda.kazuki@facebook.com>
Sat, 20 Oct 2012 02:19:42 +0000 (11:19 +0900)
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_)

modules/core/include/opencv2/core/operations.hpp

index eb34bb4..3d2812b 100644 (file)
@@ -3780,23 +3780,6 @@ struct CV_EXPORTS Formatted
     vector<int> params;
 };
 
-
-/** Writes a point to an output stream in Matlab notation
- */
-template<typename _Tp> 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<typename _Tp> 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<int>& params=vector<int>())
 {
@@ -3858,6 +3841,60 @@ template<typename _Tp> static inline std::ostream& operator << (std::ostream& ou
 }
 
 
+/** Writes a Matx to an output stream.
+ */
+template<typename _Tp, int m, int n> 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<typename _Tp> 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<typename _Tp> 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<typename _Tp, int n> 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<typename _Tp> 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<typename _Tp> 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<typename _Tp> inline Ptr<_Tp> Algorithm::create(const string& name)
 {
     return _create(name).ptr<_Tp>();