From 940eedfb277804c00e77a94dcb50d6d3b2678f6e Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 2 Apr 2013 20:59:43 +0400 Subject: [PATCH] Finalize core headers reorganization --- modules/androidcamera/src/camera_activity.cpp | 7 +- modules/calib3d/src/circlesgrid.hpp | 1 + modules/calib3d/test/test_stereomatching.cpp | 1 + modules/contrib/include/opencv2/contrib.hpp | 2 + modules/contrib/src/retina.cpp | 1 + modules/core/include/opencv2/core.hpp | 48 +- modules/core/include/opencv2/core/affine.hpp | 194 +-- modules/core/include/opencv2/core/core_c.h | 6 +- modules/core/include/opencv2/core/cvdef.h | 2 +- modules/core/include/opencv2/core/cvstd.hpp | 218 ++-- .../core/include/opencv2/core/cvstd.inl.hpp | 125 +- modules/core/include/opencv2/core/eigen.hpp | 79 +- modules/core/include/opencv2/core/gpumat.hpp | 1114 +++++++++-------- modules/core/include/opencv2/core/mat.inl.hpp | 5 - modules/core/include/opencv2/core/opengl.hpp | 6 +- .../core/include/opencv2/core/operations.hpp | 171 +-- .../core/include/opencv2/core/persistence.hpp | 2 + modules/core/include/opencv2/core/private.hpp | 4 +- modules/core/include/opencv2/core/traits.hpp | 7 +- modules/core/include/opencv2/core/types_c.h | 1 + modules/core/src/command_line_parser.cpp | 1 + modules/core/src/out.cpp | 3 +- modules/core/test/test_mat.cpp | 2 + modules/flann/src/miniflann.cpp | 18 +- modules/java/generator/src/cpp/Mat.cpp | 29 +- .../include/opencv2/softcascade.hpp | 1 + .../src/integral_channel_builder.cpp | 3 +- 27 files changed, 1127 insertions(+), 924 deletions(-) diff --git a/modules/androidcamera/src/camera_activity.cpp b/modules/androidcamera/src/camera_activity.cpp index c65fd7d3b6..3ce4089bee 100644 --- a/modules/androidcamera/src/camera_activity.cpp +++ b/modules/androidcamera/src/camera_activity.cpp @@ -29,6 +29,11 @@ #include #include +struct str_greater +{ + bool operator() (const cv::String& a, const cv::String& b) { return a > b; } +}; + class CameraWrapperConnector { public: @@ -177,7 +182,7 @@ CameraActivity::ErrorCode CameraWrapperConnector::connectToLib() std::vector listLibs; fillListWrapperLibs(folderPath, listLibs); - std::sort(listLibs.begin(), listLibs.end(), std::greater()); + std::sort(listLibs.begin(), listLibs.end(), str_greater()); void * libHandle=0; cv::String cur_path; diff --git a/modules/calib3d/src/circlesgrid.hpp b/modules/calib3d/src/circlesgrid.hpp index 3028c58b56..fae6b3cac7 100644 --- a/modules/calib3d/src/circlesgrid.hpp +++ b/modules/calib3d/src/circlesgrid.hpp @@ -47,6 +47,7 @@ #include #include #include +#include #include "precomp.hpp" diff --git a/modules/calib3d/test/test_stereomatching.cpp b/modules/calib3d/test/test_stereomatching.cpp index 85401f554d..a5817e95d5 100644 --- a/modules/calib3d/test/test_stereomatching.cpp +++ b/modules/calib3d/test/test_stereomatching.cpp @@ -48,6 +48,7 @@ #include "test_precomp.hpp" #include #include +#include using namespace std; using namespace cv; diff --git a/modules/contrib/include/opencv2/contrib.hpp b/modules/contrib/include/opencv2/contrib.hpp index 09989ec1fa..dc4a72ae1a 100644 --- a/modules/contrib/include/opencv2/contrib.hpp +++ b/modules/contrib/include/opencv2/contrib.hpp @@ -48,6 +48,8 @@ #include "opencv2/features2d.hpp" #include "opencv2/objdetect.hpp" +#include + #ifdef __cplusplus /****************************************************************************************\ diff --git a/modules/contrib/src/retina.cpp b/modules/contrib/src/retina.cpp index 772b146e72..5dae919bff 100644 --- a/modules/contrib/src/retina.cpp +++ b/modules/contrib/src/retina.cpp @@ -71,6 +71,7 @@ #include "precomp.hpp" #include "retinafilter.hpp" #include +#include namespace cv { diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index d1065c9234..e75127a3ec 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -57,18 +57,6 @@ #include "opencv2/core/mat.hpp" #include "opencv2/core/persistence.hpp" -#ifndef SKIP_INCLUDES -#include -#include -#include -#include -#include -#include -#include -#include -#include -#endif // SKIP_INCLUDES - /*! \namespace cv Namespace where all the C++ OpenCV functionality resides */ @@ -951,6 +939,42 @@ private: +/////////////////////////////// Formatted output of cv::Mat /////////////////////////// + +class CV_EXPORTS Formatted +{ +public: + virtual const char* next() = 0; + virtual void reset() = 0; + virtual ~Formatted(); +}; + + +class CV_EXPORTS Formatter +{ +public: + enum { FMT_MATLAB = 0, + FMT_CSV = 1, + FMT_PYTHON = 2, + FMT_NUMPY = 3, + FMT_C = 4, + FMT_DEFAULT = FMT_MATLAB + }; + + virtual ~Formatter(); + + virtual Ptr format(const Mat& mtx) const = 0; + + virtual void set32fPrecision(int p = 8) = 0; + virtual void set64fPrecision(int p = 16) = 0; + virtual void setMultiline(bool ml = true) = 0; + + static Ptr get(int fmt = FMT_DEFAULT); + +}; + + + //////////////////////////////////////// Algorithm //////////////////////////////////// class CV_EXPORTS Algorithm; diff --git a/modules/core/include/opencv2/core/affine.hpp b/modules/core/include/opencv2/core/affine.hpp index ae6a6a9e7b..cf7b29cadb 100644 --- a/modules/core/include/opencv2/core/affine.hpp +++ b/modules/core/include/opencv2/core/affine.hpp @@ -1,44 +1,45 @@ /*M/////////////////////////////////////////////////////////////////////////////////////// - // - // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. - // - // By downloading, copying, installing or using the software you agree to this license. - // If you do not agree to this license, do not download, install, - // copy or use the software. - // - // - // License Agreement - // For Open Source Computer Vision Library - // - // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. - // Copyright (C) 2008-2013, Willow Garage Inc., all rights reserved. - // Third party copyrights are property of their respective owners. - // - // Redistribution and use in source and binary forms, with or without modification, - // are permitted provided that the following conditions are met: - // - // * Redistribution's of source code must retain the above copyright notice, - // this list of conditions and the following disclaimer. - // - // * Redistribution's in binary form must reproduce the above copyright notice, - // this list of conditions and the following disclaimer in the documentation - // and / or other materials provided with the distribution. - // - // * The name of the copyright holders may not be used to endorse or promote products - // derived from this software without specific prior written permission. - // - // This software is provided by the copyright holders and contributors "as is" and - // any express or implied warranties, including, but not limited to, the implied - // warranties of merchantability and fitness for a particular purpose are disclaimed. - // In no event shall the Intel Corporation or contributors be liable for any direct, - // indirect, incidental, special, exemplary, or consequential damages - // (including, but not limited to, procurement of substitute goods or services; - // loss of use, data, or profits; or business interruption) however caused - // and on any theory of liability, whether in contract, strict liability, - // or tort (including negligence or otherwise) arising in any way out of - // the use of this software, even if advised of the possibility of such damage. - // - //M*/ +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ #ifndef __OPENCV_CORE_AFFINE3_HPP__ #define __OPENCV_CORE_AFFINE3_HPP__ @@ -119,24 +120,36 @@ namespace cv #endif }; - template Affine3 operator*(const Affine3& affine1, const Affine3& affine2); - template V operator*(const Affine3& affine, const V& vector); + template static + Affine3 operator*(const Affine3& affine1, const Affine3& affine2); + + template static + V operator*(const Affine3& affine, const V& vector); typedef Affine3 Affine3f; typedef Affine3 Affine3d; - cv::Vec3f operator*(const cv::Affine3f& affine, const cv::Vec3f& vector); - cv::Vec3d operator*(const cv::Affine3d& affine, const cv::Vec3d& vector); + static cv::Vec3f operator*(const cv::Affine3f& affine, const cv::Vec3f& vector); + static cv::Vec3d operator*(const cv::Affine3d& affine, const cv::Vec3d& vector); } + /////////////////////////////////////////////////////////////////////////////////// /// Implementaiton -template inline cv::Affine3::Affine3() : matrix(Mat4::eye()) {} -template inline cv::Affine3::Affine3(const Mat4& affine) : matrix(affine) {} +template inline +cv::Affine3::Affine3() + : matrix(Mat4::eye()) +{} + +template inline +cv::Affine3::Affine3(const Mat4& affine) + : matrix(affine) +{} -template inline cv::Affine3::Affine3(const Mat3& R, const Vec3& t) +template inline +cv::Affine3::Affine3(const Mat3& R, const Vec3& t) { rotation(R); translation(t); @@ -144,7 +157,8 @@ template inline cv::Affine3::Affine3(const Mat3& R, const Vec3& t matrix.val[15] = 1; } -template inline cv::Affine3::Affine3(const Vec3& rvec, const Vec3& t) +template inline +cv::Affine3::Affine3(const Vec3& rvec, const Vec3& t) { rotation(rvec); translation(t); @@ -152,7 +166,8 @@ template inline cv::Affine3::Affine3(const Vec3& rvec, const Vec3 matrix.val[15] = 1; } -template inline cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) +template inline +cv::Affine3::Affine3(const cv::Mat& data, const Vec3& t) { CV_Assert(data.type() == cv::DataType::type); @@ -168,7 +183,8 @@ template inline cv::Affine3::Affine3(const cv::Mat& data, const V matrix.val[15] = 1; } -template inline cv::Affine3::Affine3(float_type alpha, float_type beta, float_type gamma, const Vec3& t) +template inline +cv::Affine3::Affine3(float_type alpha, float_type beta, float_type gamma, const Vec3& t) { rotation(alpha, beta, gamma); translation(t); @@ -176,14 +192,20 @@ template inline cv::Affine3::Affine3(float_type alpha, float_type matrix.val[15] = 1; } -template inline cv::Affine3 cv::Affine3::Identity() +template inline +cv::Affine3 cv::Affine3::Identity() { return Affine3(cv::Affine3::Mat4::eye()); } -template inline void cv::Affine3::rotation(const Mat3& R) { linear(R); } +template inline +void cv::Affine3::rotation(const Mat3& R) +{ + linear(R); +} -template inline void cv::Affine3::rotation(const Vec3& rvec) +template inline +void cv::Affine3::rotation(const Vec3& rvec) { double rx = rvec[0], ry = rvec[1], rz = rvec[2]; double theta = std::sqrt(rx*rx + ry*ry + rz*rz); @@ -215,7 +237,8 @@ template inline void cv::Affine3::rotation(const Vec3& rvec) } //Combines rotation methods above. Suports 3x3, 1x3, 3x1 sizes of data matrix; -template inline void cv::Affine3::rotation(const cv::Mat& data) +template inline +void cv::Affine3::rotation(const cv::Mat& data) { CV_Assert(data.type() == cv::DataType::type); @@ -235,25 +258,34 @@ template inline void cv::Affine3::rotation(const cv::Mat& data) CV_Assert(!"Input marix can be 3x3, 1x3 or 3x1"); } -template inline void cv::Affine3::rotation(float_type alpha, float_type beta, float_type gamma) +template inline +void cv::Affine3::rotation(float_type alpha, float_type beta, float_type gamma) { rotation(Vec3(alpha, beta, gamma)); } -template inline void cv::Affine3::linear(const Mat3& L) +template inline +void cv::Affine3::linear(const Mat3& L) { matrix.val[0] = L.val[0]; matrix.val[1] = L.val[1]; matrix.val[ 2] = L.val[2]; matrix.val[4] = L.val[3]; matrix.val[5] = L.val[4]; matrix.val[ 6] = L.val[5]; matrix.val[8] = L.val[6]; matrix.val[9] = L.val[7]; matrix.val[10] = L.val[8]; } -template inline void cv::Affine3::translation(const Vec3& t) +template inline +void cv::Affine3::translation(const Vec3& t) { matrix.val[3] = t[0]; matrix.val[7] = t[1]; matrix.val[11] = t[2]; } -template inline typename cv::Affine3::Mat3 cv::Affine3::rotation() const { return linear(); } -template inline typename cv::Affine3::Mat3 cv::Affine3::linear() const +template inline +typename cv::Affine3::Mat3 cv::Affine3::rotation() const +{ + return linear(); +} + +template inline +typename cv::Affine3::Mat3 cv::Affine3::linear() const { typename cv::Affine3::Mat3 R; R.val[0] = matrix.val[0]; R.val[1] = matrix.val[1]; R.val[2] = matrix.val[ 2]; @@ -262,17 +294,20 @@ template inline typename cv::Affine3::Mat3 cv::Affine3::linear return R; } -template inline typename cv::Affine3::Vec3 cv::Affine3::translation() const +template inline +typename cv::Affine3::Vec3 cv::Affine3::translation() const { return Vec3(matrix.val[3], matrix.val[7], matrix.val[11]); } -template inline cv::Affine3 cv::Affine3::inv(int method) const +template inline +cv::Affine3 cv::Affine3::inv(int method) const { return matrix.inv(method); } -template inline cv::Affine3 cv::Affine3::rotate(const Mat3& R) const +template inline +cv::Affine3 cv::Affine3::rotate(const Mat3& R) const { Mat3 Lc = linear(); Vec3 tc = translation(); @@ -295,7 +330,8 @@ template inline cv::Affine3 cv::Affine3::rotate(const Mat3& R) return result; } -template inline cv::Affine3 cv::Affine3::translate(const Vec3& t) const +template inline +cv::Affine3 cv::Affine3::translate(const Vec3& t) const { Mat4 m = matrix; m.val[ 3] += t[0]; @@ -304,22 +340,26 @@ template inline cv::Affine3 cv::Affine3::translate(const Vec3& return m; } -template inline cv::Affine3 cv::Affine3::concatenate(const Affine3& affine) const +template inline +cv::Affine3 cv::Affine3::concatenate(const Affine3& affine) const { return (*this).rotate(affine.rotation()).translate(affine.translation()); } -template template inline cv::Affine3::operator Affine3() const +template template inline +cv::Affine3::operator Affine3() const { return Affine3(matrix); } -template inline cv::Affine3 cv::operator*(const cv::Affine3& affine1, const cv::Affine3& affine2) +template inline +cv::Affine3 cv::operator*(const cv::Affine3& affine1, const cv::Affine3& affine2) { return affine2.concatenate(affine1); } -template inline V cv::operator*(const cv::Affine3& affine, const V& v) +template inline +V cv::operator*(const cv::Affine3& affine, const V& v) { const typename Affine3::Mat4& m = affine.matrix; @@ -330,7 +370,8 @@ template inline V cv::operator*(const cv::Affine3& af return r; } -inline cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v) +static inline +cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v) { const cv::Matx44f& m = affine.matrix; cv::Vec3f r; @@ -340,7 +381,8 @@ inline cv::Vec3f cv::operator*(const cv::Affine3f& affine, const cv::Vec3f& v) return r; } -inline cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) +static inline +cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) { const cv::Matx44d& m = affine.matrix; cv::Vec3d r; @@ -350,20 +392,25 @@ inline cv::Vec3d cv::operator*(const cv::Affine3d& affine, const cv::Vec3d& v) return r; } + + #if defined EIGEN_WORLD_VERSION && defined EIGEN_GEOMETRY_MODULE_H -template inline cv::Affine3::Affine3(const Eigen::Transform& affine) +template inline +cv::Affine3::Affine3(const Eigen::Transform& affine) { cv::Mat(4, 4, cv::DataType::type, affine.matrix().data()).copyTo(matrix); } -template inline cv::Affine3::Affine3(const Eigen::Transform& affine) +template inline +cv::Affine3::Affine3(const Eigen::Transform& affine) { Eigen::Transform a = affine; cv::Mat(4, 4, cv::DataType::type, a.matrix().data()).copyTo(matrix); } -template inline cv::Affine3::operator Eigen::Transform() const +template inline +cv::Affine3::operator Eigen::Transform() const { Eigen::Transform r; cv::Mat hdr(4, 4, cv::DataType::type, r.matrix().data()); @@ -371,7 +418,8 @@ template inline cv::Affine3::operator Eigen::Transform inline cv::Affine3::operator Eigen::Transform() const +template inline +cv::Affine3::operator Eigen::Transform() const { return this->operator Eigen::Transform(); } diff --git a/modules/core/include/opencv2/core/core_c.h b/modules/core/include/opencv2/core/core_c.h index 5aca0cad20..98520c44d1 100644 --- a/modules/core/include/opencv2/core/core_c.h +++ b/modules/core/include/opencv2/core/core_c.h @@ -7,11 +7,12 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -1888,7 +1889,6 @@ template<> CV_EXPORTS void Ptr::delete_obj(); template<> CV_EXPORTS void Ptr::delete_obj(); template<> CV_EXPORTS void Ptr::delete_obj(); template<> CV_EXPORTS void Ptr::delete_obj(); -template<> CV_EXPORTS void Ptr::delete_obj(); ////////////// convenient wrappers for operating old-style dynamic structures ////////////// @@ -2228,7 +2228,7 @@ template inline ptrdiff_t operator - (const SeqIterator<_Tp>& a, const SeqIterator<_Tp>& b) { ptrdiff_t delta = a.index - b.index, n = a.seq->total; - if( std::abs(static_cast(delta)) > n ) + if( delta > n || delta < -n ) delta += delta < 0 ? n : -n; return delta; } diff --git a/modules/core/include/opencv2/core/cvdef.h b/modules/core/include/opencv2/core/cvdef.h index 141424f52a..7ce9bb8e1f 100644 --- a/modules/core/include/opencv2/core/cvdef.h +++ b/modules/core/include/opencv2/core/cvdef.h @@ -111,7 +111,7 @@ #define CV_CPU_NEON 11 #define CV_HARDWARE_MAX_FEATURE 255 -// disable SSE/AVX/NEON headers for NVCC compiler +// do not include SSE/AVX/NEON headers for NVCC compiler #ifndef __CUDACC__ #if defined __SSE2__ || defined _M_X64 || (defined _M_IX86_FP && _M_IX86_FP >= 2) diff --git a/modules/core/include/opencv2/core/cvstd.hpp b/modules/core/include/opencv2/core/cvstd.hpp index 968d26650d..1353e0fa90 100644 --- a/modules/core/include/opencv2/core/cvstd.hpp +++ b/modules/core/include/opencv2/core/cvstd.hpp @@ -62,6 +62,7 @@ #ifndef OPENCV_NOSTL_TRANSITIONAL # include # include +# include //for abs(int) # include namespace cv @@ -70,19 +71,31 @@ namespace cv using std::max; using std::abs; using std::swap; + using std::sqrt; + using std::exp; + using std::pow; + using std::log; +} + +namespace std +{ + static inline uchar abs(uchar a) { return a; } + static inline ushort abs(ushort a) { return a; } + static inline unsigned abs(unsigned a) { return a; } + static inline uint64 abs(uint64 a) { return a; } } #else namespace cv { - template inline T min(T a, T b) { return a < b ? a : b; } - template inline T max(T a, T b) { return a > b ? a : b; } - template inline T abs(T a) { return a < 0 ? -a : a; } - template inline void swap(T& a, T& b) { T tmp = a; a = b; b = tmp; } + template static inline T min(T a, T b) { return a < b ? a : b; } + template static inline T max(T a, T b) { return a > b ? a : b; } + template static inline T abs(T a) { return a < 0 ? -a : a; } + template static inline void swap(T& a, T& b) { T tmp = a; a = b; b = tmp; } template<> inline uchar abs(uchar a) { return a; } template<> inline ushort abs(ushort a) { return a; } - template<> inline uint abs(uint a) { return a; } + template<> inline unsigned abs(unsigned a) { return a; } template<> inline uint64 abs(uint64 a) { return a; } } #endif @@ -483,17 +496,22 @@ bool operator != (const Ptr<_Tp>& a, const Ptr<_Tp2>& b) ////////////////////////// cv::String implementation ///////////////////////// -inline String::String() : cstr_(0), len_(0) -{ -} +inline +String::String() + : cstr_(0), len_(0) +{} -inline String::String(const String& str) : cstr_(str.cstr_), len_(str.len_) +inline +String::String(const String& str) + : cstr_(str.cstr_), len_(str.len_) { if (cstr_) CV_XADD(((int*)cstr_)-1, 1); } -inline String::String(const String& str, size_t pos, size_t len) : cstr_(0), len_(0) +inline +String::String(const String& str, size_t pos, size_t len) + : cstr_(0), len_(0) { pos = min(pos, str.len_); len = min(str.len_ - pos, len); @@ -508,32 +526,41 @@ inline String::String(const String& str, size_t pos, size_t len) : cstr_(0), len memcpy(allocate(len), str.cstr_ + pos, len); } -inline String::String(const char* s) : cstr_(0), len_(0) +inline +String::String(const char* s) + : cstr_(0), len_(0) { if (!s) return; size_t len = strlen(s); memcpy(allocate(len), s, len); } -inline String::String(const char* s, size_t n) : cstr_(0), len_(0) +inline +String::String(const char* s, size_t n) + : cstr_(0), len_(0) { if (!n) return; memcpy(allocate(n), s, n); } -inline String::String(size_t n, char c) : cstr_(0), len_(0) +inline +String::String(size_t n, char c) + : cstr_(0), len_(0) { memset(allocate(n), c, n); } -inline String::String(const char* first, const char* last) : cstr_(0), len_(0) +inline +String::String(const char* first, const char* last) + : cstr_(0), len_(0) { size_t len = (size_t)(last - first); memcpy(allocate(len), first, len); } -template -inline String::String(Iterator first, Iterator last) : cstr_(0), len_(0) +template inline +String::String(Iterator first, Iterator last) + : cstr_(0), len_(0) { size_t len = (size_t)(last - first); char* str = allocate(len); @@ -544,12 +571,14 @@ inline String::String(Iterator first, Iterator last) : cstr_(0), len_(0) } } -inline String::~String() +inline +String::~String() { deallocate(); } -inline String& String::operator=(const String& str) +inline +String& String::operator=(const String& str) { deallocate(); if (str.cstr_) CV_XADD(((int*)str.cstr_)-1, 1); @@ -558,7 +587,8 @@ inline String& String::operator=(const String& str) return *this; } -inline String& String::operator=(const char* s) +inline +String& String::operator=(const char* s) { deallocate(); if (!s) return *this; @@ -567,82 +597,97 @@ inline String& String::operator=(const char* s) return *this; } -inline String& String::operator=(char c) +inline +String& String::operator=(char c) { deallocate(); allocate(1)[0] = c; return *this; } -inline size_t String::size() const +inline +size_t String::size() const { return len_; } -inline size_t String::length() const +inline +size_t String::length() const { return len_; } -inline char String::operator[](size_t idx) const +inline +char String::operator[](size_t idx) const { return cstr_[idx]; } -inline char String::operator[](int idx) const +inline +char String::operator[](int idx) const { return cstr_[idx]; } -inline const char* String::begin() const +inline +const char* String::begin() const { return cstr_; } -inline const char* String::end() const +inline +const char* String::end() const { return len_ ? cstr_ + 1 : 0; } -inline bool String::empty() const +inline +bool String::empty() const { return len_ == 0; } -inline const char* String::c_str() const +inline +const char* String::c_str() const { return cstr_ ? cstr_ : ""; } -inline void String::swap(String& str) +inline +void String::swap(String& str) { cv::swap(cstr_, str.cstr_); cv::swap(len_, str.len_); } -inline void String::clear() +inline +void String::clear() { deallocate(); } -inline int String::compare(const char* s) const +inline +int String::compare(const char* s) const { if (cstr_ == s) return 0; return strcmp(c_str(), s); } -inline int String::compare(const String& str) const +inline +int String::compare(const String& str) const { if (cstr_ == str.cstr_) return 0; return strcmp(c_str(), str.c_str()); } -inline String String::substr(size_t pos, size_t len) const +inline +String String::substr(size_t pos, size_t len) const { return String(*this, pos, len); } -inline size_t String::find(const char* s, size_t pos, size_t n) const +inline +size_t String::find(const char* s, size_t pos, size_t n) const { if (n == 0 || pos + n > len_) return npos; const char* lmax = cstr_ + len_ - n; @@ -655,17 +700,20 @@ inline size_t String::find(const char* s, size_t pos, size_t n) const return npos; } -inline size_t String::find(char c, size_t pos) const +inline +size_t String::find(char c, size_t pos) const { return find(&c, pos, 1); } -inline size_t String::find(const String& str, size_t pos) const +inline +size_t String::find(const String& str, size_t pos) const { return find(str.c_str(), pos, str.len_); } -inline size_t String::find(const char* s, size_t pos) const +inline +size_t String::find(const char* s, size_t pos) const { if (pos >= len_ || !s[0]) return npos; const char* lmax = cstr_ + len_; @@ -681,7 +729,8 @@ inline size_t String::find(const char* s, size_t pos) const return npos; } -inline size_t String::rfind(const char* s, size_t pos, size_t n) const +inline +size_t String::rfind(const char* s, size_t pos, size_t n) const { if (n > len_) return npos; if (pos > len_ - n) pos = len_ - n; @@ -694,22 +743,26 @@ inline size_t String::rfind(const char* s, size_t pos, size_t n) const return npos; } -inline size_t String::rfind(char c, size_t pos) const +inline +size_t String::rfind(char c, size_t pos) const { return rfind(&c, pos, 1); } -inline size_t String::rfind(const String& str, size_t pos) const +inline +size_t String::rfind(const String& str, size_t pos) const { return rfind(str.c_str(), pos, str.len_); } -inline size_t String::rfind(const char* s, size_t pos) const +inline +size_t String::rfind(const char* s, size_t pos) const { return rfind(s, pos, strlen(s)); } -inline size_t String::find_first_of(const char* s, size_t pos, size_t n) const +inline +size_t String::find_first_of(const char* s, size_t pos, size_t n) const { if (n == 0 || pos + n > len_) return npos; const char* lmax = cstr_ + len_; @@ -722,17 +775,20 @@ inline size_t String::find_first_of(const char* s, size_t pos, size_t n) const return npos; } -inline size_t String::find_first_of(char c, size_t pos) const +inline +size_t String::find_first_of(char c, size_t pos) const { return find_first_of(&c, pos, 1); } -inline size_t String::find_first_of(const String& str, size_t pos) const +inline +size_t String::find_first_of(const String& str, size_t pos) const { return find_first_of(str.c_str(), pos, str.len_); } -inline size_t String::find_first_of(const char* s, size_t pos) const +inline +size_t String::find_first_of(const char* s, size_t pos) const { if (pos >= len_ || !s[0]) return npos; const char* lmax = cstr_ + len_; @@ -745,7 +801,8 @@ inline size_t String::find_first_of(const char* s, size_t pos) const return npos; } -inline size_t String::find_last_of(const char* s, size_t pos, size_t n) const +inline +size_t String::find_last_of(const char* s, size_t pos, size_t n) const { if (pos >= len_) pos = len_ - 1; for (const char* i = cstr_ + pos; i >= cstr_; --i) @@ -757,17 +814,20 @@ inline size_t String::find_last_of(const char* s, size_t pos, size_t n) const return npos; } -inline size_t String::find_last_of(char c, size_t pos) const +inline +size_t String::find_last_of(char c, size_t pos) const { return find_last_of(&c, pos, 1); } -inline size_t String::find_last_of(const String& str, size_t pos) const +inline +size_t String::find_last_of(const String& str, size_t pos) const { return find_last_of(str.c_str(), pos, str.len_); } -inline size_t String::find_last_of(const char* s, size_t pos) const +inline +size_t String::find_last_of(const char* s, size_t pos) const { if (pos >= len_) pos = len_ - 1; for (const char* i = cstr_ + pos; i >= cstr_; --i) @@ -779,7 +839,8 @@ inline size_t String::find_last_of(const char* s, size_t pos) const return npos; } -inline String String::toLowerCase() const +inline +String String::toLowerCase() const { String res(cstr_, len_); @@ -791,7 +852,8 @@ inline String String::toLowerCase() const // ************************* cv::String non-member functions ************************* -inline String operator+ (const String& lhs, const String& rhs) +inline +String operator + (const String& lhs, const String& rhs) { String s; s.allocate(lhs.len_ + rhs.len_); @@ -800,7 +862,8 @@ inline String operator+ (const String& lhs, const String& rhs) return s; } -inline String operator+ (const String& lhs, const char* rhs) +inline +String operator + (const String& lhs, const char* rhs) { String s; size_t rhslen = strlen(rhs); @@ -810,7 +873,8 @@ inline String operator+ (const String& lhs, const char* rhs) return s; } -inline String operator+ (const char* lhs, const String& rhs) +inline +String operator + (const char* lhs, const String& rhs) { String s; size_t lhslen = strlen(lhs); @@ -820,7 +884,8 @@ inline String operator+ (const char* lhs, const String& rhs) return s; } -inline String operator+ (const String& lhs, char rhs) +inline +String operator + (const String& lhs, char rhs) { String s; s.allocate(lhs.len_ + 1); @@ -829,7 +894,8 @@ inline String operator+ (const String& lhs, char rhs) return s; } -inline String operator+ (char lhs, const String& rhs) +inline +String operator + (char lhs, const String& rhs) { String s; s.allocate(rhs.len_ + 1); @@ -838,24 +904,24 @@ inline String operator+ (char lhs, const String& rhs) return s; } -inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); } -inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); } -inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); } -inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); } -inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); } -inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); } -inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; } -inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; } -inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; } -inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; } -inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; } -inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; } -inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; } -inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; } -inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; } -inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; } -inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; } -inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; } +static inline bool operator== (const String& lhs, const String& rhs) { return 0 == lhs.compare(rhs); } +static inline bool operator== (const char* lhs, const String& rhs) { return 0 == rhs.compare(lhs); } +static inline bool operator== (const String& lhs, const char* rhs) { return 0 == lhs.compare(rhs); } +static inline bool operator!= (const String& lhs, const String& rhs) { return 0 != lhs.compare(rhs); } +static inline bool operator!= (const char* lhs, const String& rhs) { return 0 != rhs.compare(lhs); } +static inline bool operator!= (const String& lhs, const char* rhs) { return 0 != lhs.compare(rhs); } +static inline bool operator< (const String& lhs, const String& rhs) { return lhs.compare(rhs) < 0; } +static inline bool operator< (const char* lhs, const String& rhs) { return rhs.compare(lhs) > 0; } +static inline bool operator< (const String& lhs, const char* rhs) { return lhs.compare(rhs) < 0; } +static inline bool operator<= (const String& lhs, const String& rhs) { return lhs.compare(rhs) <= 0; } +static inline bool operator<= (const char* lhs, const String& rhs) { return rhs.compare(lhs) >= 0; } +static inline bool operator<= (const String& lhs, const char* rhs) { return lhs.compare(rhs) <= 0; } +static inline bool operator> (const String& lhs, const String& rhs) { return lhs.compare(rhs) > 0; } +static inline bool operator> (const char* lhs, const String& rhs) { return rhs.compare(lhs) < 0; } +static inline bool operator> (const String& lhs, const char* rhs) { return lhs.compare(rhs) > 0; } +static inline bool operator>= (const String& lhs, const String& rhs) { return lhs.compare(rhs) >= 0; } +static inline bool operator>= (const char* lhs, const String& rhs) { return rhs.compare(lhs) <= 0; } +static inline bool operator>= (const String& lhs, const char* rhs) { return lhs.compare(rhs) >= 0; } } // cv @@ -865,7 +931,11 @@ namespace std namespace cv #endif { - template<> inline void swap(cv::String& a, cv::String& b) { a.swap(b); } + template<> inline + void swap(cv::String& a, cv::String& b) + { + a.swap(b); + } } #endif //__OPENCV_CORE_CVSTD_HPP__ diff --git a/modules/core/include/opencv2/core/cvstd.inl.hpp b/modules/core/include/opencv2/core/cvstd.inl.hpp index 5602c81fdf..ab278bb6e7 100644 --- a/modules/core/include/opencv2/core/cvstd.inl.hpp +++ b/modules/core/include/opencv2/core/cvstd.inl.hpp @@ -68,7 +68,9 @@ public: typedef Vec vec_type; }; -inline String::String(const std::string& str) : cstr_(0), len_(0) +inline +String::String(const std::string& str) + : cstr_(0), len_(0) { if (!str.empty()) { @@ -77,7 +79,9 @@ inline String::String(const std::string& str) : cstr_(0), len_(0) } } -inline String::String(const std::string& str, size_t pos, size_t len) : cstr_(0), len_(0) +inline +String::String(const std::string& str, size_t pos, size_t len) + : cstr_(0), len_(0) { size_t strlen = str.size(); pos = max(pos, strlen); @@ -86,7 +90,8 @@ inline String::String(const std::string& str, size_t pos, size_t len) : cstr_(0) memcpy(allocate(len), str.c_str() + pos, len); } -inline String& String::operator=(const std::string& str) +inline +String& String::operator = (const std::string& str) { deallocate(); if (!str.empty()) @@ -97,12 +102,14 @@ inline String& String::operator=(const std::string& str) return *this; } -inline String::operator std::string() const +inline +String::operator std::string() const { return std::string(cstr_, len_); } -inline String operator+ (const String& lhs, const std::string& rhs) +inline +String operator + (const String& lhs, const std::string& rhs) { String s; size_t rhslen = rhs.size(); @@ -112,7 +119,8 @@ inline String operator+ (const String& lhs, const std::string& rhs) return s; } -inline String operator+ (const std::string& lhs, const String& rhs) +inline +String operator + (const std::string& lhs, const String& rhs) { String s; size_t lhslen = lhs.size(); @@ -122,30 +130,119 @@ inline String operator+ (const std::string& lhs, const String& rhs) return s; } -inline std::ostream& operator << (std::ostream& os, const String& str) -{ - return os << str.c_str(); -} - -inline FileNode::operator std::string() const +inline +FileNode::operator std::string() const { String value; read(*this, value, value); return value; } -template<> inline void operator >> (const FileNode& n, std::string& value) +template<> inline +void operator >> (const FileNode& n, std::string& value) { String val; read(n, val, val); value = val; } -template<> inline FileStorage& operator << (FileStorage& fs, const std::string& value) +template<> inline +FileStorage& operator << (FileStorage& fs, const std::string& value) { return fs << cv::String(value); } +static inline +std::ostream& operator << (std::ostream& os, const String& str) +{ + return os << str.c_str(); +} + +static inline +std::ostream& operator << (std::ostream& out, Ptr fmtd) +{ + fmtd->reset(); + for(const char* str = fmtd->next(); str; str = fmtd->next()) + out << str; + return out; +} + +static inline +std::ostream& operator << (std::ostream& out, const Mat& mtx) +{ + return out << Formatter::get()->format(mtx); +} + +template static inline +std::ostream& operator << (std::ostream& out, const std::vector >& vec) +{ + return out << Formatter::get()->format(Mat(vec)); +} + + +template static inline +std::ostream& operator << (std::ostream& out, const std::vector >& vec) +{ + return out << Formatter::get()->format(Mat(vec)); +} + + +template static inline +std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx) +{ + return out << Formatter::get()->format(matx); +} + +template static inline +std::ostream& operator << (std::ostream& out, const Point_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << "]"; + return out; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Point3_<_Tp>& p) +{ + out << "[" << p.x << ", " << p.y << ", " << p.z << "]"; + return out; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Vec<_Tp, n>& vec) +{ + out << "["; + + if(Vec<_Tp, n>::depth < CV_32F) + { + for (int i = 0; i < n - 1; ++i) { + out << (int)vec[i] << ", "; + } + out << (int)vec[n-1] << "]"; + } + else + { + for (int i = 0; i < n - 1; ++i) { + out << vec[i] << ", "; + } + out << vec[n-1] << "]"; + } + + return out; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Size_<_Tp>& size) +{ + return out << "[" << size.width << " x " << size.height << "]"; +} + +template static inline +std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect) +{ + return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; +} + + #endif // OPENCV_NOSTL } // cv diff --git a/modules/core/include/opencv2/core/eigen.hpp b/modules/core/include/opencv2/core/eigen.hpp index 6e47206c54..3005bfbfd4 100644 --- a/modules/core/include/opencv2/core/eigen.hpp +++ b/modules/core/include/opencv2/core/eigen.hpp @@ -12,6 +12,7 @@ // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -40,12 +41,10 @@ // //M*/ + #ifndef __OPENCV_CORE_EIGEN_HPP__ #define __OPENCV_CORE_EIGEN_HPP__ -#ifdef __cplusplus - -#include "opencv2/core/core_c.h" #include "opencv2/core.hpp" #if defined _MSC_VER && _MSC_VER >= 1200 @@ -57,7 +56,7 @@ namespace cv { -template +template static inline void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst ) { if( !(src.Flags & Eigen::RowMajorBit) ) @@ -75,7 +74,7 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo } // Matx case -template +template static inline void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Matx<_Tp, _rows, _cols>& dst ) { @@ -89,14 +88,14 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo } } -template +template static inline void cv2eigen( const Mat& src, Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) { CV_DbgAssert(src.rows == _rows && src.cols == _cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(src.cols, src.rows, DataType<_Tp>::type, + const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); @@ -107,46 +106,42 @@ void cv2eigen( const Mat& src, } else Mat(src.t()).convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(src.rows, src.cols, DataType<_Tp>::type, + const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } // Matx case -template +template static inline void cv2eigen( const Matx<_Tp, _rows, _cols>& src, Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) { if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(_cols, _rows, DataType<_Tp>::type, + const Mat _dst(_cols, _rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); transpose(src, _dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(_rows, _cols, DataType<_Tp>::type, + const Mat _dst(_rows, _cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); Mat(src).copyTo(_dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } -template +template static inline void cv2eigen( const Mat& src, Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) { dst.resize(src.rows, src.cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(src.cols, src.rows, DataType<_Tp>::type, + const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); @@ -157,40 +152,36 @@ void cv2eigen( const Mat& src, } else Mat(src.t()).convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(src.rows, src.cols, DataType<_Tp>::type, + const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } // Matx case -template +template static inline void cv2eigen( const Matx<_Tp, _rows, _cols>& src, Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst ) { dst.resize(_rows, _cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(_cols, _rows, DataType<_Tp>::type, + const Mat _dst(_cols, _rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); transpose(src, _dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(_rows, _cols, DataType<_Tp>::type, + const Mat _dst(_rows, _cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); Mat(src).copyTo(_dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } -template +template static inline void cv2eigen( const Mat& src, Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) { @@ -199,25 +190,23 @@ void cv2eigen( const Mat& src, if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(src.cols, src.rows, DataType<_Tp>::type, + const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); else Mat(src.t()).convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(src.rows, src.cols, DataType<_Tp>::type, + const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } // Matx case -template +template static inline void cv2eigen( const Matx<_Tp, _rows, 1>& src, Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst ) { @@ -225,22 +214,20 @@ void cv2eigen( const Matx<_Tp, _rows, 1>& src, if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(1, _rows, DataType<_Tp>::type, + const Mat _dst(1, _rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); transpose(src, _dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(_rows, 1, DataType<_Tp>::type, + const Mat _dst(_rows, 1, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); src.copyTo(_dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } -template +template static inline void cv2eigen( const Mat& src, Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) { @@ -248,49 +235,41 @@ void cv2eigen( const Mat& src, dst.resize(src.cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(src.cols, src.rows, DataType<_Tp>::type, + const Mat _dst(src.cols, src.rows, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); if( src.type() == _dst.type() ) transpose(src, _dst); else Mat(src.t()).convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(src.rows, src.cols, DataType<_Tp>::type, + const Mat _dst(src.rows, src.cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); src.convertTo(_dst, _dst.type()); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } //Matx -template +template static inline void cv2eigen( const Matx<_Tp, 1, _cols>& src, Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst ) { dst.resize(_cols); if( !(dst.Flags & Eigen::RowMajorBit) ) { - Mat _dst(_cols, 1, DataType<_Tp>::type, + const Mat _dst(_cols, 1, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); transpose(src, _dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } else { - Mat _dst(1, _cols, DataType<_Tp>::type, + const Mat _dst(1, _cols, DataType<_Tp>::type, dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); Mat(src).copyTo(_dst); - CV_DbgAssert(_dst.data == (uchar*)dst.data()); } } - -} +} // cv #endif - -#endif - diff --git a/modules/core/include/opencv2/core/gpumat.hpp b/modules/core/include/opencv2/core/gpumat.hpp index d0c729c948..60d37e5008 100644 --- a/modules/core/include/opencv2/core/gpumat.hpp +++ b/modules/core/include/opencv2/core/gpumat.hpp @@ -7,11 +7,12 @@ // copy or use the software. // // -// License Agreement +// License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, @@ -40,652 +41,687 @@ // //M*/ + #ifndef __OPENCV_GPUMAT_HPP__ #define __OPENCV_GPUMAT_HPP__ -#ifdef __cplusplus - #include "opencv2/core.hpp" #include "opencv2/core/cuda_devptrs.hpp" namespace cv { namespace gpu { - //////////////////////////////// CudaMem //////////////////////////////// - // CudaMem is limited cv::Mat with page locked memory allocation. - // Page locked memory is only needed for async and faster coping to GPU. - // It is convertable to cv::Mat header without reference counting - // so you can use it with other opencv functions. +//////////////////////////////// CudaMem //////////////////////////////// +// CudaMem is limited cv::Mat with page locked memory allocation. +// Page locked memory is only needed for async and faster coping to GPU. +// It is convertable to cv::Mat header without reference counting +// so you can use it with other opencv functions. - // Page-locks the matrix m memory and maps it for the device(s) - CV_EXPORTS void registerPageLocked(Mat& m); - // Unmaps the memory of matrix m, and makes it pageable again. - CV_EXPORTS void unregisterPageLocked(Mat& m); +// Page-locks the matrix m memory and maps it for the device(s) +CV_EXPORTS void registerPageLocked(Mat& m); - class CV_EXPORTS CudaMem - { - public: - enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 }; +// Unmaps the memory of matrix m, and makes it pageable again. +CV_EXPORTS void unregisterPageLocked(Mat& m); - CudaMem(); - CudaMem(const CudaMem& m); +class CV_EXPORTS CudaMem +{ +public: + enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 }; - CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED); - CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED); + CudaMem(); + CudaMem(const CudaMem& m); + CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED); + CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED); - //! creates from cv::Mat with coping data - explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED); - ~CudaMem(); + //! creates from cv::Mat with coping data + explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED); - CudaMem& operator = (const CudaMem& m); + ~CudaMem(); - //! returns deep copy of the matrix, i.e. the data is copied - CudaMem clone() const; + CudaMem& operator = (const CudaMem& m); - //! allocates new matrix data unless the matrix already has specified size and type. - void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED); - void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED); + //! returns deep copy of the matrix, i.e. the data is copied + CudaMem clone() const; - //! decrements reference counter and released memory if needed. - void release(); + //! allocates new matrix data unless the matrix already has specified size and type. + void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED); + void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED); - //! returns matrix header with disabled reference counting for CudaMem data. - Mat createMatHeader() const; - operator Mat() const; + //! decrements reference counter and released memory if needed. + void release(); - //! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware. - GpuMat createGpuMatHeader() const; - operator GpuMat() const; + //! returns matrix header with disabled reference counting for CudaMem data. + Mat createMatHeader() const; + operator Mat() const; - //returns if host memory can be mapperd to gpu address space; - static bool canMapHostMemory(); + //! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware. + GpuMat createGpuMatHeader() const; + operator GpuMat() const; - // Please see cv::Mat for descriptions - bool isContinuous() const; - size_t elemSize() const; - size_t elemSize1() const; - int type() const; - int depth() const; - int channels() const; - size_t step1() const; - Size size() const; - bool empty() const; + //returns if host memory can be mapperd to gpu address space; + static bool canMapHostMemory(); + // Please see cv::Mat for descriptions + bool isContinuous() const; + size_t elemSize() const; + size_t elemSize1() const; + int type() const; + int depth() const; + int channels() const; + size_t step1() const; + Size size() const; + bool empty() const; - // Please see cv::Mat for descriptions - int flags; - int rows, cols; - size_t step; - uchar* data; - int* refcount; + // Please see cv::Mat for descriptions + int flags; + int rows, cols; + size_t step; - uchar* datastart; - uchar* dataend; + uchar* data; + int* refcount; - int alloc_type; - }; + uchar* datastart; + uchar* dataend; + int alloc_type; +}; - //////////////////////////////// CudaStream //////////////////////////////// - // Encapculates Cuda Stream. Provides interface for async coping. - // Passed to each function that supports async kernel execution. - // Reference counting is enabled - class CV_EXPORTS Stream - { - public: - Stream(); - ~Stream(); +//////////////////////////////// CudaStream //////////////////////////////// +// Encapculates Cuda Stream. Provides interface for async coping. +// Passed to each function that supports async kernel execution. +// Reference counting is enabled - Stream(const Stream&); - Stream& operator =(const Stream&); +class CV_EXPORTS Stream +{ +public: + Stream(); + ~Stream(); - bool queryIfComplete(); - void waitForCompletion(); + Stream(const Stream&); + Stream& operator =(const Stream&); - //! downloads asynchronously - // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat) - void enqueueDownload(const GpuMat& src, CudaMem& dst); - void enqueueDownload(const GpuMat& src, Mat& dst); + bool queryIfComplete(); + void waitForCompletion(); - //! uploads asynchronously - // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI) - void enqueueUpload(const CudaMem& src, GpuMat& dst); - void enqueueUpload(const Mat& src, GpuMat& dst); + //! downloads asynchronously + // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat) + void enqueueDownload(const GpuMat& src, CudaMem& dst); + void enqueueDownload(const GpuMat& src, Mat& dst); - //! copy asynchronously - void enqueueCopy(const GpuMat& src, GpuMat& dst); + //! uploads asynchronously + // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI) + void enqueueUpload(const CudaMem& src, GpuMat& dst); + void enqueueUpload(const Mat& src, GpuMat& dst); - //! memory set asynchronously - void enqueueMemSet(GpuMat& src, Scalar val); - void enqueueMemSet(GpuMat& src, Scalar val, const GpuMat& mask); + //! copy asynchronously + void enqueueCopy(const GpuMat& src, GpuMat& dst); - //! converts matrix type, ex from float to uchar depending on type - void enqueueConvert(const GpuMat& src, GpuMat& dst, int dtype, double a = 1, double b = 0); + //! memory set asynchronously + void enqueueMemSet(GpuMat& src, Scalar val); + void enqueueMemSet(GpuMat& src, Scalar val, const GpuMat& mask); - //! adds a callback to be called on the host after all currently enqueued items in the stream have completed - typedef void (*StreamCallback)(Stream& stream, int status, void* userData); - void enqueueHostCallback(StreamCallback callback, void* userData); + //! converts matrix type, ex from float to uchar depending on type + void enqueueConvert(const GpuMat& src, GpuMat& dst, int dtype, double a = 1, double b = 0); - static Stream& Null(); + //! adds a callback to be called on the host after all currently enqueued items in the stream have completed + typedef void (*StreamCallback)(Stream& stream, int status, void* userData); + void enqueueHostCallback(StreamCallback callback, void* userData); - operator bool() const; + static Stream& Null(); - private: - struct Impl; + operator bool() const; - explicit Stream(Impl* impl); - void create(); - void release(); +private: + struct Impl; - Impl *impl; + explicit Stream(Impl* impl); + void create(); + void release(); - friend struct StreamAccessor; - }; + Impl *impl; - //////////////////////////////// Initialization & Info //////////////////////// + friend struct StreamAccessor; +}; - //! This is the only function that do not throw exceptions if the library is compiled without Cuda. - CV_EXPORTS int getCudaEnabledDeviceCount(); +//////////////////////////////// Initialization & Info //////////////////////// - //! Functions below throw cv::Expception if the library is compiled without Cuda. +//! This is the only function that do not throw exceptions if the library is compiled without Cuda. +CV_EXPORTS int getCudaEnabledDeviceCount(); - CV_EXPORTS void setDevice(int device); - CV_EXPORTS int getDevice(); +//! Functions below throw cv::Expception if the library is compiled without Cuda. - //! Explicitly destroys and cleans up all resources associated with the current device in the current process. - //! Any subsequent API call to this device will reinitialize the device. - CV_EXPORTS void resetDevice(); +CV_EXPORTS void setDevice(int device); - enum FeatureSet - { - FEATURE_SET_COMPUTE_10 = 10, - FEATURE_SET_COMPUTE_11 = 11, - FEATURE_SET_COMPUTE_12 = 12, - FEATURE_SET_COMPUTE_13 = 13, - FEATURE_SET_COMPUTE_20 = 20, - FEATURE_SET_COMPUTE_21 = 21, - FEATURE_SET_COMPUTE_30 = 30, - FEATURE_SET_COMPUTE_35 = 35, - - GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11, - SHARED_ATOMICS = FEATURE_SET_COMPUTE_12, - NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13, - WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30, - DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35 - }; - - // Checks whether current device supports the given feature - CV_EXPORTS bool deviceSupports(FeatureSet feature_set); - - // Gives information about what GPU archs this OpenCV GPU module was - // compiled for - class CV_EXPORTS TargetArchs - { - public: - static bool builtWith(FeatureSet feature_set); - static bool has(int major, int minor); - static bool hasPtx(int major, int minor); - static bool hasBin(int major, int minor); - static bool hasEqualOrLessPtx(int major, int minor); - static bool hasEqualOrGreater(int major, int minor); - static bool hasEqualOrGreaterPtx(int major, int minor); - static bool hasEqualOrGreaterBin(int major, int minor); - private: - TargetArchs(); - }; - - // Gives information about the given GPU - class CV_EXPORTS DeviceInfo - { - public: - // Creates DeviceInfo object for the current GPU - DeviceInfo() : device_id_(getDevice()) { query(); } +CV_EXPORTS int getDevice(); - // Creates DeviceInfo object for the given GPU - DeviceInfo(int device_id) : device_id_(device_id) { query(); } +//! Explicitly destroys and cleans up all resources associated with the current device in the current process. +//! Any subsequent API call to this device will reinitialize the device. +CV_EXPORTS void resetDevice(); - String name() const { return name_; } +enum FeatureSet +{ + FEATURE_SET_COMPUTE_10 = 10, + FEATURE_SET_COMPUTE_11 = 11, + FEATURE_SET_COMPUTE_12 = 12, + FEATURE_SET_COMPUTE_13 = 13, + FEATURE_SET_COMPUTE_20 = 20, + FEATURE_SET_COMPUTE_21 = 21, + FEATURE_SET_COMPUTE_30 = 30, + FEATURE_SET_COMPUTE_35 = 35, + + GLOBAL_ATOMICS = FEATURE_SET_COMPUTE_11, + SHARED_ATOMICS = FEATURE_SET_COMPUTE_12, + NATIVE_DOUBLE = FEATURE_SET_COMPUTE_13, + WARP_SHUFFLE_FUNCTIONS = FEATURE_SET_COMPUTE_30, + DYNAMIC_PARALLELISM = FEATURE_SET_COMPUTE_35 +}; + +// Checks whether current device supports the given feature +CV_EXPORTS bool deviceSupports(FeatureSet feature_set); + +// Gives information about what GPU archs this OpenCV GPU module was +// compiled for +class CV_EXPORTS TargetArchs +{ +public: + static bool builtWith(FeatureSet feature_set); + static bool has(int major, int minor); + static bool hasPtx(int major, int minor); + static bool hasBin(int major, int minor); + static bool hasEqualOrLessPtx(int major, int minor); + static bool hasEqualOrGreater(int major, int minor); + static bool hasEqualOrGreaterPtx(int major, int minor); + static bool hasEqualOrGreaterBin(int major, int minor); +private: + TargetArchs(); +}; + +// Gives information about the given GPU +class CV_EXPORTS DeviceInfo +{ +public: + // Creates DeviceInfo object for the current GPU + DeviceInfo() : device_id_(getDevice()) { query(); } - // Return compute capability versions - int majorVersion() const { return majorVersion_; } - int minorVersion() const { return minorVersion_; } + // Creates DeviceInfo object for the given GPU + DeviceInfo(int device_id) : device_id_(device_id) { query(); } - int multiProcessorCount() const { return multi_processor_count_; } + String name() const { return name_; } - size_t sharedMemPerBlock() const; + // Return compute capability versions + int majorVersion() const { return majorVersion_; } + int minorVersion() const { return minorVersion_; } - void queryMemory(size_t& totalMemory, size_t& freeMemory) const; - size_t freeMemory() const; - size_t totalMemory() const; + int multiProcessorCount() const { return multi_processor_count_; } - // Checks whether device supports the given feature - bool supports(FeatureSet feature_set) const; + size_t sharedMemPerBlock() const; - // Checks whether the GPU module can be run on the given device - bool isCompatible() const; + void queryMemory(size_t& totalMemory, size_t& freeMemory) const; + size_t freeMemory() const; + size_t totalMemory() const; - int deviceID() const { return device_id_; } + // Checks whether device supports the given feature + bool supports(FeatureSet feature_set) const; - private: - void query(); + // Checks whether the GPU module can be run on the given device + bool isCompatible() const; - int device_id_; + int deviceID() const { return device_id_; } - String name_; - int multi_processor_count_; - int majorVersion_; - int minorVersion_; - }; +private: + void query(); - CV_EXPORTS void printCudaDeviceInfo(int device); - CV_EXPORTS void printShortCudaDeviceInfo(int device); + int device_id_; - //////////////////////////////// GpuMat /////////////////////////////// + String name_; + int multi_processor_count_; + int majorVersion_; + int minorVersion_; +}; - //! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat. - class CV_EXPORTS GpuMat - { - public: - //! default constructor - GpuMat(); - - //! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) - GpuMat(int rows, int cols, int type); - GpuMat(Size size, int type); - - //! constucts GpuMatrix and fills it with the specified value _s. - GpuMat(int rows, int cols, int type, Scalar s); - GpuMat(Size size, int type, Scalar s); - - //! copy constructor - GpuMat(const GpuMat& m); - - //! constructor for GpuMatrix headers pointing to user-allocated data - GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP); - GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP); - - //! creates a matrix header for a part of the bigger matrix - GpuMat(const GpuMat& m, Range rowRange, Range colRange); - GpuMat(const GpuMat& m, Rect roi); - - //! builds GpuMat from Mat. Perfom blocking upload to device. - explicit GpuMat(const Mat& m); - - //! destructor - calls release() - ~GpuMat(); - - //! assignment operators - GpuMat& operator = (const GpuMat& m); - - //! pefroms blocking upload data to GpuMat. - void upload(const Mat& m); - - //! downloads data from device to host memory. Blocking calls. - void download(Mat& m) const; - - //! returns a new GpuMatrix header for the specified row - GpuMat row(int y) const; - //! returns a new GpuMatrix header for the specified column - GpuMat col(int x) const; - //! ... for the specified row span - GpuMat rowRange(int startrow, int endrow) const; - GpuMat rowRange(Range r) const; - //! ... for the specified column span - GpuMat colRange(int startcol, int endcol) const; - GpuMat colRange(Range r) const; - - //! returns deep copy of the GpuMatrix, i.e. the data is copied - GpuMat clone() const; - //! copies the GpuMatrix content to "m". - // It calls m.create(this->size(), this->type()). - void copyTo(GpuMat& m) const; - //! copies those GpuMatrix elements to "m" that are marked with non-zero mask elements. - void copyTo(GpuMat& m, const GpuMat& mask) const; - //! converts GpuMatrix to another datatype with optional scalng. See cvConvertScale. - void convertTo(GpuMat& m, int rtype, double alpha = 1, double beta = 0) const; - - void assignTo(GpuMat& m, int type=-1) const; - - //! sets every GpuMatrix element to s - GpuMat& operator = (Scalar s); - //! sets some of the GpuMatrix elements to s, according to the mask - GpuMat& setTo(Scalar s, const GpuMat& mask = GpuMat()); - //! creates alternative GpuMatrix header for the same data, with different - // number of channels and/or different number of rows. see cvReshape. - GpuMat reshape(int cn, int rows = 0) const; - - //! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type. - // previous data is unreferenced if needed. - void create(int rows, int cols, int type); - void create(Size size, int type); - //! decreases reference counter; - // deallocate the data when reference counter reaches 0. - void release(); - - //! swaps with other smart pointer - void swap(GpuMat& mat); - - //! locates GpuMatrix header within a parent GpuMatrix. See below - void locateROI(Size& wholeSize, Point& ofs) const; - //! moves/resizes the current GpuMatrix ROI inside the parent GpuMatrix. - GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright); - //! extracts a rectangular sub-GpuMatrix - // (this is a generalized form of row, rowRange etc.) - GpuMat operator()(Range rowRange, Range colRange) const; - GpuMat operator()(Rect roi) const; - - //! returns true iff the GpuMatrix data is continuous - // (i.e. when there are no gaps between successive rows). - // similar to CV_IS_GpuMat_CONT(cvGpuMat->type) - bool isContinuous() const; - //! returns element size in bytes, - // similar to CV_ELEM_SIZE(cvMat->type) - size_t elemSize() const; - //! returns the size of element channel in bytes. - size_t elemSize1() const; - //! returns element type, similar to CV_MAT_TYPE(cvMat->type) - int type() const; - //! returns element type, similar to CV_MAT_DEPTH(cvMat->type) - int depth() const; - //! returns element type, similar to CV_MAT_CN(cvMat->type) - int channels() const; - //! returns step/elemSize1() - size_t step1() const; - //! returns GpuMatrix size: - // width == number of columns, height == number of rows - Size size() const; - //! returns true if GpuMatrix data is NULL - bool empty() const; - - //! returns pointer to y-th row - uchar* ptr(int y = 0); - const uchar* ptr(int y = 0) const; - - //! template version of the above method - template _Tp* ptr(int y = 0); - template const _Tp* ptr(int y = 0) const; - - template operator PtrStepSz<_Tp>() const; - template operator PtrStep<_Tp>() const; - - // Deprecated function - __CV_GPU_DEPR_BEFORE__ template operator DevMem2D_<_Tp>() const __CV_GPU_DEPR_AFTER__; - #undef __CV_GPU_DEPR_BEFORE__ - #undef __CV_GPU_DEPR_AFTER__ - - /*! includes several bit-fields: - - the magic signature - - continuity flag - - depth - - number of channels - */ - int flags; - - //! the number of rows and columns - int rows, cols; - - //! a distance between successive rows in bytes; includes the gap if any - size_t step; - - //! pointer to the data - uchar* data; - - //! pointer to the reference counter; - // when GpuMatrix points to user-allocated data, the pointer is NULL - int* refcount; - - //! helper fields used in locateROI and adjustROI - uchar* datastart; - uchar* dataend; - }; - - //! Creates continuous GPU matrix - CV_EXPORTS void createContinuous(int rows, int cols, int type, GpuMat& m); - CV_EXPORTS GpuMat createContinuous(int rows, int cols, int type); - CV_EXPORTS void createContinuous(Size size, int type, GpuMat& m); - CV_EXPORTS GpuMat createContinuous(Size size, int type); - - //! Ensures that size of the given matrix is not less than (rows, cols) size - //! and matrix type is match specified one too - CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m); - CV_EXPORTS void ensureSizeIsEnough(Size size, int type, GpuMat& m); - - CV_EXPORTS GpuMat allocMatFromBuf(int rows, int cols, int type, GpuMat &mat); - - //////////////////////////////////////////////////////////////////////// - // Error handling - - CV_EXPORTS void error(const char* error_string, const char* file, const int line, const char* func = ""); - - //////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////// - - inline GpuMat::GpuMat() - : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) - { - } +CV_EXPORTS void printCudaDeviceInfo(int device); - inline GpuMat::GpuMat(int rows_, int cols_, int type_) - : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) - { - if (rows_ > 0 && cols_ > 0) - create(rows_, cols_, type_); - } +CV_EXPORTS void printShortCudaDeviceInfo(int device); - inline GpuMat::GpuMat(Size size_, int type_) - : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) - { - if (size_.height > 0 && size_.width > 0) - create(size_.height, size_.width, type_); - } +//////////////////////////////// GpuMat /////////////////////////////// - inline GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_) - : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) - { - if (rows_ > 0 && cols_ > 0) - { - create(rows_, cols_, type_); - setTo(s_); - } - } +//! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat. +class CV_EXPORTS GpuMat +{ +public: + //! default constructor + GpuMat(); + + //! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.) + GpuMat(int rows, int cols, int type); + GpuMat(Size size, int type); + + //! constucts GpuMatrix and fills it with the specified value _s. + GpuMat(int rows, int cols, int type, Scalar s); + GpuMat(Size size, int type, Scalar s); + + //! copy constructor + GpuMat(const GpuMat& m); + + //! constructor for GpuMatrix headers pointing to user-allocated data + GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP); + GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP); + + //! creates a matrix header for a part of the bigger matrix + GpuMat(const GpuMat& m, Range rowRange, Range colRange); + GpuMat(const GpuMat& m, Rect roi); + + //! builds GpuMat from Mat. Perfom blocking upload to device. + explicit GpuMat(const Mat& m); + + //! destructor - calls release() + ~GpuMat(); + + //! assignment operators + GpuMat& operator = (const GpuMat& m); + + //! pefroms blocking upload data to GpuMat. + void upload(const Mat& m); + + //! downloads data from device to host memory. Blocking calls. + void download(Mat& m) const; + + //! returns a new GpuMatrix header for the specified row + GpuMat row(int y) const; + //! returns a new GpuMatrix header for the specified column + GpuMat col(int x) const; + //! ... for the specified row span + GpuMat rowRange(int startrow, int endrow) const; + GpuMat rowRange(Range r) const; + //! ... for the specified column span + GpuMat colRange(int startcol, int endcol) const; + GpuMat colRange(Range r) const; + + //! returns deep copy of the GpuMatrix, i.e. the data is copied + GpuMat clone() const; + //! copies the GpuMatrix content to "m". + // It calls m.create(this->size(), this->type()). + void copyTo(GpuMat& m) const; + //! copies those GpuMatrix elements to "m" that are marked with non-zero mask elements. + void copyTo(GpuMat& m, const GpuMat& mask) const; + //! converts GpuMatrix to another datatype with optional scalng. See cvConvertScale. + void convertTo(GpuMat& m, int rtype, double alpha = 1, double beta = 0) const; + + void assignTo(GpuMat& m, int type=-1) const; + + //! sets every GpuMatrix element to s + GpuMat& operator = (Scalar s); + //! sets some of the GpuMatrix elements to s, according to the mask + GpuMat& setTo(Scalar s, const GpuMat& mask = GpuMat()); + //! creates alternative GpuMatrix header for the same data, with different + // number of channels and/or different number of rows. see cvReshape. + GpuMat reshape(int cn, int rows = 0) const; + + //! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type. + // previous data is unreferenced if needed. + void create(int rows, int cols, int type); + void create(Size size, int type); + //! decreases reference counter; + // deallocate the data when reference counter reaches 0. + void release(); + + //! swaps with other smart pointer + void swap(GpuMat& mat); + + //! locates GpuMatrix header within a parent GpuMatrix. See below + void locateROI(Size& wholeSize, Point& ofs) const; + //! moves/resizes the current GpuMatrix ROI inside the parent GpuMatrix. + GpuMat& adjustROI(int dtop, int dbottom, int dleft, int dright); + //! extracts a rectangular sub-GpuMatrix + // (this is a generalized form of row, rowRange etc.) + GpuMat operator()(Range rowRange, Range colRange) const; + GpuMat operator()(Rect roi) const; + + //! returns true iff the GpuMatrix data is continuous + // (i.e. when there are no gaps between successive rows). + // similar to CV_IS_GpuMat_CONT(cvGpuMat->type) + bool isContinuous() const; + //! returns element size in bytes, + // similar to CV_ELEM_SIZE(cvMat->type) + size_t elemSize() const; + //! returns the size of element channel in bytes. + size_t elemSize1() const; + //! returns element type, similar to CV_MAT_TYPE(cvMat->type) + int type() const; + //! returns element type, similar to CV_MAT_DEPTH(cvMat->type) + int depth() const; + //! returns element type, similar to CV_MAT_CN(cvMat->type) + int channels() const; + //! returns step/elemSize1() + size_t step1() const; + //! returns GpuMatrix size: + // width == number of columns, height == number of rows + Size size() const; + //! returns true if GpuMatrix data is NULL + bool empty() const; + + //! returns pointer to y-th row + uchar* ptr(int y = 0); + const uchar* ptr(int y = 0) const; + + //! template version of the above method + template _Tp* ptr(int y = 0); + template const _Tp* ptr(int y = 0) const; + + template operator PtrStepSz<_Tp>() const; + template operator PtrStep<_Tp>() const; + + // Deprecated function + __CV_GPU_DEPR_BEFORE__ template operator DevMem2D_<_Tp>() const __CV_GPU_DEPR_AFTER__; + #undef __CV_GPU_DEPR_BEFORE__ + #undef __CV_GPU_DEPR_AFTER__ + + /*! includes several bit-fields: + - the magic signature + - continuity flag + - depth + - number of channels + */ + int flags; + + //! the number of rows and columns + int rows, cols; + + //! a distance between successive rows in bytes; includes the gap if any + size_t step; + + //! pointer to the data + uchar* data; + + //! pointer to the reference counter; + // when GpuMatrix points to user-allocated data, the pointer is NULL + int* refcount; + + //! helper fields used in locateROI and adjustROI + uchar* datastart; + uchar* dataend; +}; + +//! Creates continuous GPU matrix +CV_EXPORTS void createContinuous(int rows, int cols, int type, GpuMat& m); + +//! Ensures that size of the given matrix is not less than (rows, cols) size +//! and matrix type is match specified one too +CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m); + +CV_EXPORTS GpuMat allocMatFromBuf(int rows, int cols, int type, GpuMat &mat); + +//////////////////////////////////////////////////////////////////////// +// Error handling + +CV_EXPORTS void error(const char* error_string, const char* file, const int line, const char* func = ""); + +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////// + +inline +GpuMat::GpuMat() + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) +{} + +inline +GpuMat::GpuMat(int rows_, int cols_, int type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) +{ + if (rows_ > 0 && cols_ > 0) + create(rows_, cols_, type_); +} - inline GpuMat::GpuMat(Size size_, int type_, Scalar s_) - : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) - { - if (size_.height > 0 && size_.width > 0) - { - create(size_.height, size_.width, type_); - setTo(s_); - } - } +inline +GpuMat::GpuMat(Size size_, int type_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) +{ + if (size_.height > 0 && size_.width > 0) + create(size_.height, size_.width, type_); +} - inline GpuMat::~GpuMat() +inline +GpuMat::GpuMat(int rows_, int cols_, int type_, Scalar s_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) +{ + if (rows_ > 0 && cols_ > 0) { - release(); + create(rows_, cols_, type_); + setTo(s_); } +} - inline GpuMat GpuMat::clone() const +inline +GpuMat::GpuMat(Size size_, int type_, Scalar s_) + : flags(0), rows(0), cols(0), step(0), data(0), refcount(0), datastart(0), dataend(0) +{ + if (size_.height > 0 && size_.width > 0) { - GpuMat m; - copyTo(m); - return m; + create(size_.height, size_.width, type_); + setTo(s_); } +} - inline void GpuMat::assignTo(GpuMat& m, int _type) const - { - if (_type < 0) - m = *this; - else - convertTo(m, _type); - } +inline +GpuMat::~GpuMat() +{ + release(); +} - inline size_t GpuMat::step1() const - { - return step / elemSize1(); - } +inline +GpuMat GpuMat::clone() const +{ + GpuMat m; + copyTo(m); + return m; +} - inline bool GpuMat::empty() const - { - return data == 0; - } +inline +void GpuMat::assignTo(GpuMat& m, int _type) const +{ + if (_type < 0) + m = *this; + else + convertTo(m, _type); +} + +inline +size_t GpuMat::step1() const +{ + return step / elemSize1(); +} - template inline _Tp* GpuMat::ptr(int y) - { - return (_Tp*)ptr(y); - } +inline +bool GpuMat::empty() const +{ + return data == 0; +} - template inline const _Tp* GpuMat::ptr(int y) const - { - return (const _Tp*)ptr(y); - } +template inline +_Tp* GpuMat::ptr(int y) +{ + return (_Tp*)ptr(y); +} - inline void swap(GpuMat& a, GpuMat& b) - { - a.swap(b); - } +template inline +const _Tp* GpuMat::ptr(int y) const +{ + return (const _Tp*)ptr(y); +} - inline GpuMat GpuMat::row(int y) const - { - return GpuMat(*this, Range(y, y+1), Range::all()); - } +inline +GpuMat GpuMat::row(int y) const +{ + return GpuMat(*this, Range(y, y+1), Range::all()); +} - inline GpuMat GpuMat::col(int x) const - { - return GpuMat(*this, Range::all(), Range(x, x+1)); - } +inline +GpuMat GpuMat::col(int x) const +{ + return GpuMat(*this, Range::all(), Range(x, x+1)); +} - inline GpuMat GpuMat::rowRange(int startrow, int endrow) const - { - return GpuMat(*this, Range(startrow, endrow), Range::all()); - } +inline +GpuMat GpuMat::rowRange(int startrow, int endrow) const +{ + return GpuMat(*this, Range(startrow, endrow), Range::all()); +} - inline GpuMat GpuMat::rowRange(Range r) const - { - return GpuMat(*this, r, Range::all()); - } +inline +GpuMat GpuMat::rowRange(Range r) const +{ + return GpuMat(*this, r, Range::all()); +} - inline GpuMat GpuMat::colRange(int startcol, int endcol) const - { - return GpuMat(*this, Range::all(), Range(startcol, endcol)); - } +inline +GpuMat GpuMat::colRange(int startcol, int endcol) const +{ + return GpuMat(*this, Range::all(), Range(startcol, endcol)); +} - inline GpuMat GpuMat::colRange(Range r) const - { - return GpuMat(*this, Range::all(), r); - } +inline +GpuMat GpuMat::colRange(Range r) const +{ + return GpuMat(*this, Range::all(), r); +} - inline void GpuMat::create(Size size_, int type_) - { - create(size_.height, size_.width, type_); - } +inline +void GpuMat::create(Size size_, int type_) +{ + create(size_.height, size_.width, type_); +} - inline GpuMat GpuMat::operator()(Range _rowRange, Range _colRange) const - { - return GpuMat(*this, _rowRange, _colRange); - } +inline +GpuMat GpuMat::operator()(Range _rowRange, Range _colRange) const +{ + return GpuMat(*this, _rowRange, _colRange); +} - inline GpuMat GpuMat::operator()(Rect roi) const - { - return GpuMat(*this, roi); - } +inline +GpuMat GpuMat::operator()(Rect roi) const +{ + return GpuMat(*this, roi); +} - inline bool GpuMat::isContinuous() const - { - return (flags & Mat::CONTINUOUS_FLAG) != 0; - } +inline +bool GpuMat::isContinuous() const +{ + return (flags & Mat::CONTINUOUS_FLAG) != 0; +} - inline size_t GpuMat::elemSize() const - { - return CV_ELEM_SIZE(flags); - } +inline +size_t GpuMat::elemSize() const +{ + return CV_ELEM_SIZE(flags); +} - inline size_t GpuMat::elemSize1() const - { - return CV_ELEM_SIZE1(flags); - } +inline +size_t GpuMat::elemSize1() const +{ + return CV_ELEM_SIZE1(flags); +} - inline int GpuMat::type() const - { - return CV_MAT_TYPE(flags); - } +inline +int GpuMat::type() const +{ + return CV_MAT_TYPE(flags); +} - inline int GpuMat::depth() const - { - return CV_MAT_DEPTH(flags); - } +inline +int GpuMat::depth() const +{ + return CV_MAT_DEPTH(flags); +} - inline int GpuMat::channels() const - { - return CV_MAT_CN(flags); - } +inline +int GpuMat::channels() const +{ + return CV_MAT_CN(flags); +} - inline Size GpuMat::size() const - { - return Size(cols, rows); - } +inline +Size GpuMat::size() const +{ + return Size(cols, rows); +} - inline uchar* GpuMat::ptr(int y) - { - CV_DbgAssert((unsigned)y < (unsigned)rows); - return data + step * y; - } +inline +uchar* GpuMat::ptr(int y) +{ + CV_DbgAssert((unsigned)y < (unsigned)rows); + return data + step * y; +} - inline const uchar* GpuMat::ptr(int y) const - { - CV_DbgAssert((unsigned)y < (unsigned)rows); - return data + step * y; - } +inline +const uchar* GpuMat::ptr(int y) const +{ + CV_DbgAssert((unsigned)y < (unsigned)rows); + return data + step * y; +} - inline GpuMat& GpuMat::operator = (Scalar s) - { - setTo(s); - return *this; - } +inline +GpuMat& GpuMat::operator = (Scalar s) +{ + setTo(s); + return *this; +} - template inline GpuMat::operator PtrStepSz() const - { - return PtrStepSz(rows, cols, (T*)data, step); - } +template inline +GpuMat::operator PtrStepSz() const +{ + return PtrStepSz(rows, cols, (T*)data, step); +} - template inline GpuMat::operator PtrStep() const - { - return PtrStep((T*)data, step); - } +template inline +GpuMat::operator PtrStep() const +{ + return PtrStep((T*)data, step); +} - template inline GpuMat::operator DevMem2D_() const - { - return DevMem2D_(rows, cols, (T*)data, step); - } +template inline +GpuMat::operator DevMem2D_() const +{ + return DevMem2D_(rows, cols, (T*)data, step); +} - inline GpuMat createContinuous(int rows, int cols, int type) - { - GpuMat m; - createContinuous(rows, cols, type, m); - return m; - } +static inline +void swap(GpuMat& a, GpuMat& b) +{ + a.swap(b); +} - inline void createContinuous(Size size, int type, GpuMat& m) - { - createContinuous(size.height, size.width, type, m); - } +static inline +GpuMat createContinuous(int rows, int cols, int type) +{ + GpuMat m; + createContinuous(rows, cols, type, m); + return m; +} - inline GpuMat createContinuous(Size size, int type) - { - GpuMat m; - createContinuous(size, type, m); - return m; - } +static inline +void createContinuous(Size size, int type, GpuMat& m) +{ + createContinuous(size.height, size.width, type, m); +} - inline void ensureSizeIsEnough(Size size, int type, GpuMat& m) - { - ensureSizeIsEnough(size.height, size.width, type, m); - } -}} +static inline +GpuMat createContinuous(Size size, int type) +{ + GpuMat m; + createContinuous(size, type, m); + return m; +} + +static inline +void ensureSizeIsEnough(Size size, int type, GpuMat& m) +{ + ensureSizeIsEnough(size.height, size.width, type, m); +} -#endif // __cplusplus +}} // cv::gpu #endif // __OPENCV_GPUMAT_HPP__ diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 3b480e7fd2..a5ecea8dce 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -47,11 +47,6 @@ # error mat.inl.hpp header must be compiled as C++ #endif -#ifndef SKIP_INCLUDES -#include -#include -#endif // SKIP_INCLUDES - namespace cv { diff --git a/modules/core/include/opencv2/core/opengl.hpp b/modules/core/include/opencv2/core/opengl.hpp index 2e428bc0c4..a7a7ae5029 100644 --- a/modules/core/include/opencv2/core/opengl.hpp +++ b/modules/core/include/opencv2/core/opengl.hpp @@ -43,8 +43,6 @@ #ifndef __OPENCV_OPENGL_INTEROP_HPP__ #define __OPENCV_OPENGL_INTEROP_HPP__ -#ifdef __cplusplus - #include "opencv2/core.hpp" namespace cv { namespace ogl { @@ -269,7 +267,7 @@ namespace cv { namespace gpu { //! set a CUDA device to use OpenGL interoperability CV_EXPORTS void setGlDevice(int device = 0); -}} +}} // cv::gpu namespace cv { @@ -278,6 +276,4 @@ template <> CV_EXPORTS void Ptr::delete_obj(); } -#endif // __cplusplus - #endif // __OPENCV_OPENGL_INTEROP_HPP__ diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 398fd8564a..7d39154a16 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -47,12 +47,7 @@ # error operations.hpp header must be compiled as C++ #endif -#ifndef SKIP_INCLUDES - #include - #include -#endif // SKIP_INCLUDES - -#include +#include namespace cv { @@ -356,6 +351,7 @@ inline unsigned RNG::next() } + ///////////////////////////////////////// LineIterator //////////////////////////////////////// inline @@ -398,39 +394,8 @@ template static inline _Tp randu() } -////////////////////////////////////////////////////////////////////////////// - -class CV_EXPORTS Formatted -{ -public: - virtual const char* next() = 0; - virtual void reset() = 0; - virtual ~Formatted(); -}; - - -class CV_EXPORTS Formatter -{ -public: - enum { FMT_MATLAB = 0, - FMT_CSV = 1, - FMT_PYTHON = 2, - FMT_NUMPY = 3, - FMT_C = 4, - FMT_DEFAULT = FMT_MATLAB - }; - - virtual ~Formatter(); - - virtual Ptr format(const Mat& mtx) const = 0; - - virtual void set32fPrecision(int p = 8) = 0; - virtual void set64fPrecision(int p = 16) = 0; - virtual void setMultiline(bool ml = true) = 0; - static Ptr get(int fmt = FMT_DEFAULT); - -}; +///////////////////////////////// Formatted output of cv::Mat ///////////////////////////////// static inline Ptr format(InputArray mtx, int fmt) @@ -438,111 +403,53 @@ Ptr format(InputArray mtx, int fmt) return Formatter::get(fmt)->format(mtx.getMat()); } - static inline -std::ostream& operator << (std::ostream& out, Ptr fmtd) +int print(Ptr fmtd, FILE* stream = stdout) { + int written = 0; fmtd->reset(); for(const char* str = fmtd->next(); str; str = fmtd->next()) - out << str; - return out; + written += fputs(str, stream); + + return written; } static inline -std::ostream& operator << (std::ostream& out, const Mat& mtx) +int print(const Mat& mtx, FILE* stream = stdout) { - return out << Formatter::get()->format(mtx); + return print(Formatter::get()->format(mtx), stream); } template static inline -std::ostream& operator << (std::ostream& out, const std::vector >& vec) +int print(const std::vector >& vec, FILE* stream = stdout) { - return out << Formatter::get()->format(Mat(vec)); + return print(Formatter::get()->format(Mat(vec)), stream); } - template static inline -std::ostream& operator << (std::ostream& out, const std::vector >& vec) +int print(const std::vector >& vec, FILE* stream = stdout) { - return out << Formatter::get()->format(Mat(vec)); + return print(Formatter::get()->format(Mat(vec)), stream); } - -/** Writes a Matx to an output stream. - */ -template inline -std::ostream& operator << (std::ostream& out, const Matx<_Tp, m, n>& matx) +template static inline +int print(const Matx<_Tp, m, n>& matx, FILE* stream = stdout) { - return out << Formatter::get()->format(matx); -} - -/** 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 << "["; - - if(Vec<_Tp, n>::depth < CV_32F) - { - for (int i = 0; i < n - 1; ++i) { - out << (int)vec[i] << ", "; - } - out << (int)vec[n-1] << "]"; - } - else - { - 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; + return print(Formatter::get()->format(matx), stream); } ////////////////////////////////////////// Algorithm ////////////////////////////////////////// -template inline Ptr<_Tp> Algorithm::create(const String& name) +template inline +Ptr<_Tp> Algorithm::create(const String& name) { return _create(name).ptr<_Tp>(); } -template -inline void Algorithm::set(const char* _name, const Ptr<_Tp>& value) +template inline +void Algorithm::set(const char* _name, const Ptr<_Tp>& value) { Ptr algo_ptr = value. template ptr(); if (algo_ptr.empty()) { @@ -551,14 +458,14 @@ inline void Algorithm::set(const char* _name, const Ptr<_Tp>& value) info()->set(this, _name, ParamType::type, &algo_ptr); } -template -inline void Algorithm::set(const String& _name, const Ptr<_Tp>& value) +template inline +void Algorithm::set(const String& _name, const Ptr<_Tp>& value) { this->set<_Tp>(_name.c_str(), value); } -template -inline void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value) +template inline +void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value) { Ptr algo_ptr = value. template ptr(); if (algo_ptr.empty()) { @@ -567,44 +474,50 @@ inline void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value) info()->set(this, _name, ParamType::type, &algo_ptr); } -template -inline void Algorithm::setAlgorithm(const String& _name, const Ptr<_Tp>& value) +template inline +void Algorithm::setAlgorithm(const String& _name, const Ptr<_Tp>& value) { this->set<_Tp>(_name.c_str(), value); } -template inline typename ParamType<_Tp>::member_type Algorithm::get(const String& _name) const +template inline +typename ParamType<_Tp>::member_type Algorithm::get(const String& _name) const { typename ParamType<_Tp>::member_type value; info()->get(this, _name.c_str(), ParamType<_Tp>::type, &value); return value; } -template inline typename ParamType<_Tp>::member_type Algorithm::get(const char* _name) const +template inline +typename ParamType<_Tp>::member_type Algorithm::get(const char* _name) const { typename ParamType<_Tp>::member_type value; info()->get(this, _name, ParamType<_Tp>::type, &value); return value; } -template inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&), - const String& help) +template inline +void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, Ptr<_Tp>& value, bool readOnly, + Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&), + const String& help) { //TODO: static assert: _Tp inherits from _Base addParam_(algo, parameter, ParamType<_Base>::type, &value, readOnly, (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); } -template inline void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, - Ptr<_Tp>& value, bool readOnly, Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&), - const String& help) +template inline +void AlgorithmInfo::addParam(Algorithm& algo, const char* parameter, Ptr<_Tp>& value, bool readOnly, + Ptr<_Tp> (Algorithm::*getter)(), void (Algorithm::*setter)(const Ptr<_Tp>&), + const String& help) { //TODO: static assert: _Tp inherits from Algorithm addParam_(algo, parameter, ParamType::type, &value, readOnly, (Algorithm::Getter)getter, (Algorithm::Setter)setter, help); } -} + + +} // cv #endif diff --git a/modules/core/include/opencv2/core/persistence.hpp b/modules/core/include/opencv2/core/persistence.hpp index 895b0f0765..e81401caed 100644 --- a/modules/core/include/opencv2/core/persistence.hpp +++ b/modules/core/include/opencv2/core/persistence.hpp @@ -226,6 +226,8 @@ public: int state; //!< the writer state }; +template<> CV_EXPORTS void Ptr::delete_obj(); + /*! File Storage Node class diff --git a/modules/core/include/opencv2/core/private.hpp b/modules/core/include/opencv2/core/private.hpp index 5e94b62fe5..12961b32c4 100644 --- a/modules/core/include/opencv2/core/private.hpp +++ b/modules/core/include/opencv2/core/private.hpp @@ -171,7 +171,7 @@ namespace cv #define CV_TOGGLE_FLT(x) ((x)^((int)(x) < 0 ? 0x7fffffff : 0)) #define CV_TOGGLE_DBL(x) ((x)^((int64)(x) < 0 ? CV_BIG_INT(0x7fffffffffffffff) : 0)) -static inline void* cvAlignPtr( const void* ptr, int align CV_DEFAULT(32) ) +static inline void* cvAlignPtr( const void* ptr, int align = 32 ) { CV_DbgAssert ( (align & (align-1)) == 0 ); return (void*)( ((size_t)ptr + align - 1) & ~(size_t)(align-1) ); @@ -183,10 +183,12 @@ static inline int cvAlign( int size, int align ) return (size + align - 1) & -align; } +#ifdef IPL_DEPTH_8U static inline cv::Size cvGetMatSize( const CvMat* mat ) { return cv::Size(mat->cols, mat->rows); } +#endif namespace cv { diff --git a/modules/core/include/opencv2/core/traits.hpp b/modules/core/include/opencv2/core/traits.hpp index 642f513439..85a5132f0e 100644 --- a/modules/core/include/opencv2/core/traits.hpp +++ b/modules/core/include/opencv2/core/traits.hpp @@ -228,7 +228,12 @@ public: }; -template class TypeDepth {}; + +template class TypeDepth +{ + enum { depth = CV_USRTYPE1 }; + typedef void value_type; +}; template<> class TypeDepth { diff --git a/modules/core/include/opencv2/core/types_c.h b/modules/core/include/opencv2/core/types_c.h index 988da62a79..e95170f2c0 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -12,6 +12,7 @@ // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Copyright (C) 2013, OpenCV Foundation, all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp index 0bd04ef96b..4f4c8db4aa 100644 --- a/modules/core/src/command_line_parser.cpp +++ b/modules/core/src/command_line_parser.cpp @@ -1,4 +1,5 @@ #include "precomp.hpp" +#include namespace cv { diff --git a/modules/core/src/out.cpp b/modules/core/src/out.cpp index 4bfd1363fb..cc2294ded6 100644 --- a/modules/core/src/out.cpp +++ b/modules/core/src/out.cpp @@ -55,7 +55,7 @@ namespace char buf[32]; // enough for double with precision up to 20 cv::Mat mtx; - int mcn; + int mcn; // == mtx.channels() bool singleLine; int state; @@ -68,7 +68,6 @@ namespace char braces[5]; void (FormattedImpl::*valueToStr)(); - void valueToStr8u() { sprintf(buf, "%3d", (int)mtx.ptr(row, col)[cn]); } void valueToStr8s() { sprintf(buf, "%3d", (int)mtx.ptr(row, col)[cn]); } void valueToStr16u() { sprintf(buf, "%d", (int)mtx.ptr(row, col)[cn]); } diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 830c329f6f..245347b8b2 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -1,5 +1,7 @@ #include "test_precomp.hpp" +#include + using namespace cv; using namespace std; diff --git a/modules/flann/src/miniflann.cpp b/modules/flann/src/miniflann.cpp index c15a5ab383..efa58927d3 100644 --- a/modules/flann/src/miniflann.cpp +++ b/modules/flann/src/miniflann.cpp @@ -312,9 +312,9 @@ buildIndex_(void*& index, const Mat& data, const IndexParams& params, const Dist { typedef typename Distance::ElementType ElementType; if(DataType::type != data.type()) - CV_Error_(CV_StsUnsupportedFormat, ("type=%d\n", data.type())); + CV_Error_(Error::StsUnsupportedFormat, ("type=%d\n", data.type())); if(!data.isContinuous()) - CV_Error(CV_StsBadArg, "Only continuous arrays are supported"); + CV_Error(Error::StsBadArg, "Only continuous arrays are supported"); ::cvflann::Matrix dataset((ElementType*)data.data, data.rows, data.cols); IndexType* _index = new IndexType(dataset, get_params(params), dist); @@ -400,7 +400,7 @@ void Index::build(InputArray _data, const IndexParams& params, flann_distance_t break; #endif default: - CV_Error(CV_StsBadArg, "Unknown/unsupported distance type"); + CV_Error(Error::StsBadArg, "Unknown/unsupported distance type"); } } @@ -453,7 +453,7 @@ void Index::release() break; #endif default: - CV_Error(CV_StsBadArg, "Unknown/unsupported distance type"); + CV_Error(Error::StsBadArg, "Unknown/unsupported distance type"); } index = 0; } @@ -585,7 +585,7 @@ void Index::knnSearch(InputArray _query, OutputArray _indices, break; #endif default: - CV_Error(CV_StsBadArg, "Unknown/unsupported distance type"); + CV_Error(Error::StsBadArg, "Unknown/unsupported distance type"); } } @@ -599,7 +599,7 @@ int Index::radiusSearch(InputArray _query, OutputArray _indices, createIndicesDists( _indices, _dists, indices, dists, query.rows, maxResults, INT_MAX, dtype ); if( algo == FLANN_INDEX_LSH ) - CV_Error( CV_StsNotImplemented, "LSH index does not support radiusSearch operation" ); + CV_Error( Error::StsNotImplemented, "LSH index does not support radiusSearch operation" ); switch( distType ) { @@ -623,7 +623,7 @@ int Index::radiusSearch(InputArray _query, OutputArray _indices, return runRadiusSearch< ::cvflann::KL_Divergence >(index, query, indices, dists, radius, params); #endif default: - CV_Error(CV_StsBadArg, "Unknown/unsupported distance type"); + CV_Error(Error::StsBadArg, "Unknown/unsupported distance type"); } return -1; } @@ -658,7 +658,7 @@ void Index::save(const String& filename) const { FILE* fout = fopen(filename.c_str(), "wb"); if (fout == NULL) - CV_Error_( CV_StsError, ("Can not open file %s for writing FLANN index\n", filename.c_str()) ); + CV_Error_( Error::StsError, ("Can not open file %s for writing FLANN index\n", filename.c_str()) ); switch( distType ) { @@ -691,7 +691,7 @@ void Index::save(const String& filename) const default: fclose(fout); fout = 0; - CV_Error(CV_StsBadArg, "Unknown/unsupported distance type"); + CV_Error(Error::StsBadArg, "Unknown/unsupported distance type"); } if( fout ) fclose(fout); diff --git a/modules/java/generator/src/cpp/Mat.cpp b/modules/java/generator/src/cpp/Mat.cpp index 6b1d10038b..4dd7ef085e 100644 --- a/modules/java/generator/src/cpp/Mat.cpp +++ b/modules/java/generator/src/cpp/Mat.cpp @@ -2543,12 +2543,35 @@ JNIEXPORT jstring JNICALL Java_org_opencv_core_Mat_nDump (JNIEnv *env, jclass, jlong self) { cv::Mat* me = (cv::Mat*) self; //TODO: check for NULL - std::stringstream s; try { LOGD("Mat::nDump()"); - s << *me; - return env->NewStringUTF(s.str().c_str()); + const int BUFSZ = 4096 - 32; + char buf[BUFSZ + 32]; + String s; + + Ptr fmtd = Formatter::get()->format(*me); + char* pos = buf; + + for(const char* str = fmtd->next(); str; str = fmtd->next()) + { + pos = strcpy(pos, str); + if(pos > buf + BUFSZ) + { + s = s + String(buf, pos - buf); + pos = buf; + } + } + + if (pos > buf) + { + if (s.empty()) + return env->NewStringUTF(buf); + + s = s + String(buf, pos - buf); + } + + return env->NewStringUTF(s.c_str()); } catch(cv::Exception e) { LOGE("Mat::nDump() catched cv::Exception: %s", e.what()); jclass je = env->FindClass("org/opencv/core/CvException"); diff --git a/modules/softcascade/include/opencv2/softcascade.hpp b/modules/softcascade/include/opencv2/softcascade.hpp index 6e116c8bdf..a174c5098b 100644 --- a/modules/softcascade/include/opencv2/softcascade.hpp +++ b/modules/softcascade/include/opencv2/softcascade.hpp @@ -45,6 +45,7 @@ #include "opencv2/core.hpp" #include "opencv2/core/gpumat.hpp" +#include namespace cv { namespace softcascade { diff --git a/modules/softcascade/src/integral_channel_builder.cpp b/modules/softcascade/src/integral_channel_builder.cpp index ae44de0547..f804abe2bb 100644 --- a/modules/softcascade/src/integral_channel_builder.cpp +++ b/modules/softcascade/src/integral_channel_builder.cpp @@ -165,8 +165,7 @@ void cv::softcascade::write(cv::FileStorage& fs, const cv::String&, const Channe std::ostream& cv::softcascade::operator<<(std::ostream& out, const ChannelFeature& m) { - out << m.channel << " " << m.bb; - return out; + return out << m.channel << " " << "[" << m.bb.width << " x " << m.bb.height << " from (" << m.bb.x << ", " << m.bb.y << ")]"; } ChannelFeature::~ChannelFeature(){} -- GitLab