From 13b31b0804ee69268b6b2f29bf27ec535d9f3a2f Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 26 Mar 2013 19:48:50 +0400 Subject: [PATCH] Move C++ basic structures to separate header and inverse dependency from C API cv::Complex, cv::Point_ and cv::Point3_ are moved. --- modules/calib3d/src/calibinit.cpp | 6 +- modules/core/include/opencv2/core.hpp | 127 +-------- .../core/include/opencv2/core/operations.hpp | 91 ------- modules/core/include/opencv2/core/types.hpp | 251 ++++++++++++++++++ modules/core/include/opencv2/core/types_c.h | 28 ++ modules/imgproc/src/contours.cpp | 4 +- modules/legacy/src/3dtracker.cpp | 2 +- modules/legacy/src/_vectrack.h | 4 +- modules/legacy/src/calibfilter.cpp | 2 +- modules/legacy/src/epilines.cpp | 2 +- modules/legacy/src/lcm.cpp | 4 +- modules/legacy/src/morphcontours.cpp | 4 +- modules/legacy/src/segment.cpp | 6 +- modules/legacy/src/vecfacetracking.cpp | 20 +- modules/legacy/test/test_pyrsegmentation.cpp | 4 +- modules/ml/test/test_mltests2.cpp | 2 +- modules/objdetect/src/datamatrix.cpp | 4 +- samples/c/find_obj.cpp | 2 +- samples/cpp/letter_recog.cpp | 2 +- 19 files changed, 314 insertions(+), 251 deletions(-) create mode 100644 modules/core/include/opencv2/core/types.hpp diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index 0a349584e7..21e2a39989 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -1095,7 +1095,7 @@ icvOrderQuad(CvCBQuad *quad, CvCBCorner *corner, int common) static int icvCleanFoundConnectedQuads( int quad_count, CvCBQuad **quad_group, CvSize pattern_size ) { - CvPoint2D32f center = {0,0}; + CvPoint2D32f center; int i, j, k; // number of quads this pattern should contain int count = ((pattern_size.width + 1)*(pattern_size.height + 1) + 1)/2; @@ -1111,7 +1111,7 @@ icvCleanFoundConnectedQuads( int quad_count, CvCBQuad **quad_group, CvSize patte for( i = 0; i < quad_count; i++ ) { - CvPoint2D32f ci = {0,0}; + CvPoint2D32f ci; CvCBQuad* q = quad_group[i]; for( j = 0; j < 4; j++ ) @@ -1856,7 +1856,7 @@ cvDrawChessboardCorners( CvArr* _image, CvSize pattern_size, else { int x, y; - CvPoint prev_pt = {0, 0}; + CvPoint prev_pt; const int line_max = 7; static const CvScalar line_colors[line_max] = { diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 782997c583..18cc2cb77a 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -53,6 +53,7 @@ #ifdef __cplusplus #include "opencv2/core/cvstd.hpp" +#include "opencv2/core/types.hpp" #ifndef SKIP_INCLUDES #include @@ -523,125 +524,6 @@ typedef Vec Vec4d; typedef Vec Vec6d; -//////////////////////////////// Complex ////////////////////////////// - -/*! - A complex number class. - - The template class is similar and compatible with std::complex, however it provides slightly - more convenient access to the real and imaginary parts using through the simple field access, as opposite - to std::complex::real() and std::complex::imag(). -*/ -template class CV_EXPORTS Complex -{ -public: - - //! constructors - Complex(); - Complex( _Tp _re, _Tp _im=0 ); - Complex( const std::complex<_Tp>& c ); - - //! conversion to another data type - template operator Complex() const; - //! conjugation - Complex conj() const; - //! conversion to std::complex - operator std::complex<_Tp>() const; - - _Tp re, im; //< the real and the imaginary parts -}; - - -/*! - \typedef -*/ -typedef Complex Complexf; -typedef Complex Complexd; - - -//////////////////////////////// Point_ //////////////////////////////// - -/*! - template 2D point class. - - The class defines a point in 2D space. Data type of the point coordinates is specified - as a template parameter. There are a few shorter aliases available for user convenience. - See cv::Point, cv::Point2i, cv::Point2f and cv::Point2d. -*/ -template class CV_EXPORTS Point_ -{ -public: - typedef _Tp value_type; - - // various constructors - Point_(); - Point_(_Tp _x, _Tp _y); - Point_(const Point_& pt); - Point_(const CvPoint& pt); - Point_(const CvPoint2D32f& pt); - Point_(const Size_<_Tp>& sz); - Point_(const Vec<_Tp, 2>& v); - - Point_& operator = (const Point_& pt); - //! conversion to another data type - template operator Point_<_Tp2>() const; - - //! conversion to the old-style C structures - operator CvPoint() const; - operator CvPoint2D32f() const; - operator Vec<_Tp, 2>() const; - - //! dot product - _Tp dot(const Point_& pt) const; - //! dot product computed in double-precision arithmetics - double ddot(const Point_& pt) const; - //! cross-product - double cross(const Point_& pt) const; - //! checks whether the point is inside the specified rectangle - bool inside(const Rect_<_Tp>& r) const; - - _Tp x, y; //< the point coordinates -}; - -/*! - template 3D point class. - - The class defines a point in 3D space. Data type of the point coordinates is specified - as a template parameter. - - \see cv::Point3i, cv::Point3f and cv::Point3d -*/ -template class CV_EXPORTS Point3_ -{ -public: - typedef _Tp value_type; - - // various constructors - Point3_(); - Point3_(_Tp _x, _Tp _y, _Tp _z); - Point3_(const Point3_& pt); - explicit Point3_(const Point_<_Tp>& pt); - Point3_(const CvPoint3D32f& pt); - Point3_(const Vec<_Tp, 3>& v); - - Point3_& operator = (const Point3_& pt); - //! conversion to another data type - template operator Point3_<_Tp2>() const; - //! conversion to the old-style CvPoint... - operator CvPoint3D32f() const; - //! conversion to cv::Vec<> - operator Vec<_Tp, 3>() const; - - //! dot product - _Tp dot(const Point3_& pt) const; - //! dot product computed in double-precision arithmetics - double ddot(const Point3_& pt) const; - //! cross product of the 2 3D points - Point3_ cross(const Point3_& pt) const; - - _Tp x, y, z; //< the point coordinates -}; - //////////////////////////////// Size_ //////////////////////////////// /*! @@ -726,17 +608,10 @@ public: shorter aliases for the most popular cv::Point_<>, cv::Size_<> and cv::Rect_<> specializations */ -typedef Point_ Point2i; -typedef Point2i Point; typedef Size_ Size2i; typedef Size2i Size; typedef Rect_ Rect; -typedef Point_ Point2f; -typedef Point_ Point2d; typedef Size_ Size2f; -typedef Point3_ Point3i; -typedef Point3_ Point3f; -typedef Point3_ Point3d; /*! diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index dd4bc9b3a5..a492dba528 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -98,85 +98,6 @@ namespace cv { -/////////////// saturate_cast (used in image & signal processing) /////////////////// - -template static inline _Tp saturate_cast(uchar v) { return _Tp(v); } -template static inline _Tp saturate_cast(schar v) { return _Tp(v); } -template static inline _Tp saturate_cast(ushort v) { return _Tp(v); } -template static inline _Tp saturate_cast(short v) { return _Tp(v); } -template static inline _Tp saturate_cast(unsigned v) { return _Tp(v); } -template static inline _Tp saturate_cast(int v) { return _Tp(v); } -template static inline _Tp saturate_cast(float v) { return _Tp(v); } -template static inline _Tp saturate_cast(double v) { return _Tp(v); } - -template<> inline uchar saturate_cast(schar v) -{ return (uchar)std::max((int)v, 0); } -template<> inline uchar saturate_cast(ushort v) -{ return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); } -template<> inline uchar saturate_cast(int v) -{ return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } -template<> inline uchar saturate_cast(short v) -{ return saturate_cast((int)v); } -template<> inline uchar saturate_cast(unsigned v) -{ return (uchar)std::min(v, (unsigned)UCHAR_MAX); } -template<> inline uchar saturate_cast(float v) -{ int iv = cvRound(v); return saturate_cast(iv); } -template<> inline uchar saturate_cast(double v) -{ int iv = cvRound(v); return saturate_cast(iv); } - -template<> inline schar saturate_cast(uchar v) -{ return (schar)std::min((int)v, SCHAR_MAX); } -template<> inline schar saturate_cast(ushort v) -{ return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); } -template<> inline schar saturate_cast(int v) -{ - return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? - v : v > 0 ? SCHAR_MAX : SCHAR_MIN); -} -template<> inline schar saturate_cast(short v) -{ return saturate_cast((int)v); } -template<> inline schar saturate_cast(unsigned v) -{ return (schar)std::min(v, (unsigned)SCHAR_MAX); } - -template<> inline schar saturate_cast(float v) -{ int iv = cvRound(v); return saturate_cast(iv); } -template<> inline schar saturate_cast(double v) -{ int iv = cvRound(v); return saturate_cast(iv); } - -template<> inline ushort saturate_cast(schar v) -{ return (ushort)std::max((int)v, 0); } -template<> inline ushort saturate_cast(short v) -{ return (ushort)std::max((int)v, 0); } -template<> inline ushort saturate_cast(int v) -{ return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } -template<> inline ushort saturate_cast(unsigned v) -{ return (ushort)std::min(v, (unsigned)USHRT_MAX); } -template<> inline ushort saturate_cast(float v) -{ int iv = cvRound(v); return saturate_cast(iv); } -template<> inline ushort saturate_cast(double v) -{ int iv = cvRound(v); return saturate_cast(iv); } - -template<> inline short saturate_cast(ushort v) -{ return (short)std::min((int)v, SHRT_MAX); } -template<> inline short saturate_cast(int v) -{ - return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? - v : v > 0 ? SHRT_MAX : SHRT_MIN); -} -template<> inline short saturate_cast(unsigned v) -{ return (short)std::min(v, (unsigned)SHRT_MAX); } -template<> inline short saturate_cast(float v) -{ int iv = cvRound(v); return saturate_cast(iv); } -template<> inline short saturate_cast(double v) -{ int iv = cvRound(v); return saturate_cast(iv); } - -template<> inline int saturate_cast(float v) { return cvRound(v); } -template<> inline int saturate_cast(double v) { return cvRound(v); } - -// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. -template<> inline unsigned saturate_cast(float v){ return cvRound(v); } -template<> inline unsigned saturate_cast(double v) { return cvRound(v); } - inline int fast_abs(uchar v) { return v; } inline int fast_abs(schar v) { return std::abs((int)v); } inline int fast_abs(ushort v) { return v; } @@ -1605,9 +1526,6 @@ Complex<_Tp> operator /= (const Complex<_Tp>& a, _Tp b) template inline Point_<_Tp>::Point_() : x(0), y(0) {} template inline Point_<_Tp>::Point_(_Tp _x, _Tp _y) : x(_x), y(_y) {} template inline Point_<_Tp>::Point_(const Point_& pt) : x(pt.x), y(pt.y) {} -template inline Point_<_Tp>::Point_(const CvPoint& pt) : x((_Tp)pt.x), y((_Tp)pt.y) {} -template inline Point_<_Tp>::Point_(const CvPoint2D32f& pt) - : x(saturate_cast<_Tp>(pt.x)), y(saturate_cast<_Tp>(pt.y)) {} template inline Point_<_Tp>::Point_(const Size_<_Tp>& sz) : x(sz.width), y(sz.height) {} template inline Point_<_Tp>::Point_(const Vec<_Tp,2>& v) : x(v[0]), y(v[1]) {} template inline Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt) @@ -1615,10 +1533,6 @@ template inline Point_<_Tp>& Point_<_Tp>::operator = (const Point_ template template inline Point_<_Tp>::operator Point_<_Tp2>() const { return Point_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y)); } -template inline Point_<_Tp>::operator CvPoint() const -{ return cvPoint(saturate_cast(x), saturate_cast(y)); } -template inline Point_<_Tp>::operator CvPoint2D32f() const -{ return cvPoint2D32f((float)x, (float)y); } template inline Point_<_Tp>::operator Vec<_Tp, 2>() const { return Vec<_Tp, 2>(x, y); } @@ -1712,16 +1626,11 @@ template inline Point3_<_Tp>::Point3_() : x(0), y(0), z(0) {} template inline Point3_<_Tp>::Point3_(_Tp _x, _Tp _y, _Tp _z) : x(_x), y(_y), z(_z) {} template inline Point3_<_Tp>::Point3_(const Point3_& pt) : x(pt.x), y(pt.y), z(pt.z) {} template inline Point3_<_Tp>::Point3_(const Point_<_Tp>& pt) : x(pt.x), y(pt.y), z(_Tp()) {} -template inline Point3_<_Tp>::Point3_(const CvPoint3D32f& pt) : - x(saturate_cast<_Tp>(pt.x)), y(saturate_cast<_Tp>(pt.y)), z(saturate_cast<_Tp>(pt.z)) {} template inline Point3_<_Tp>::Point3_(const Vec<_Tp, 3>& v) : x(v[0]), y(v[1]), z(v[2]) {} template template inline Point3_<_Tp>::operator Point3_<_Tp2>() const { return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z)); } -template inline Point3_<_Tp>::operator CvPoint3D32f() const -{ return cvPoint3D32f((float)x, (float)y, (float)z); } - template inline Point3_<_Tp>::operator Vec<_Tp, 3>() const { return Vec<_Tp, 3>(x, y, z); } diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp new file mode 100644 index 0000000000..20cd07096a --- /dev/null +++ b/modules/core/include/opencv2/core/types.hpp @@ -0,0 +1,251 @@ +/*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_TYPES_HPP__ +#define __OPENCV_CORE_TYPES_HPP__ + +#include + +#ifndef OPENCV_NOSTL +# include +#endif + +#include "opencv2/core/cvdef.h" +#include "opencv2/core/cvstd.hpp" + +namespace cv +{ +template class CV_EXPORTS Size_; +template class CV_EXPORTS Point_; +template class CV_EXPORTS Rect_; + +template class CV_EXPORTS Vec; +//template class CV_EXPORTS Matx; + + + +/////////////// saturate_cast (used in image & signal processing) /////////////////// + +template static inline _Tp saturate_cast(uchar v) { return _Tp(v); } +template static inline _Tp saturate_cast(schar v) { return _Tp(v); } +template static inline _Tp saturate_cast(ushort v) { return _Tp(v); } +template static inline _Tp saturate_cast(short v) { return _Tp(v); } +template static inline _Tp saturate_cast(unsigned v) { return _Tp(v); } +template static inline _Tp saturate_cast(int v) { return _Tp(v); } +template static inline _Tp saturate_cast(float v) { return _Tp(v); } +template static inline _Tp saturate_cast(double v) { return _Tp(v); } + +template<> inline uchar saturate_cast(schar v) { return (uchar)std::max((int)v, 0); } +template<> inline uchar saturate_cast(ushort v) { return (uchar)std::min((unsigned)v, (unsigned)UCHAR_MAX); } +template<> inline uchar saturate_cast(int v) { return (uchar)((unsigned)v <= UCHAR_MAX ? v : v > 0 ? UCHAR_MAX : 0); } +template<> inline uchar saturate_cast(short v) { return saturate_cast((int)v); } +template<> inline uchar saturate_cast(unsigned v) { return (uchar)std::min(v, (unsigned)UCHAR_MAX); } +template<> inline uchar saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline uchar saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } + +template<> inline schar saturate_cast(uchar v) { return (schar)std::min((int)v, SCHAR_MAX); } +template<> inline schar saturate_cast(ushort v) { return (schar)std::min((unsigned)v, (unsigned)SCHAR_MAX); } +template<> inline schar saturate_cast(int v) { return (schar)((unsigned)(v-SCHAR_MIN) <= (unsigned)UCHAR_MAX ? v : v > 0 ? SCHAR_MAX : SCHAR_MIN); } +template<> inline schar saturate_cast(short v) { return saturate_cast((int)v); } +template<> inline schar saturate_cast(unsigned v) { return (schar)std::min(v, (unsigned)SCHAR_MAX); } +template<> inline schar saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline schar saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } + +template<> inline ushort saturate_cast(schar v) { return (ushort)std::max((int)v, 0); } +template<> inline ushort saturate_cast(short v) { return (ushort)std::max((int)v, 0); } +template<> inline ushort saturate_cast(int v) { return (ushort)((unsigned)v <= (unsigned)USHRT_MAX ? v : v > 0 ? USHRT_MAX : 0); } +template<> inline ushort saturate_cast(unsigned v) { return (ushort)std::min(v, (unsigned)USHRT_MAX); } +template<> inline ushort saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline ushort saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } + +template<> inline short saturate_cast(ushort v) { return (short)std::min((int)v, SHRT_MAX); } +template<> inline short saturate_cast(int v) { return (short)((unsigned)(v - SHRT_MIN) <= (unsigned)USHRT_MAX ? v : v > 0 ? SHRT_MAX : SHRT_MIN); } +template<> inline short saturate_cast(unsigned v) { return (short)std::min(v, (unsigned)SHRT_MAX); } +template<> inline short saturate_cast(float v) { int iv = cvRound(v); return saturate_cast(iv); } +template<> inline short saturate_cast(double v) { int iv = cvRound(v); return saturate_cast(iv); } + +template<> inline int saturate_cast(float v) { return cvRound(v); } +template<> inline int saturate_cast(double v) { return cvRound(v); } + +// we intentionally do not clip negative numbers, to make -1 become 0xffffffff etc. +template<> inline unsigned saturate_cast(float v) { return cvRound(v); } +template<> inline unsigned saturate_cast(double v) { return cvRound(v); } + + + +//////////////////////////////// Complex ////////////////////////////// + +/*! + A complex number class. + + The template class is similar and compatible with std::complex, however it provides slightly + more convenient access to the real and imaginary parts using through the simple field access, as opposite + to std::complex::real() and std::complex::imag(). +*/ +template class CV_EXPORTS Complex +{ +public: + + //! constructors + Complex(); + Complex( _Tp _re, _Tp _im=0 ); + + //! conversion to another data type + template operator Complex() const; + //! conjugation + Complex conj() const; + + _Tp re, im; //< the real and the imaginary parts + +#ifndef OPENCV_NOSTL + Complex( const std::complex<_Tp>& c ); + operator std::complex<_Tp>() const; +#endif +}; + +/*! + \typedef +*/ +typedef Complex Complexf; +typedef Complex Complexd; + + + +//////////////////////////////// Point_ //////////////////////////////// + +/*! + template 2D point class. + + The class defines a point in 2D space. Data type of the point coordinates is specified + as a template parameter. There are a few shorter aliases available for user convenience. + See cv::Point, cv::Point2i, cv::Point2f and cv::Point2d. +*/ +template class CV_EXPORTS Point_ +{ +public: + typedef _Tp value_type; + + // various constructors + Point_(); + Point_(_Tp _x, _Tp _y); + Point_(const Point_& pt); + Point_(const Size_<_Tp>& sz); + Point_(const Vec<_Tp, 2>& v); + + Point_& operator = (const Point_& pt); + //! conversion to another data type + template operator Point_<_Tp2>() const; + + //! conversion to the old-style C structures + operator Vec<_Tp, 2>() const; + + //! dot product + _Tp dot(const Point_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point_& pt) const; + //! cross-product + double cross(const Point_& pt) const; + //! checks whether the point is inside the specified rectangle + bool inside(const Rect_<_Tp>& r) const; + + _Tp x, y; //< the point coordinates +}; + +/*! + \typedef +*/ +typedef Point_ Point2i; +typedef Point_ Point2f; +typedef Point_ Point2d; +typedef Point2i Point; + + + +//////////////////////////////// Point3_ //////////////////////////////// + +/*! + template 3D point class. + + The class defines a point in 3D space. Data type of the point coordinates is specified + as a template parameter. + + \see cv::Point3i, cv::Point3f and cv::Point3d +*/ +template class CV_EXPORTS Point3_ +{ +public: + typedef _Tp value_type; + + // various constructors + Point3_(); + Point3_(_Tp _x, _Tp _y, _Tp _z); + Point3_(const Point3_& pt); + explicit Point3_(const Point_<_Tp>& pt); + Point3_(const Vec<_Tp, 3>& v); + + Point3_& operator = (const Point3_& pt); + //! conversion to another data type + template operator Point3_<_Tp2>() const; + //! conversion to cv::Vec<> + operator Vec<_Tp, 3>() const; + + //! dot product + _Tp dot(const Point3_& pt) const; + //! dot product computed in double-precision arithmetics + double ddot(const Point3_& pt) const; + //! cross product of the 2 3D points + Point3_ cross(const Point3_& pt) const; + + _Tp x, y, z; //< the point coordinates +}; + +/*! + \typedef +*/ +typedef Point3_ Point3i; +typedef Point3_ Point3f; +typedef Point3_ Point3d; + +} // cv + +#endif //__OPENCV_CORE_TYPES_HPP__ \ No newline at end of file diff --git a/modules/core/include/opencv2/core/types_c.h b/modules/core/include/opencv2/core/types_c.h index 5838c0415d..2f1d3455e7 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -92,6 +92,10 @@ # define CVAPI(rettype) CV_EXTERN_C CV_EXPORTS rettype CV_CDECL #endif +#ifdef __cplusplus +# include "opencv2/core/types.hpp" +#endif + /* CvArr* is used to pass arbitrary * array-like data structures * into functions where the particular @@ -749,6 +753,14 @@ typedef struct CvPoint { int x; int y; + +#ifdef __cplusplus + CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {} + template + CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {} + template + operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } +#endif } CvPoint; @@ -768,6 +780,14 @@ typedef struct CvPoint2D32f { float x; float y; + +#ifdef __cplusplus + CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {} + template + CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {} + template + operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } +#endif } CvPoint2D32f; @@ -804,6 +824,14 @@ typedef struct CvPoint3D32f float x; float y; float z; + +#ifdef __cplusplus + CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {} + template + CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {} + template + operator cv::Point3_<_Tp>() const { return cv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); } +#endif } CvPoint3D32f; diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index 75e18b2d84..6f5b0c8ac6 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -48,7 +48,7 @@ (deltas)[6] = (step), (deltas)[7] = (step) + (nch)) static const CvPoint icvCodeDeltas[8] = - { {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1} }; + { CvPoint(1, 0), CvPoint(1, -1), CvPoint(0, -1), CvPoint(-1, -1), CvPoint(-1, 0), CvPoint(-1, 1), CvPoint(0, 1), CvPoint(1, 1) }; CV_IMPL void cvStartReadChainPoints( CvChain * chain, CvChainPtReader * reader ) @@ -78,7 +78,7 @@ cvReadChainPoint( CvChainPtReader * reader ) { schar *ptr; int code; - CvPoint pt = { 0, 0 }; + CvPoint pt; if( !reader ) CV_Error( CV_StsNullPtr, "" ); diff --git a/modules/legacy/src/3dtracker.cpp b/modules/legacy/src/3dtracker.cpp index 536a534fe2..4042c65015 100644 --- a/modules/legacy/src/3dtracker.cpp +++ b/modules/legacy/src/3dtracker.cpp @@ -321,7 +321,7 @@ static void DrawEtalon(IplImage *img, CvPoint2D32f *corners, const int r = 4; int i; int x, y; - CvPoint prev_pt = { 0, 0 }; + CvPoint prev_pt; static const CvScalar rgb_colors[] = { {{0,0,255}}, {{0,128,255}}, diff --git a/modules/legacy/src/_vectrack.h b/modules/legacy/src/_vectrack.h index 77df1e3c0c..9c90cc7e8a 100644 --- a/modules/legacy/src/_vectrack.h +++ b/modules/legacy/src/_vectrack.h @@ -87,8 +87,8 @@ int PointInRect(const CvPoint& p, const CvRect& r) inline int RectInRect(const CvRect& r1, const CvRect& r2) { - CvPoint plt = {r1.x, r1.y}; - CvPoint prb = {r1.x + r1.width, r1.y + r1.height}; + CvPoint plt(r1.x, r1.y); + CvPoint prb(r1.x + r1.width, r1.y + r1.height); return (PointInRect(plt, r2) && PointInRect(prb, r2)); } diff --git a/modules/legacy/src/calibfilter.cpp b/modules/legacy/src/calibfilter.cpp index f1a4d7cd2b..ffbb4a2110 100644 --- a/modules/legacy/src/calibfilter.cpp +++ b/modules/legacy/src/calibfilter.cpp @@ -558,7 +558,7 @@ void CvCalibFilter::DrawPoints( CvMat** dstarr ) const int colorCount = sizeof(line_colors)/sizeof(line_colors[0]); const int r = 4; CvScalar color = line_colors[0]; - CvPoint prev_pt = { 0, 0}; + CvPoint prev_pt; for( j = 0; j < count; j++ ) { diff --git a/modules/legacy/src/epilines.cpp b/modules/legacy/src/epilines.cpp index 309ca0b1d5..19d929df98 100644 --- a/modules/legacy/src/epilines.cpp +++ b/modules/legacy/src/epilines.cpp @@ -1826,7 +1826,7 @@ void icvGetCutPiece( CvVect64d areaLineCoef1,CvVect64d areaLineCoef2, /* Collect all candidate point */ CvPoint2D64d candPoints[8]; - CvPoint2D64d midPoint = {0, 0}; + CvPoint2D64d midPoint; int numPoints = 0; int res; int i; diff --git a/modules/legacy/src/lcm.cpp b/modules/legacy/src/lcm.cpp index 58abcdb7dc..05919f59f5 100644 --- a/modules/legacy/src/lcm.cpp +++ b/modules/legacy/src/lcm.cpp @@ -694,7 +694,7 @@ void _cvProjectionPointToSegment(CvPoint2D32f* PointO, float* dist) { float scal_AO_AB, scal_AB_AB; - CvPoint2D32f VectorAB = {PointB->x - PointA->x, PointB->y - PointA->y}; + CvPoint2D32f VectorAB(PointB->x - PointA->x, PointB->y - PointA->y); scal_AB_AB = VectorAB.x*VectorAB.x + VectorAB.y*VectorAB.y; if(scal_AB_AB < LCM_CONST_ZERO) { @@ -704,7 +704,7 @@ void _cvProjectionPointToSegment(CvPoint2D32f* PointO, return; } - CvPoint2D32f VectorAO = {PointO->x - PointA->x, PointO->y - PointA->y}; + CvPoint2D32f VectorAO(PointO->x - PointA->x, PointO->y - PointA->y); scal_AO_AB = VectorAO.x*VectorAB.x + VectorAO.y*VectorAB.y; if(dist) diff --git a/modules/legacy/src/morphcontours.cpp b/modules/legacy/src/morphcontours.cpp index 851b00bbe8..b04cdd48ad 100644 --- a/modules/legacy/src/morphcontours.cpp +++ b/modules/legacy/src/morphcontours.cpp @@ -78,7 +78,7 @@ void _cvWorkEast (int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D void _cvWorkSouthEast(int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D32f* edges2); void _cvWorkSouth (int i, int j, _CvWork** W, CvPoint2D32f* edges1, CvPoint2D32f* edges2); -static CvPoint2D32f null_edge = {0,0}; +static CvPoint2D32f null_edge; double _cvStretchingWork(CvPoint2D32f* P1, CvPoint2D32f* P2) @@ -106,7 +106,7 @@ double _cvBendingWork( CvPoint2D32f* B0, CvPoint* K*/) { CvPoint2D32f Q0, Q1, Q2; - CvPoint2D32f Q1_nm = { 0, 0 }, Q2_nm = { 0, 0 }; + CvPoint2D32f Q1_nm, Q2_nm; double d0, d1, d2, des, t_zero; double k_zero, k_nonmon; CvPoint2D32f center; diff --git a/modules/legacy/src/segment.cpp b/modules/legacy/src/segment.cpp index 07e6082988..e61eeadf42 100644 --- a/modules/legacy/src/segment.cpp +++ b/modules/legacy/src/segment.cpp @@ -328,8 +328,8 @@ static void color_derv( const CvArr* srcArr, CvArr* dstArr, int thresh ) } #endif -const CvPoint icvCodeDeltas[8] = - { {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1} }; +static const CvPoint icvCodeDeltas[8] = + { CvPoint(1, 0), CvPoint(1, -1), CvPoint(0, -1), CvPoint(-1, -1), CvPoint(-1, 0), CvPoint(-1, 1), CvPoint(0, 1), CvPoint(1, 1) }; static CvSeq* icvGetComponent( uchar* img, int step, CvRect rect, @@ -366,7 +366,7 @@ icvGetComponent( uchar* img, int step, CvRect rect, CvSeqWriter writer; char *i0, *i1, *i3, *i4 = 0; int prev_s = -1, s, s_end; - CvPoint pt = { x, y }; + CvPoint pt(x, y); if( !(prev == 0 && p == 2) ) /* if not external contour */ { diff --git a/modules/legacy/src/vecfacetracking.cpp b/modules/legacy/src/vecfacetracking.cpp index 3a11ea9256..c532a69b24 100644 --- a/modules/legacy/src/vecfacetracking.cpp +++ b/modules/legacy/src/vecfacetracking.cpp @@ -749,11 +749,11 @@ int ChoiceTrackingFace2(CvFaceTracker* pTF, const int nElements, const CvFaceEle face[element[0]] = *(new_face[element[0]]); face[element[1]] = *(new_face[element[1]]); // 3 element find by template - CvPoint templ_v01 = {pTF->ptTempl[element[1]].x - pTF->ptTempl[element[0]].x, pTF->ptTempl[element[1]].y - pTF->ptTempl[element[0]].y}; - CvPoint templ_v02 = {pTF->ptTempl[element[2]].x - pTF->ptTempl[element[0]].x, pTF->ptTempl[element[2]].y - pTF->ptTempl[element[0]].y}; - CvPoint prev_v01 = {pTF->face[element[1]].ptCenter.x - pTF->face[element[0]].ptCenter.x, pTF->face[element[1]].ptCenter.y - pTF->face[element[0]].ptCenter.y}; - CvPoint prev_v02 = {pTF->face[element[2]].ptCenter.x - pTF->face[element[0]].ptCenter.x, pTF->face[element[2]].ptCenter.y - pTF->face[element[0]].ptCenter.y}; - CvPoint new_v01 = {new_face[element[1]]->ptCenter.x - new_face[element[0]]->ptCenter.x, new_face[element[1]]->ptCenter.y - new_face[element[0]]->ptCenter.y}; + CvPoint templ_v01(pTF->ptTempl[element[1]].x - pTF->ptTempl[element[0]].x, pTF->ptTempl[element[1]].y - pTF->ptTempl[element[0]].y); + CvPoint templ_v02(pTF->ptTempl[element[2]].x - pTF->ptTempl[element[0]].x, pTF->ptTempl[element[2]].y - pTF->ptTempl[element[0]].y); + CvPoint prev_v01(pTF->face[element[1]].ptCenter.x - pTF->face[element[0]].ptCenter.x, pTF->face[element[1]].ptCenter.y - pTF->face[element[0]].ptCenter.y); + CvPoint prev_v02(pTF->face[element[2]].ptCenter.x - pTF->face[element[0]].ptCenter.x, pTF->face[element[2]].ptCenter.y - pTF->face[element[0]].ptCenter.y); + CvPoint new_v01(new_face[element[1]]->ptCenter.x - new_face[element[0]]->ptCenter.x, new_face[element[1]]->ptCenter.y - new_face[element[0]]->ptCenter.y); double templ_d01 = sqrt((double)templ_v01.x*templ_v01.x + templ_v01.y*templ_v01.y); double templ_d02 = sqrt((double)templ_v02.x*templ_v02.x + templ_v02.y*templ_v02.y); double prev_d01 = sqrt((double)prev_v01.x*prev_v01.x + prev_v01.y*prev_v01.y); @@ -767,7 +767,7 @@ int ChoiceTrackingFace2(CvFaceTracker* pTF, const int nElements, const CvFaceEle double y = double(new_v01.x) * sin_a + double(new_v01.y) * cos_a; x = x * new_d02 / new_d01; y = y * new_d02 / new_d01; - CvPoint new_v02 = {int(x + 0.5), int(y + 0.5)}; + CvPoint new_v02(int(x + 0.5), int(y + 0.5)); face[element[2]].iColor = 0; face[element[2]].iEnergy = 0; face[element[2]].nRectsInThis = 0; @@ -818,10 +818,10 @@ inline int GetEnergy(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoin inline int GetEnergy2(CvTrackingRect** ppNew, const CvTrackingRect* pPrev, CvPoint* ptTempl, CvRect* rTempl, int* element) { - CvPoint new_v = {ppNew[element[0]]->ptCenter.x - ppNew[element[1]]->ptCenter.x, - ppNew[element[0]]->ptCenter.y - ppNew[element[1]]->ptCenter.y}; - CvPoint prev_v = {pPrev[element[0]].ptCenter.x - pPrev[element[1]].ptCenter.x, - pPrev[element[0]].ptCenter.y - pPrev[element[1]].ptCenter.y}; + CvPoint new_v(ppNew[element[0]]->ptCenter.x - ppNew[element[1]]->ptCenter.x, + ppNew[element[0]]->ptCenter.y - ppNew[element[1]]->ptCenter.y); + CvPoint prev_v(pPrev[element[0]].ptCenter.x - pPrev[element[1]].ptCenter.x, + pPrev[element[0]].ptCenter.y - pPrev[element[1]].ptCenter.y); double new_d = sqrt((double)new_v.x*new_v.x + new_v.y*new_v.y); double prev_d = sqrt((double)prev_v.x*prev_v.x + prev_v.y*prev_v.y); double dx = ptTempl[element[0]].x - ptTempl[element[1]].x; diff --git a/modules/legacy/test/test_pyrsegmentation.cpp b/modules/legacy/test/test_pyrsegmentation.cpp index 674265a7cf..5d7074465b 100644 --- a/modules/legacy/test/test_pyrsegmentation.cpp +++ b/modules/legacy/test/test_pyrsegmentation.cpp @@ -66,8 +66,8 @@ void CV_PyrSegmentationTest::run( int /*start_from*/ ) int code = cvtest::TS::OK; - CvPoint _cp[] ={{33,33}, {43,33}, {43,43}, {33,43}}; - CvPoint _cp2[] ={{50,50}, {70,50}, {70,70}, {50,70}}; + CvPoint _cp[] ={ CvPoint(33,33), CvPoint(43,33), CvPoint(43,43), CvPoint(33,43)}; + CvPoint _cp2[] ={CvPoint(50,50), CvPoint(70,50), CvPoint(70,70), CvPoint(50,70)}; CvPoint* cp = _cp; CvPoint* cp2 = _cp2; CvConnectedComp *dst_comp[3]; diff --git a/modules/ml/test/test_mltests2.cpp b/modules/ml/test/test_mltests2.cpp index 42400867f8..4f6c95921e 100644 --- a/modules/ml/test/test_mltests2.cpp +++ b/modules/ml/test/test_mltests2.cpp @@ -397,7 +397,7 @@ float ann_calc_error( CvANN_MLP* ann, CvMLData* _data, map& cls_map, i int si = sidx ? sidx[i] : i; cvGetRow( &predictors, &sample, si ); ann->predict( &sample, &_output ); - CvPoint best_cls = {0,0}; + CvPoint best_cls; cvMinMaxLoc( &_output, 0, 0, 0, &best_cls, 0 ); int r = cvRound(responses->data.fl[si*r_step]); CV_DbgAssert( fabs(responses->data.fl[si*r_step]-r) < FLT_EPSILON ); diff --git a/modules/objdetect/src/datamatrix.cpp b/modules/objdetect/src/datamatrix.cpp index a4d4af44eb..d1dfcdab21 100644 --- a/modules/objdetect/src/datamatrix.cpp +++ b/modules/objdetect/src/datamatrix.cpp @@ -43,7 +43,7 @@ unsigned char ccblk[256] = { 34,17,2,17,19,19,2,17,36,36,2,36,19,19,2,17,51,51,2 36,19,19,2,32,66,66,2,66,19,19,2,66,36,36,2,36,19,19,2,66,51,51,2,51,19,19,2,51,36,36,2,36,19,19,2,32,49,49,2,49, 19,19,2,49,36,36,2,36,19,19,2,49,51,51,2,51,19,19,2,51,36,36,2,36,19,19,2,49,66,66,2,66,19,19,2,66,36,36,2,36,19, 19,2,66,51,51,2,51,19,19,2,51,36,36,2,36,19,19,2,34 }; -static const CvPoint pickup[64] = { {7,6},{8,6},{7,5},{8,5},{1,5},{7,4},{8,4},{1,4},{1,8},{2,8},{1,7},{2,7},{3,7}, +static const int pickup[64][2] = { {7,6},{8,6},{7,5},{8,5},{1,5},{7,4},{8,4},{1,4},{1,8},{2,8},{1,7},{2,7},{3,7}, {1,6},{2,6},{3,6},{3,2},{4,2},{3,1},{4,1},{5,1},{3,8},{4,8},{5,8},{6,1},{7,1},{6,8},{7,8},{8,8},{6,7},{7,7},{8,7}, {4,7},{5,7},{4,6},{5,6},{6,6},{4,5},{5,5},{6,5},{2,5},{3,5},{2,4},{3,4},{4,4},{2,3},{3,3},{4,3},{8,3},{1,3},{8,2}, {1,2},{2,2},{8,1},{1,1},{2,1},{5,4},{6,4},{5,3},{6,3},{7,3},{5,2},{6,2},{7,2} }; @@ -255,7 +255,7 @@ static int decode(Sampler &sa, code &cc) sum += sa.getpixel(1 + (i & 7), 1 + (i >> 3)); uchar mean = (uchar)(sum / 64); for (int i = 0; i < 64; i++) { - b = (b << 1) + (sa.getpixel(pickup[i].x, pickup[i].y) <= mean); + b = (b << 1) + (sa.getpixel(pickup[i][0], pickup[i][1]) <= mean); if ((i & 7) == 7) { binary[i >> 3] = b; b = 0; diff --git a/samples/c/find_obj.cpp b/samples/c/find_obj.cpp index e0431fc6d4..8d03b02c9c 100644 --- a/samples/c/find_obj.cpp +++ b/samples/c/find_obj.cpp @@ -262,7 +262,7 @@ int main(int argc, char** argv) printf( "Extraction time = %gms\n", tt/(cvGetTickFrequency()*1000.)); - CvPoint src_corners[4] = {{0,0}, {object->width,0}, {object->width, object->height}, {0, object->height}}; + CvPoint src_corners[4] = {CvPoint(0,0), CvPoint(object->width,0), CvPoint(object->width, object->height), CvPoint(0, object->height)}; CvPoint dst_corners[4]; IplImage* correspond = cvCreateImage( cvSize(image->width, object->height+image->height), 8, 1 ); cvSetImageROI( correspond, cvRect( 0, 0, object->width, object->height ) ); diff --git a/samples/cpp/letter_recog.cpp b/samples/cpp/letter_recog.cpp index 74d5971caa..ddbe676291 100644 --- a/samples/cpp/letter_recog.cpp +++ b/samples/cpp/letter_recog.cpp @@ -463,7 +463,7 @@ int build_mlp_classifier( char* data_filename, int best_class; CvMat sample; cvGetRow( data, &sample, i ); - CvPoint max_loc = {0,0}; + CvPoint max_loc; mlp.predict( &sample, mlp_response ); cvMinMaxLoc( mlp_response, 0, 0, 0, &max_loc, 0 ); best_class = max_loc.x + 'A';