Commit ad146e5a authored by Alexander Alekhin's avatar Alexander Alekhin

core: remove constructors from C API structures

POD structures can't have constructors.
parent 66d15e89
...@@ -44,6 +44,27 @@ ...@@ -44,6 +44,27 @@
#ifndef OPENCV_CORE_TYPES_H #ifndef OPENCV_CORE_TYPES_H
#define OPENCV_CORE_TYPES_H #define OPENCV_CORE_TYPES_H
#define CV__ENABLE_C_API_CTORS // enable C API ctors (must be removed)
//#define CV__VALIDATE_UNUNITIALIZED_VARS 1 // C++11 & GCC only
#ifdef __cplusplus
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#define CV_STRUCT_INITIALIZER {0,}
#else
#if defined(__GNUC__) && __GNUC__ == 4 // GCC 4.x warns on "= {}" initialization, fixed in GCC 5.0
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
#define CV_STRUCT_INITIALIZER {}
#endif
#else
#define CV_STRUCT_INITIALIZER {0}
#endif
#ifdef HAVE_IPL #ifdef HAVE_IPL
# ifndef __IPL_H__ # ifndef __IPL_H__
# if defined _WIN32 # if defined _WIN32
...@@ -285,6 +306,11 @@ CV_INLINE double cvRandReal( CvRNG* rng ) ...@@ -285,6 +306,11 @@ CV_INLINE double cvRandReal( CvRNG* rng )
#define IPL_BORDER_REFLECT 2 #define IPL_BORDER_REFLECT 2
#define IPL_BORDER_WRAP 3 #define IPL_BORDER_WRAP 3
#ifdef __cplusplus
typedef struct _IplImage IplImage;
CV_EXPORTS _IplImage cvIplImage(const cv::Mat& m);
#endif
/** The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV /** The IplImage is taken from the Intel Image Processing Library, in which the format is native. OpenCV
only supports a subset of possible IplImage formats, as outlined in the parameter list above. only supports a subset of possible IplImage formats, as outlined in the parameter list above.
...@@ -294,9 +320,6 @@ hand, the Intel Image Processing Library processes the area of intersection betw ...@@ -294,9 +320,6 @@ hand, the Intel Image Processing Library processes the area of intersection betw
destination images (or ROIs), allowing them to vary independently. destination images (or ROIs), allowing them to vary independently.
*/ */
typedef struct typedef struct
#ifdef __cplusplus
CV_EXPORTS
#endif
_IplImage _IplImage
{ {
int nSize; /**< sizeof(IplImage) */ int nSize; /**< sizeof(IplImage) */
...@@ -330,13 +353,22 @@ _IplImage ...@@ -330,13 +353,22 @@ _IplImage
(not necessarily aligned) - (not necessarily aligned) -
needed for correct deallocation */ needed for correct deallocation */
#ifdef __cplusplus #if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
_IplImage() {} _IplImage() {}
_IplImage(const cv::Mat& m); _IplImage(const cv::Mat& m) { *this = cvIplImage(m); }
#endif #endif
} }
IplImage; IplImage;
CV_INLINE IplImage cvIplImage()
{
#if !defined(CV__ENABLE_C_API_CTORS)
IplImage self = CV_STRUCT_INITIALIZER; self.nSize = sizeof(IplImage); return self;
#else
return _IplImage();
#endif
}
typedef struct _IplTileInfo IplTileInfo; typedef struct _IplTileInfo IplTileInfo;
typedef struct _IplROI typedef struct _IplROI
...@@ -460,13 +492,10 @@ typedef struct CvMat ...@@ -460,13 +492,10 @@ typedef struct CvMat
int cols; int cols;
#endif #endif
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
#ifdef __cplusplus
CvMat() {} CvMat() {}
CvMat(const CvMat& m) { memcpy(this, &m, sizeof(CvMat));} CvMat(const cv::Mat& m) { *this = cvMat(m); }
CvMat(const cv::Mat& m);
#endif #endif
} }
CvMat; CvMat;
...@@ -529,15 +558,8 @@ CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL) ...@@ -529,15 +558,8 @@ CV_INLINE CvMat cvMat( int rows, int cols, int type, void* data CV_DEFAULT(NULL)
} }
#ifdef __cplusplus #ifdef __cplusplus
inline CvMat::CvMat(const cv::Mat& m)
{
CV_DbgAssert(m.dims <= 2);
*this = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data);
step = (int)m.step[0];
type = (type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
}
inline CvMat cvMat(const cv::Mat& m) CV_INLINE CvMat cvMat(const cv::Mat& m)
{ {
CvMat self; CvMat self;
CV_DbgAssert(m.dims <= 2); CV_DbgAssert(m.dims <= 2);
...@@ -546,7 +568,24 @@ inline CvMat cvMat(const cv::Mat& m) ...@@ -546,7 +568,24 @@ inline CvMat cvMat(const cv::Mat& m)
self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG); self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
return self; return self;
} }
CV_INLINE CvMat cvMat()
{
#if !defined(CV__ENABLE_C_API_CTORS)
CvMat self = CV_STRUCT_INITIALIZER; return self;
#else
return CvMat();
#endif #endif
}
CV_INLINE CvMat cvMat(const CvMat& m)
{
#if !defined(CV__ENABLE_C_API_CTORS)
CvMat self = CV_STRUCT_INITIALIZER; memcpy(&self, &m, sizeof(self)); return self;
#else
return CvMat(m);
#endif
}
#endif // __cplusplus
#define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \ #define CV_MAT_ELEM_PTR_FAST( mat, row, col, pix_size ) \
...@@ -630,13 +669,15 @@ CV_INLINE int cvIplDepth( int type ) ...@@ -630,13 +669,15 @@ CV_INLINE int cvIplDepth( int type )
#define CV_MAX_DIM 32 #define CV_MAX_DIM 32
#ifdef __cplusplus
typedef struct CvMatND CvMatND;
CV_EXPORTS CvMatND cvMatND(const cv::Mat& m);
#endif
/** /**
@deprecated consider using cv::Mat instead @deprecated consider using cv::Mat instead
*/ */
typedef struct typedef struct
#ifdef __cplusplus
CV_EXPORTS
#endif
CvMatND CvMatND
{ {
int type; int type;
...@@ -661,13 +702,23 @@ CvMatND ...@@ -661,13 +702,23 @@ CvMatND
} }
dim[CV_MAX_DIM]; dim[CV_MAX_DIM];
#ifdef __cplusplus #if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvMatND() {} CvMatND() {}
CvMatND(const cv::Mat& m); CvMatND(const cv::Mat& m) { *this = cvMatND(m); }
#endif #endif
} }
CvMatND; CvMatND;
CV_INLINE CvMatND cvMatND()
{
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvMatND self = CV_STRUCT_INITIALIZER; return self;
#else
return CvMatND();
#endif
}
#define CV_IS_MATND_HDR(mat) \ #define CV_IS_MATND_HDR(mat) \
((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL) ((mat) != NULL && (((const CvMatND*)(mat))->type & CV_MAGIC_MASK) == CV_MATND_MAGIC_VAL)
...@@ -684,11 +735,7 @@ CvMatND; ...@@ -684,11 +735,7 @@ CvMatND;
struct CvSet; struct CvSet;
typedef struct typedef struct CvSparseMat
#ifdef __cplusplus
CV_EXPORTS
#endif
CvSparseMat
{ {
int type; int type;
int dims; int dims;
...@@ -703,13 +750,13 @@ CvSparseMat ...@@ -703,13 +750,13 @@ CvSparseMat
int size[CV_MAX_DIM]; int size[CV_MAX_DIM];
#ifdef __cplusplus #ifdef __cplusplus
void copyToSparseMat(cv::SparseMat& m) const; CV_EXPORTS void copyToSparseMat(cv::SparseMat& m) const;
#endif #endif
} }
CvSparseMat; CvSparseMat;
#ifdef __cplusplus #ifdef __cplusplus
CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m); CV_EXPORTS CvSparseMat* cvCreateSparseMat(const cv::SparseMat& m);
#endif #endif
#define CV_IS_SPARSE_MAT_HDR(mat) \ #define CV_IS_SPARSE_MAT_HDR(mat) \
...@@ -796,10 +843,23 @@ typedef struct CvRect ...@@ -796,10 +843,23 @@ typedef struct CvRect
int width; int width;
int height; int height;
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvRect() __attribute__(( warning("Non-initialized variable") )) {};
template<typename _Tp> CvRect(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 4);
x = y = width = height = 0;
if (list.size() == 4)
{
x = list.begin()[0]; y = list.begin()[1]; width = list.begin()[2]; height = list.begin()[3];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {} CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {}
template<typename _Tp> template<typename _Tp>
CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast<int>(r.x)), y(cv::saturate_cast<int>(r.y)), width(cv::saturate_cast<int>(r.width)), height(cv::saturate_cast<int>(r.height)) {} CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast<int>(r.x)), y(cv::saturate_cast<int>(r.y)), width(cv::saturate_cast<int>(r.width)), height(cv::saturate_cast<int>(r.height)) {}
#endif
#ifdef __cplusplus
template<typename _Tp> template<typename _Tp>
operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); } operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); }
#endif #endif
...@@ -809,16 +869,16 @@ CvRect; ...@@ -809,16 +869,16 @@ CvRect;
/** constructs CvRect structure. */ /** constructs CvRect structure. */
CV_INLINE CvRect cvRect( int x, int y, int width, int height ) CV_INLINE CvRect cvRect( int x, int y, int width, int height )
{ {
CvRect r; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvRect r = {x, y, width, height};
r.x = x; #else
r.y = y; CvRect r(x, y , width, height);
r.width = width; #endif
r.height = height;
return r; return r;
} }
#ifdef __cplusplus
CV_INLINE CvRect cvRect(const cv::Rect& rc) { return cvRect(rc.x, rc.y, rc.width, rc.height); }
#endif
CV_INLINE IplROI cvRectToROI( CvRect rect, int coi ) CV_INLINE IplROI cvRectToROI( CvRect rect, int coi )
{ {
...@@ -853,26 +913,28 @@ typedef struct CvTermCriteria ...@@ -853,26 +913,28 @@ typedef struct CvTermCriteria
CV_TERMCRIT_EPS */ CV_TERMCRIT_EPS */
int max_iter; int max_iter;
double epsilon; double epsilon;
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
#ifdef __cplusplus
CvTermCriteria(int _type = 0, int _iter = 0, double _eps = 0) : type(_type), max_iter(_iter), epsilon(_eps) {} CvTermCriteria(int _type = 0, int _iter = 0, double _eps = 0) : type(_type), max_iter(_iter), epsilon(_eps) {}
CvTermCriteria(const cv::TermCriteria& t) : type(t.type), max_iter(t.maxCount), epsilon(t.epsilon) {} CvTermCriteria(const cv::TermCriteria& t) : type(t.type), max_iter(t.maxCount), epsilon(t.epsilon) {}
#endif
#ifdef __cplusplus
operator cv::TermCriteria() const { return cv::TermCriteria(type, max_iter, epsilon); } operator cv::TermCriteria() const { return cv::TermCriteria(type, max_iter, epsilon); }
#endif #endif
} }
CvTermCriteria; CvTermCriteria;
CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon ) CV_INLINE CvTermCriteria cvTermCriteria( int type, int max_iter, double epsilon )
{ {
CvTermCriteria t; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvTermCriteria t = { type, max_iter, (float)epsilon};
t.type = type; #else
t.max_iter = max_iter; CvTermCriteria t(type, max_iter, epsilon);
t.epsilon = (float)epsilon; #endif
return t; return t;
} }
#ifdef __cplusplus
CV_INLINE CvTermCriteria cvTermCriteria(const cv::TermCriteria& t) { return cvTermCriteria(t.type, t.maxCount, t.epsilon); }
#endif
/******************************* CvPoint and variants ***********************************/ /******************************* CvPoint and variants ***********************************/
...@@ -882,10 +944,23 @@ typedef struct CvPoint ...@@ -882,10 +944,23 @@ typedef struct CvPoint
int x; int x;
int y; int y;
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvPoint() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvPoint(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 2);
x = y = 0;
if (list.size() == 2)
{
x = list.begin()[0]; y = list.begin()[1];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {} CvPoint(int _x = 0, int _y = 0): x(_x), y(_y) {}
template<typename _Tp> template<typename _Tp>
CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {} CvPoint(const cv::Point_<_Tp>& pt): x((int)pt.x), y((int)pt.y) {}
#endif
#ifdef __cplusplus
template<typename _Tp> template<typename _Tp>
operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); }
#endif #endif
...@@ -895,24 +970,39 @@ CvPoint; ...@@ -895,24 +970,39 @@ CvPoint;
/** constructs CvPoint structure. */ /** constructs CvPoint structure. */
CV_INLINE CvPoint cvPoint( int x, int y ) CV_INLINE CvPoint cvPoint( int x, int y )
{ {
CvPoint p; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvPoint p = {x, y};
p.x = x; #else
p.y = y; CvPoint p(x, y);
#endif
return p; return p;
} }
#ifdef __cplusplus
CV_INLINE CvPoint cvPoint(const cv::Point& pt) { return cvPoint(pt.x, pt.y); }
#endif
typedef struct CvPoint2D32f typedef struct CvPoint2D32f
{ {
float x; float x;
float y; float y;
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvPoint2D32f() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvPoint2D32f(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 2);
x = y = 0;
if (list.size() == 2)
{
x = list.begin()[0]; y = list.begin()[1];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {} CvPoint2D32f(float _x = 0, float _y = 0): x(_x), y(_y) {}
template<typename _Tp> template<typename _Tp>
CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {} CvPoint2D32f(const cv::Point_<_Tp>& pt): x((float)pt.x), y((float)pt.y) {}
#endif
#ifdef __cplusplus
template<typename _Tp> template<typename _Tp>
operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); } operator cv::Point_<_Tp>() const { return cv::Point_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y)); }
#endif #endif
...@@ -922,11 +1012,11 @@ CvPoint2D32f; ...@@ -922,11 +1012,11 @@ CvPoint2D32f;
/** constructs CvPoint2D32f structure. */ /** constructs CvPoint2D32f structure. */
CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y ) CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
{ {
CvPoint2D32f p; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvPoint2D32f p = { (float)x, (float)y };
p.x = (float)x; #else
p.y = (float)y; CvPoint2D32f p((float)x, (float)y);
#endif
return p; return p;
} }
...@@ -934,7 +1024,11 @@ CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y ) ...@@ -934,7 +1024,11 @@ CV_INLINE CvPoint2D32f cvPoint2D32f( double x, double y )
template<typename _Tp> template<typename _Tp>
CvPoint2D32f cvPoint2D32f(const cv::Point_<_Tp>& pt) CvPoint2D32f cvPoint2D32f(const cv::Point_<_Tp>& pt)
{ {
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvPoint2D32f p = { (float)pt.x, (float)pt.y };
#else
CvPoint2D32f p((float)pt.x, (float)pt.y); CvPoint2D32f p((float)pt.x, (float)pt.y);
#endif
return p; return p;
} }
#endif #endif
...@@ -948,10 +1042,11 @@ CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point ) ...@@ -948,10 +1042,11 @@ CV_INLINE CvPoint2D32f cvPointTo32f( CvPoint point )
/** converts CvPoint2D32f to CvPoint. */ /** converts CvPoint2D32f to CvPoint. */
CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point ) CV_INLINE CvPoint cvPointFrom32f( CvPoint2D32f point )
{ {
CvPoint ipt; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
ipt.x = cvRound(point.x); CvPoint ipt = { cvRound(point.x), cvRound(point.y) };
ipt.y = cvRound(point.y); #else
CvPoint ipt(cvRound(point.x), cvRound(point.y));
#endif
return ipt; return ipt;
} }
...@@ -962,10 +1057,23 @@ typedef struct CvPoint3D32f ...@@ -962,10 +1057,23 @@ typedef struct CvPoint3D32f
float y; float y;
float z; float z;
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvPoint3D32f() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvPoint3D32f(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 3);
x = y = z = 0;
if (list.size() == 3)
{
x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {} CvPoint3D32f(float _x = 0, float _y = 0, float _z = 0): x(_x), y(_y), z(_z) {}
template<typename _Tp> template<typename _Tp>
CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {} CvPoint3D32f(const cv::Point3_<_Tp>& pt): x((float)pt.x), y((float)pt.y), z((float)pt.z) {}
#endif
#ifdef __cplusplus
template<typename _Tp> template<typename _Tp>
operator cv::Point3_<_Tp>() const { return cv::Point3_<_Tp>(cv::saturate_cast<_Tp>(x), cv::saturate_cast<_Tp>(y), cv::saturate_cast<_Tp>(z)); } 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 #endif
...@@ -975,31 +1083,51 @@ CvPoint3D32f; ...@@ -975,31 +1083,51 @@ CvPoint3D32f;
/** constructs CvPoint3D32f structure. */ /** constructs CvPoint3D32f structure. */
CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z ) CV_INLINE CvPoint3D32f cvPoint3D32f( double x, double y, double z )
{ {
CvPoint3D32f p; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvPoint3D32f p = { (float)x, (float)y, (float)z };
p.x = (float)x; #else
p.y = (float)y; CvPoint3D32f p((float)x, (float)y, (float)z);
p.z = (float)z; #endif
return p;
}
#ifdef __cplusplus
template<typename _Tp>
CvPoint3D32f cvPoint3D32f(const cv::Point3_<_Tp>& pt)
{
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvPoint3D32f p = { (float)pt.x, (float)pt.y, (float)pt.z };
#else
CvPoint3D32f p((float)pt.x, (float)pt.y, (float)pt.z);
#endif
return p; return p;
} }
#endif
typedef struct CvPoint2D64f typedef struct CvPoint2D64f
{ {
double x; double x;
double y; double y;
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvPoint2D64f() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvPoint2D64f(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 2);
x = y = 0;
if (list.size() == 2)
{
x = list.begin()[0]; y = list.begin()[1];
}
};
#endif
} }
CvPoint2D64f; CvPoint2D64f;
/** constructs CvPoint2D64f structure.*/ /** constructs CvPoint2D64f structure.*/
CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y ) CV_INLINE CvPoint2D64f cvPoint2D64f( double x, double y )
{ {
CvPoint2D64f p; CvPoint2D64f p = { x, y };
p.x = x;
p.y = y;
return p; return p;
} }
...@@ -1009,18 +1137,25 @@ typedef struct CvPoint3D64f ...@@ -1009,18 +1137,25 @@ typedef struct CvPoint3D64f
double x; double x;
double y; double y;
double z; double z;
#ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvPoint3D64f() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvPoint3D64f(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 3);
x = y = z = 0;
if (list.size() == 3)
{
x = list.begin()[0]; y = list.begin()[1]; z = list.begin()[2];
}
};
#endif
} }
CvPoint3D64f; CvPoint3D64f;
/** constructs CvPoint3D64f structure. */ /** constructs CvPoint3D64f structure. */
CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z ) CV_INLINE CvPoint3D64f cvPoint3D64f( double x, double y, double z )
{ {
CvPoint3D64f p; CvPoint3D64f p = { x, y, z };
p.x = x;
p.y = y;
p.z = z;
return p; return p;
} }
...@@ -1032,10 +1167,23 @@ typedef struct CvSize ...@@ -1032,10 +1167,23 @@ typedef struct CvSize
int width; int width;
int height; int height;
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvSize() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvSize(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 2);
width = 0; height = 0;
if (list.size() == 2)
{
width = list.begin()[0]; height = list.begin()[1];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvSize(int w = 0, int h = 0): width(w), height(h) {} CvSize(int w = 0, int h = 0): width(w), height(h) {}
template<typename _Tp> template<typename _Tp>
CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<int>(sz.width)), height(cv::saturate_cast<int>(sz.height)) {} CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<int>(sz.width)), height(cv::saturate_cast<int>(sz.height)) {}
#endif
#ifdef __cplusplus
template<typename _Tp> template<typename _Tp>
operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); }
#endif #endif
...@@ -1045,23 +1193,48 @@ CvSize; ...@@ -1045,23 +1193,48 @@ CvSize;
/** constructs CvSize structure. */ /** constructs CvSize structure. */
CV_INLINE CvSize cvSize( int width, int height ) CV_INLINE CvSize cvSize( int width, int height )
{ {
CvSize s; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvSize s = { width, height };
s.width = width; #else
s.height = height; CvSize s(width, height);
#endif
return s;
}
#ifdef __cplusplus
CV_INLINE CvSize cvSize(const cv::Size& sz)
{
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvSize s = { sz.width, sz.height };
#else
CvSize s(sz.width, sz.height);
#endif
return s; return s;
} }
#endif
typedef struct CvSize2D32f typedef struct CvSize2D32f
{ {
float width; float width;
float height; float height;
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvSize2D32f() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvSize2D32f(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 2);
width = 0; height = 0;
if (list.size() == 2)
{
width = list.begin()[0]; height = list.begin()[1];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {} CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {}
template<typename _Tp> template<typename _Tp>
CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<float>(sz.width)), height(cv::saturate_cast<float>(sz.height)) {} CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast<float>(sz.width)), height(cv::saturate_cast<float>(sz.height)) {}
#endif
#ifdef __cplusplus
template<typename _Tp> template<typename _Tp>
operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); }
#endif #endif
...@@ -1071,13 +1244,25 @@ CvSize2D32f; ...@@ -1071,13 +1244,25 @@ CvSize2D32f;
/** constructs CvSize2D32f structure. */ /** constructs CvSize2D32f structure. */
CV_INLINE CvSize2D32f cvSize2D32f( double width, double height ) CV_INLINE CvSize2D32f cvSize2D32f( double width, double height )
{ {
CvSize2D32f s; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvSize2D32f s = { (float)width, (float)height };
s.width = (float)width; #else
s.height = (float)height; CvSize2D32f s((float)width, (float)height);
#endif
return s; return s;
} }
#ifdef __cplusplus
template<typename _Tp>
CvSize2D32f cvSize2D32f(const cv::Size_<_Tp>& sz)
{
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvSize2D32f s = { (float)sz.width, (float)sz.height };
#else
CvSize2D32f s((float)sz.width, (float)sz.height);
#endif
return s;
}
#endif
/** @sa RotatedRect /** @sa RotatedRect
*/ */
...@@ -1088,15 +1273,37 @@ typedef struct CvBox2D ...@@ -1088,15 +1273,37 @@ typedef struct CvBox2D
float angle; /**< Angle between the horizontal axis */ float angle; /**< Angle between the horizontal axis */
/**< and the first side (i.e. length) in degrees */ /**< and the first side (i.e. length) in degrees */
#ifdef __cplusplus #if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) : center(c), size(s), angle(a) {} CvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0) : center(c), size(s), angle(a) {}
CvBox2D(const cv::RotatedRect& rr) : center(rr.center), size(rr.size), angle(rr.angle) {} CvBox2D(const cv::RotatedRect& rr) : center(rr.center), size(rr.size), angle(rr.angle) {}
#endif
#ifdef __cplusplus
operator cv::RotatedRect() const { return cv::RotatedRect(center, size, angle); } operator cv::RotatedRect() const { return cv::RotatedRect(center, size, angle); }
#endif #endif
} }
CvBox2D; CvBox2D;
#ifdef __cplusplus
CV_INLINE CvBox2D cvBox2D(CvPoint2D32f c = CvPoint2D32f(), CvSize2D32f s = CvSize2D32f(), float a = 0)
{
CvBox2D self;
self.center = c;
self.size = s;
self.angle = a;
return self;
}
CV_INLINE CvBox2D cvBox2D(const cv::RotatedRect& rr)
{
CvBox2D self;
self.center = cvPoint2D32f(rr.center);
self.size = cvSize2D32f(rr.size);
self.angle = rr.angle;
return self;
}
#endif
/** Line iterator state: */ /** Line iterator state: */
typedef struct CvLineIterator typedef struct CvLineIterator
{ {
...@@ -1122,7 +1329,19 @@ typedef struct CvSlice ...@@ -1122,7 +1329,19 @@ typedef struct CvSlice
{ {
int start_index, end_index; int start_index, end_index;
#if defined(__cplusplus) && !defined(__CUDACC__) #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvSlice() __attribute__(( warning("Non-initialized variable") )) {}
template<typename _Tp> CvSlice(const std::initializer_list<_Tp> list)
{
CV_Assert(list.size() == 0 || list.size() == 2);
start_index = end_index = 0;
if (list.size() == 2)
{
start_index = list.begin()[0]; end_index = list.begin()[1];
}
};
#endif
#if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus) && !defined(__CUDACC__)
CvSlice(int start = 0, int end = 0) : start_index(start), end_index(end) {} CvSlice(int start = 0, int end = 0) : start_index(start), end_index(end) {}
CvSlice(const cv::Range& r) { *this = (r.start != INT_MIN && r.end != INT_MAX) ? CvSlice(r.start, r.end) : CvSlice(0, CV_WHOLE_SEQ_END_INDEX); } CvSlice(const cv::Range& r) { *this = (r.start != INT_MIN && r.end != INT_MAX) ? CvSlice(r.start, r.end) : CvSlice(0, CV_WHOLE_SEQ_END_INDEX); }
operator cv::Range() const { return (start_index == 0 && end_index == CV_WHOLE_SEQ_END_INDEX ) ? cv::Range::all() : cv::Range(start_index, end_index); } operator cv::Range() const { return (start_index == 0 && end_index == CV_WHOLE_SEQ_END_INDEX ) ? cv::Range::all() : cv::Range(start_index, end_index); }
...@@ -1132,13 +1351,21 @@ CvSlice; ...@@ -1132,13 +1351,21 @@ CvSlice;
CV_INLINE CvSlice cvSlice( int start, int end ) CV_INLINE CvSlice cvSlice( int start, int end )
{ {
CvSlice slice; #if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
slice.start_index = start; CvSlice slice = { start, end };
slice.end_index = end; #else
CvSlice slice(start, end);
#endif
return slice; return slice;
} }
#if defined(__cplusplus)
CV_INLINE CvSlice cvSlice(const cv::Range& r)
{
CvSlice slice = (r.start != INT_MIN && r.end != INT_MAX) ? cvSlice(r.start, r.end) : cvSlice(0, CV_WHOLE_SEQ_END_INDEX);
return slice;
}
#endif
/************************************* CvScalar *****************************************/ /************************************* CvScalar *****************************************/
...@@ -1148,13 +1375,22 @@ typedef struct CvScalar ...@@ -1148,13 +1375,22 @@ typedef struct CvScalar
{ {
double val[4]; double val[4];
#ifdef __cplusplus #ifdef CV__VALIDATE_UNUNITIALIZED_VARS
CvScalar() __attribute__(( warning("Non-initialized variable") )) {}
CvScalar(const std::initializer_list<double> list)
{
CV_Assert(list.size() == 0 || list.size() == 4);
val[0] = val[1] = val[2] = val[3] = 0;
if (list.size() == 4)
{
val[0] = list.begin()[0]; val[1] = list.begin()[1]; val[2] = list.begin()[2]; val[3] = list.begin()[3];
}
};
#elif defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvScalar() {} CvScalar() {}
CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; } CvScalar(double d0, double d1 = 0, double d2 = 0, double d3 = 0) { val[0] = d0; val[1] = d1; val[2] = d2; val[3] = d3; }
template<typename _Tp> template<typename _Tp>
CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; } CvScalar(const cv::Scalar_<_Tp>& s) { val[0] = s.val[0]; val[1] = s.val[1]; val[2] = s.val[2]; val[3] = s.val[3]; }
template<typename _Tp>
operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); }
template<typename _Tp, int cn> template<typename _Tp, int cn>
CvScalar(const cv::Vec<_Tp, cn>& v) CvScalar(const cv::Vec<_Tp, cn>& v)
{ {
...@@ -1163,22 +1399,59 @@ typedef struct CvScalar ...@@ -1163,22 +1399,59 @@ typedef struct CvScalar
for( ; i < 4; i++ ) val[i] = 0; for( ; i < 4; i++ ) val[i] = 0;
} }
#endif #endif
#ifdef __cplusplus
template<typename _Tp>
operator cv::Scalar_<_Tp>() const { return cv::Scalar_<_Tp>(cv::saturate_cast<_Tp>(val[0]), cv::saturate_cast<_Tp>(val[1]), cv::saturate_cast<_Tp>(val[2]), cv::saturate_cast<_Tp>(val[3])); }
#endif
} }
CvScalar; CvScalar;
CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0), CV_INLINE CvScalar cvScalar( double val0, double val1 CV_DEFAULT(0),
double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0)) double val2 CV_DEFAULT(0), double val3 CV_DEFAULT(0))
{ {
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvScalar scalar = CV_STRUCT_INITIALIZER;
#else
CvScalar scalar; CvScalar scalar;
#endif
scalar.val[0] = val0; scalar.val[1] = val1; scalar.val[0] = val0; scalar.val[1] = val1;
scalar.val[2] = val2; scalar.val[3] = val3; scalar.val[2] = val2; scalar.val[3] = val3;
return scalar; return scalar;
} }
#ifdef __cplusplus
CV_INLINE CvScalar cvScalar()
{
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvScalar scalar = CV_STRUCT_INITIALIZER;
#else
CvScalar scalar;
#endif
scalar.val[0] = scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
return scalar;
}
CV_INLINE CvScalar cvScalar(const cv::Scalar& s)
{
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvScalar scalar = CV_STRUCT_INITIALIZER;
#else
CvScalar scalar;
#endif
scalar.val[0] = s.val[0];
scalar.val[1] = s.val[1];
scalar.val[2] = s.val[2];
scalar.val[3] = s.val[3];
return scalar;
}
#endif
CV_INLINE CvScalar cvRealScalar( double val0 ) CV_INLINE CvScalar cvRealScalar( double val0 )
{ {
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvScalar scalar = CV_STRUCT_INITIALIZER;
#else
CvScalar scalar; CvScalar scalar;
#endif
scalar.val[0] = val0; scalar.val[0] = val0;
scalar.val[1] = scalar.val[2] = scalar.val[3] = 0; scalar.val[1] = scalar.val[2] = scalar.val[3] = 0;
return scalar; return scalar;
...@@ -1186,7 +1459,11 @@ CV_INLINE CvScalar cvRealScalar( double val0 ) ...@@ -1186,7 +1459,11 @@ CV_INLINE CvScalar cvRealScalar( double val0 )
CV_INLINE CvScalar cvScalarAll( double val0123 ) CV_INLINE CvScalar cvScalarAll( double val0123 )
{ {
#if !(defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus))
CvScalar scalar = CV_STRUCT_INITIALIZER;
#else
CvScalar scalar; CvScalar scalar;
#endif
scalar.val[0] = val0123; scalar.val[0] = val0123;
scalar.val[1] = val0123; scalar.val[1] = val0123;
scalar.val[2] = val0123; scalar.val[2] = val0123;
...@@ -1239,7 +1516,7 @@ typedef struct CvSeqBlock ...@@ -1239,7 +1516,7 @@ typedef struct CvSeqBlock
{ {
struct CvSeqBlock* prev; /**< Previous sequence block. */ struct CvSeqBlock* prev; /**< Previous sequence block. */
struct CvSeqBlock* next; /**< Next sequence block. */ struct CvSeqBlock* next; /**< Next sequence block. */
int start_index; /**< Index of the first element in the block + */ int start_index; /**< Index of the first element in the block + */
/**< sequence->first->start_index. */ /**< sequence->first->start_index. */
int count; /**< Number of elements in the block. */ int count; /**< Number of elements in the block. */
schar* data; /**< Pointer to the first element of the block. */ schar* data; /**< Pointer to the first element of the block. */
......
...@@ -4,20 +4,24 @@ ...@@ -4,20 +4,24 @@
// glue // glue
CvMatND::CvMatND(const cv::Mat& m) CvMatND cvMatND(const cv::Mat& m)
{ {
cvInitMatNDHeader(this, m.dims, m.size, m.type(), m.data ); CvMatND self;
cvInitMatNDHeader(&self, m.dims, m.size, m.type(), m.data );
int i, d = m.dims; int i, d = m.dims;
for( i = 0; i < d; i++ ) for( i = 0; i < d; i++ )
dim[i].step = (int)m.step[i]; self.dim[i].step = (int)m.step[i];
type |= m.flags & cv::Mat::CONTINUOUS_FLAG; self.type |= m.flags & cv::Mat::CONTINUOUS_FLAG;
return self;
} }
_IplImage::_IplImage(const cv::Mat& m) _IplImage cvIplImage(const cv::Mat& m)
{ {
_IplImage self;
CV_Assert( m.dims <= 2 ); CV_Assert( m.dims <= 2 );
cvInitImageHeader(this, m.size(), cvIplDepth(m.flags), m.channels()); cvInitImageHeader(&self, cvSize(m.size()), cvIplDepth(m.flags), m.channels());
cvSetData(this, m.data, (int)m.step[0]); cvSetData(&self, m.data, (int)m.step[0]);
return self;
} }
namespace cv { namespace cv {
......
...@@ -410,7 +410,7 @@ typedef struct CvMoments ...@@ -410,7 +410,7 @@ typedef struct CvMoments
double mu20, mu11, mu02, mu30, mu21, mu12, mu03; /**< central moments */ double mu20, mu11, mu02, mu30, mu21, mu12, mu03; /**< central moments */
double inv_sqrt_m00; /**< m00 != 0 ? 1/sqrt(m00) : 0 */ double inv_sqrt_m00; /**< m00 != 0 ? 1/sqrt(m00) : 0 */
#ifdef __cplusplus #if defined(CV__ENABLE_C_API_CTORS) && defined(__cplusplus)
CvMoments(){} CvMoments(){}
CvMoments(const cv::Moments& m) CvMoments(const cv::Moments& m)
{ {
...@@ -430,6 +430,36 @@ typedef struct CvMoments ...@@ -430,6 +430,36 @@ typedef struct CvMoments
} }
CvMoments; CvMoments;
#ifdef __cplusplus
} // extern "C"
CV_INLINE CvMoments cvMoments()
{
#if !defined(CV__ENABLE_C_API_CTORS)
CvMoments self = CV_STRUCT_INITIALIZER; return self;
#else
return CvMoments();
#endif
}
CV_INLINE CvMoments cvMoments(const cv::Moments& m)
{
#if !defined(CV__ENABLE_C_API_CTORS)
double am00 = std::abs(m.m00);
CvMoments self = {
m.m00, m.m10, m.m01, m.m20, m.m11, m.m02, m.m30, m.m21, m.m12, m.m03,
m.mu20, m.mu11, m.mu02, m.mu30, m.mu21, m.mu12, m.mu03,
am00 > DBL_EPSILON ? 1./std::sqrt(am00) : 0
};
return self;
#else
return CvMoments(m);
#endif
}
extern "C" {
#endif // __cplusplus
/** Hu invariants */ /** Hu invariants */
typedef struct CvHuMoments typedef struct CvHuMoments
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment