From addf0309ec0e59ad47d27599e85e778cb4c65cfc Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 26 Mar 2013 20:23:40 +0400 Subject: [PATCH] Move cv::Size_ --- modules/core/include/opencv2/core.hpp | 38 ------------------- .../core/include/opencv2/core/operations.hpp | 8 ---- modules/core/include/opencv2/core/types.hpp | 38 +++++++++++++++++++ modules/core/include/opencv2/core/types_c.h | 16 ++++++++ modules/core/src/array.cpp | 2 +- modules/highgui/src/utils.cpp | 2 +- modules/legacy/src/optflowbm.cpp | 5 +-- modules/legacy/src/pyrsegmentation.cpp | 4 +- modules/legacy/src/testseq.cpp | 4 +- modules/legacy/src/vecfacetracking.cpp | 2 +- modules/legacy/test/test_pyrsegmentation.cpp | 2 +- modules/objdetect/src/haar.cpp | 12 +++--- 12 files changed, 70 insertions(+), 63 deletions(-) diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 18cc2cb77a..0b05f7739b 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -524,41 +524,6 @@ typedef Vec Vec4d; typedef Vec Vec6d; -//////////////////////////////// Size_ //////////////////////////////// - -/*! - The 2D size class - - The class represents the size of a 2D rectangle, image size, matrix size etc. - Normally, cv::Size ~ cv::Size_ is used. -*/ -template class CV_EXPORTS Size_ -{ -public: - typedef _Tp value_type; - - //! various constructors - Size_(); - Size_(_Tp _width, _Tp _height); - Size_(const Size_& sz); - Size_(const CvSize& sz); - Size_(const CvSize2D32f& sz); - Size_(const Point_<_Tp>& pt); - - Size_& operator = (const Size_& sz); - //! the area (width*height) - _Tp area() const; - - //! conversion of another data type. - template operator Size_<_Tp2>() const; - - //! conversion to the old-style OpenCV types - operator CvSize() const; - operator CvSize2D32f() const; - - _Tp width, height; // the width and the height -}; - //////////////////////////////// Rect_ //////////////////////////////// /*! @@ -608,10 +573,7 @@ public: shorter aliases for the most popular cv::Point_<>, cv::Size_<> and cv::Rect_<> specializations */ -typedef Size_ Size2i; -typedef Size2i Size; typedef Rect_ Rect; -typedef Size_ Size2f; /*! diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index a492dba528..4007a3dc99 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -1754,18 +1754,10 @@ template inline Size_<_Tp>::Size_(_Tp _width, _Tp _height) : width(_width), height(_height) {} template inline Size_<_Tp>::Size_(const Size_& sz) : width(sz.width), height(sz.height) {} -template inline Size_<_Tp>::Size_(const CvSize& sz) - : width(saturate_cast<_Tp>(sz.width)), height(saturate_cast<_Tp>(sz.height)) {} -template inline Size_<_Tp>::Size_(const CvSize2D32f& sz) - : width(saturate_cast<_Tp>(sz.width)), height(saturate_cast<_Tp>(sz.height)) {} template inline Size_<_Tp>::Size_(const Point_<_Tp>& pt) : width(pt.x), height(pt.y) {} template template inline Size_<_Tp>::operator Size_<_Tp2>() const { return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height)); } -template inline Size_<_Tp>::operator CvSize() const -{ return cvSize(saturate_cast(width), saturate_cast(height)); } -template inline Size_<_Tp>::operator CvSize2D32f() const -{ return cvSize2D32f((float)width, (float)height); } template inline Size_<_Tp>& Size_<_Tp>::operator = (const Size_<_Tp>& sz) { width = sz.width; height = sz.height; return *this; } diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index 20cd07096a..71857bc363 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -246,6 +246,44 @@ typedef Point3_ Point3i; typedef Point3_ Point3f; typedef Point3_ Point3d; + + +//////////////////////////////// Size_ //////////////////////////////// + +/*! + The 2D size class + + The class represents the size of a 2D rectangle, image size, matrix size etc. + Normally, cv::Size ~ cv::Size_ is used. +*/ +template class CV_EXPORTS Size_ +{ +public: + typedef _Tp value_type; + + //! various constructors + Size_(); + Size_(_Tp _width, _Tp _height); + Size_(const Size_& sz); + Size_(const Point_<_Tp>& pt); + + Size_& operator = (const Size_& sz); + //! the area (width*height) + _Tp area() const; + + //! conversion of another data type. + template operator Size_<_Tp2>() const; + + _Tp width, height; // the width and the height +}; + +/*! + \typedef +*/ +typedef Size_ Size2i; +typedef Size_ Size2f; +typedef Size2i Size; + } // 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 2f1d3455e7..609dd2367a 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -894,6 +894,14 @@ typedef struct CvSize { int width; int height; + +#ifdef __cplusplus + CvSize(int w = 0, int h = 0): width(w), height(h) {} + template + CvSize(const cv::Size_<_Tp>& sz): width(cv::saturate_cast(sz.width)), height(cv::saturate_cast(sz.height)) {} + template + operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } +#endif } CvSize; @@ -911,6 +919,14 @@ typedef struct CvSize2D32f { float width; float height; + +#ifdef __cplusplus + CvSize2D32f(float w = 0, float h = 0): width(w), height(h) {} + template + CvSize2D32f(const cv::Size_<_Tp>& sz): width(cv::saturate_cast(sz.width)), height(cv::saturate_cast(sz.height)) {} + template + operator cv::Size_<_Tp>() const { return cv::Size_<_Tp>(cv::saturate_cast<_Tp>(width), cv::saturate_cast<_Tp>(height)); } +#endif } CvSize2D32f; diff --git a/modules/core/src/array.cpp b/modules/core/src/array.cpp index 9c024293eb..f4e3f3a5ca 100644 --- a/modules/core/src/array.cpp +++ b/modules/core/src/array.cpp @@ -1210,7 +1210,7 @@ cvGetDimSize( const CvArr* arr, int index ) CV_IMPL CvSize cvGetSize( const CvArr* arr ) { - CvSize size = { 0, 0 }; + CvSize size; if( CV_IS_MAT_HDR_Z( arr )) { diff --git a/modules/highgui/src/utils.cpp b/modules/highgui/src/utils.cpp index 095a256ae2..7efd3830ea 100644 --- a/modules/highgui/src/utils.cpp +++ b/modules/highgui/src/utils.cpp @@ -641,7 +641,7 @@ cvConvertImage( const CvArr* srcarr, CvArr* dstarr, int flags ) uchar *s = src->data.ptr, *d = dst->data.ptr; int s_step = src->step, d_step = dst->step; int code = src_cn*10 + dst_cn; - CvSize size = { src->cols, src->rows }; + CvSize size(src->cols, src->rows); if( CV_IS_MAT_CONT(src->type & dst->type) ) { diff --git a/modules/legacy/src/optflowbm.cpp b/modules/legacy/src/optflowbm.cpp index afab0c1fe8..91b55cd584 100644 --- a/modules/legacy/src/optflowbm.cpp +++ b/modules/legacy/src/optflowbm.cpp @@ -75,11 +75,10 @@ cvCalcOpticalFlowBM( const void* srcarrA, const void* srcarrB, if( !CV_ARE_TYPES_EQ( velx, vely )) CV_Error( CV_StsUnmatchedFormats, "Destination images have different formats" ); - CvSize velSize = - { + CvSize velSize( (srcA->width - blockSize.width + shiftSize.width)/shiftSize.width, (srcA->height - blockSize.height + shiftSize.height)/shiftSize.height - }; + ); if( !CV_ARE_SIZES_EQ( srcA, srcB ) || !CV_ARE_SIZES_EQ( velx, vely ) || diff --git a/modules/legacy/src/pyrsegmentation.cpp b/modules/legacy/src/pyrsegmentation.cpp index c64b7bcde0..e4097c681e 100644 --- a/modules/legacy/src/pyrsegmentation.cpp +++ b/modules/legacy/src/pyrsegmentation.cpp @@ -287,7 +287,7 @@ icvPyrSegmentation8uC1R( uchar * src_image, int src_step, /* calculate initial pyramid */ for( l = 1; l <= level; l++ ) { - CvSize dst_size = { size.width/2+1, size.height/2+1 }; + CvSize dst_size(size.width/2+1, size.height/2+1); CvMat prev_level = cvMat( size.height, size.width, CV_32FC1 ); CvMat next_level = cvMat( dst_size.height, dst_size.width, CV_32FC1 ); @@ -706,7 +706,7 @@ icvPyrSegmentation8uC3R( uchar * src_image, int src_step, /* calculate initial pyramid */ for( l = 1; l <= level; l++ ) { - CvSize dst_size = { size.width/2 + 1, size.height/2 + 1 }; + CvSize dst_size(size.width/2 + 1, size.height/2 + 1); CvMat prev_level = cvMat( size.height, size.width, CV_32FC3 ); CvMat next_level = cvMat( dst_size.height, dst_size.width, CV_32FC3 ); diff --git a/modules/legacy/src/testseq.cpp b/modules/legacy/src/testseq.cpp index d3521a5ae2..2f7e0d2a2a 100644 --- a/modules/legacy/src/testseq.cpp +++ b/modules/legacy/src/testseq.cpp @@ -850,13 +850,13 @@ CvTestSeq* cvCreateTestSeq(char* pConfigfile, char** videos, int numvideo, float { /* Calculate elements and image size and video length: */ CvTestSeqElem* p = pTS->pElemList; int num = 0; - CvSize MaxSize = {0,0}; + CvSize MaxSize; int MaxFN = 0; for(p = pTS->pElemList; p; p=p->next, num++) { int FN = p->FrameBegin+p->FrameNum; - CvSize S = {0,0}; + CvSize S; if(p->pImg && p->BG) { diff --git a/modules/legacy/src/vecfacetracking.cpp b/modules/legacy/src/vecfacetracking.cpp index c532a69b24..8ca75432a4 100644 --- a/modules/legacy/src/vecfacetracking.cpp +++ b/modules/legacy/src/vecfacetracking.cpp @@ -157,7 +157,7 @@ struct CvFaceTracker }; int InitNextImage(IplImage* img) { - CvSize sz = {img->width, img->height}; + CvSize sz(img->width, img->height); ReallocImage(&imgGray, sz, 1); ReallocImage(&imgThresh, sz, 1); ptRotate = face[MOUTH].ptCenter; diff --git a/modules/legacy/test/test_pyrsegmentation.cpp b/modules/legacy/test/test_pyrsegmentation.cpp index 5d7074465b..e52cc4ef1d 100644 --- a/modules/legacy/test/test_pyrsegmentation.cpp +++ b/modules/legacy/test/test_pyrsegmentation.cpp @@ -86,7 +86,7 @@ void CV_PyrSegmentationTest::run( int /*start_from*/ ) int i, j, iter; IplImage *image, *image_f, *image_s; - CvSize size = {128, 128}; + CvSize size(128, 128); const int threshold1 = 50, threshold2 = 50; rect[1].width = size.width; diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index 4166162739..23e7287f49 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1569,10 +1569,10 @@ cvHaarDetectObjectsForROC( const CvArr* _img, for( factor = 1; ; factor *= scaleFactor ) { - CvSize winSize = { cvRound(winSize0.width*factor), - cvRound(winSize0.height*factor) }; - CvSize sz = { cvRound( img->cols/factor ), cvRound( img->rows/factor ) }; - CvSize sz1 = { sz.width - winSize0.width + 1, sz.height - winSize0.height + 1 }; + CvSize winSize(cvRound(winSize0.width*factor), + cvRound(winSize0.height*factor)); + CvSize sz(cvRound( img->cols/factor ), cvRound( img->rows/factor )); + CvSize sz1(sz.width - winSize0.width + 1, sz.height - winSize0.height + 1); CvRect equRect = { icv_object_win_border, icv_object_win_border, winSize0.width - icv_object_win_border*2, @@ -1656,8 +1656,8 @@ cvHaarDetectObjectsForROC( const CvArr* _img, for( ; n_factors-- > 0; factor *= scaleFactor ) { const double ystep = std::max( 2., factor ); - CvSize winSize = { cvRound( cascade->orig_window_size.width * factor ), - cvRound( cascade->orig_window_size.height * factor )}; + CvSize winSize(cvRound( cascade->orig_window_size.width * factor ), + cvRound( cascade->orig_window_size.height * factor )); CvRect equRect = { 0, 0, 0, 0 }; int *p[4] = {0,0,0,0}; int *pq[4] = {0,0,0,0};