cvstd.inl.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
  15. // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  16. // Third party copyrights are property of their respective owners.
  17. //
  18. // Redistribution and use in source and binary forms, with or without modification,
  19. // are permitted provided that the following conditions are met:
  20. //
  21. // * Redistribution's of source code must retain the above copyright notice,
  22. // this list of conditions and the following disclaimer.
  23. //
  24. // * Redistribution's in binary form must reproduce the above copyright notice,
  25. // this list of conditions and the following disclaimer in the documentation
  26. // and/or other materials provided with the distribution.
  27. //
  28. // * The name of the copyright holders may not be used to endorse or promote products
  29. // derived from this software without specific prior written permission.
  30. //
  31. // This software is provided by the copyright holders and contributors "as is" and
  32. // any express or implied warranties, including, but not limited to, the implied
  33. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  34. // In no event shall the Intel Corporation or contributors be liable for any direct,
  35. // indirect, incidental, special, exemplary, or consequential damages
  36. // (including, but not limited to, procurement of substitute goods or services;
  37. // loss of use, data, or profits; or business interruption) however caused
  38. // and on any theory of liability, whether in contract, strict liability,
  39. // or tort (including negligence or otherwise) arising in any way out of
  40. // the use of this software, even if advised of the possibility of such damage.
  41. //
  42. //M*/
  43. #ifndef OPENCV_CORE_CVSTDINL_HPP
  44. #define OPENCV_CORE_CVSTDINL_HPP
  45. #include <complex>
  46. #include <ostream>
  47. #include <sstream>
  48. //! @cond IGNORED
  49. #ifdef _MSC_VER
  50. #pragma warning( push )
  51. #pragma warning( disable: 4127 )
  52. #endif
  53. namespace cv
  54. {
  55. template<typename _Tp> class DataType< std::complex<_Tp> >
  56. {
  57. public:
  58. typedef std::complex<_Tp> value_type;
  59. typedef value_type work_type;
  60. typedef _Tp channel_type;
  61. enum { generic_type = 0,
  62. depth = DataType<channel_type>::depth,
  63. channels = 2,
  64. fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
  65. type = CV_MAKETYPE(depth, channels) };
  66. typedef Vec<channel_type, channels> vec_type;
  67. };
  68. static inline
  69. std::ostream& operator << (std::ostream& out, Ptr<Formatted> fmtd)
  70. {
  71. fmtd->reset();
  72. for(const char* str = fmtd->next(); str; str = fmtd->next())
  73. out << str;
  74. return out;
  75. }
  76. static inline
  77. std::ostream& operator << (std::ostream& out, const Mat& mtx)
  78. {
  79. return out << Formatter::get()->format(mtx);
  80. }
  81. static inline
  82. std::ostream& operator << (std::ostream& out, const UMat& m)
  83. {
  84. return out << m.getMat(ACCESS_READ);
  85. }
  86. template<typename _Tp> static inline
  87. std::ostream& operator << (std::ostream& out, const Complex<_Tp>& c)
  88. {
  89. return out << "(" << c.re << "," << c.im << ")";
  90. }
  91. template<typename _Tp> static inline
  92. std::ostream& operator << (std::ostream& out, const std::vector<Point_<_Tp> >& vec)
  93. {
  94. return out << Formatter::get()->format(Mat(vec));
  95. }
  96. template<typename _Tp> static inline
  97. std::ostream& operator << (std::ostream& out, const std::vector<Point3_<_Tp> >& vec)
  98. {
  99. return out << Formatter::get()->format(Mat(vec));
  100. }
  101. template<typename _Tp, int m, int n> static inline
  102. std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx)
  103. {
  104. return out << Formatter::get()->format(Mat(matx));
  105. }
  106. template<typename _Tp> static inline
  107. std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p)
  108. {
  109. out << "[" << p.x << ", " << p.y << "]";
  110. return out;
  111. }
  112. template<typename _Tp> static inline
  113. std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p)
  114. {
  115. out << "[" << p.x << ", " << p.y << ", " << p.z << "]";
  116. return out;
  117. }
  118. template<typename _Tp, int n> static inline
  119. std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec)
  120. {
  121. out << "[";
  122. if (cv::traits::Depth<_Tp>::value <= CV_32S)
  123. {
  124. for (int i = 0; i < n - 1; ++i) {
  125. out << (int)vec[i] << ", ";
  126. }
  127. out << (int)vec[n-1] << "]";
  128. }
  129. else
  130. {
  131. for (int i = 0; i < n - 1; ++i) {
  132. out << vec[i] << ", ";
  133. }
  134. out << vec[n-1] << "]";
  135. }
  136. return out;
  137. }
  138. template<typename _Tp> static inline
  139. std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size)
  140. {
  141. return out << "[" << size.width << " x " << size.height << "]";
  142. }
  143. template<typename _Tp> static inline
  144. std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect)
  145. {
  146. return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]";
  147. }
  148. static inline std::ostream& operator << (std::ostream& out, const MatSize& msize)
  149. {
  150. int i, dims = msize.dims();
  151. for( i = 0; i < dims; i++ )
  152. {
  153. out << msize[i];
  154. if( i < dims-1 )
  155. out << " x ";
  156. }
  157. return out;
  158. }
  159. static inline std::ostream &operator<< (std::ostream &s, cv::Range &r)
  160. {
  161. return s << "[" << r.start << " : " << r.end << ")";
  162. }
  163. } // cv
  164. #ifdef _MSC_VER
  165. #pragma warning( pop )
  166. #endif
  167. //! @endcond
  168. #endif // OPENCV_CORE_CVSTDINL_HPP