From 62adc019809e311f1b22363eaaf96ab4bf571027 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Tue, 26 Mar 2013 20:43:27 +0400 Subject: [PATCH] Move cv::Rect_ --- modules/core/include/opencv2/core.hpp | 52 ------------------------ modules/core/include/opencv2/core/operations.hpp | 4 -- modules/core/include/opencv2/core/types.hpp | 47 +++++++++++++++++++++ modules/core/include/opencv2/core/types_c.h | 8 ++++ modules/core/src/array.cpp | 2 +- modules/imgproc/src/convhull.cpp | 8 ++-- modules/imgproc/src/shapedescr.cpp | 2 +- modules/legacy/src/oneway.cpp | 2 +- modules/legacy/src/snakes.cpp | 4 +- modules/legacy/test/test_pyrsegmentation.cpp | 2 +- modules/objdetect/src/haar.cpp | 8 ++-- modules/objdetect/src/latentsvmdetector.cpp | 4 +- modules/ts/src/ts_arrtest.cpp | 2 +- 13 files changed, 72 insertions(+), 73 deletions(-) diff --git a/modules/core/include/opencv2/core.hpp b/modules/core/include/opencv2/core.hpp index 0b05f77..638f97d 100644 --- a/modules/core/include/opencv2/core.hpp +++ b/modules/core/include/opencv2/core.hpp @@ -524,58 +524,6 @@ typedef Vec Vec4d; typedef Vec Vec6d; -//////////////////////////////// Rect_ //////////////////////////////// - -/*! - The 2D up-right rectangle class - - The class represents a 2D rectangle with coordinates of the specified data type. - Normally, cv::Rect ~ cv::Rect_ is used. -*/ -template class CV_EXPORTS Rect_ -{ -public: - typedef _Tp value_type; - - //! various constructors - Rect_(); - Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); - Rect_(const Rect_& r); - Rect_(const CvRect& r); - Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); - Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); - - Rect_& operator = ( const Rect_& r ); - //! the top-left corner - Point_<_Tp> tl() const; - //! the bottom-right corner - Point_<_Tp> br() const; - - //! size (width, height) of the rectangle - Size_<_Tp> size() const; - //! area (width*height) of the rectangle - _Tp area() const; - - //! conversion to another data type - template operator Rect_<_Tp2>() const; - //! conversion to the old-style CvRect - operator CvRect() const; - - //! checks whether the rectangle contains the point - bool contains(const Point_<_Tp>& pt) const; - - _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle -}; - - -/*! - \typedef - - shorter aliases for the most popular cv::Point_<>, cv::Size_<> and cv::Rect_<> specializations -*/ -typedef Rect_ Rect; - - /*! The rotated 2D rectangle. diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index 4007a3d..ff36cc1 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -1785,7 +1785,6 @@ template static inline bool operator != (const Size_<_Tp>& a, cons template inline Rect_<_Tp>::Rect_() : x(0), y(0), width(0), height(0) {} template inline Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height) : x(_x), y(_y), width(_width), height(_height) {} template inline Rect_<_Tp>::Rect_(const Rect_<_Tp>& r) : x(r.x), y(r.y), width(r.width), height(r.height) {} -template inline Rect_<_Tp>::Rect_(const CvRect& r) : x((_Tp)r.x), y((_Tp)r.y), width((_Tp)r.width), height((_Tp)r.height) {} template inline Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz) : x(org.x), y(org.y), width(sz.width), height(sz.height) {} template inline Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2) @@ -1836,9 +1835,6 @@ template inline _Tp Rect_<_Tp>::area() const { return width*height template template inline Rect_<_Tp>::operator Rect_<_Tp2>() const { return Rect_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height)); } -template inline Rect_<_Tp>::operator CvRect() const -{ return cvRect(saturate_cast(x), saturate_cast(y), - saturate_cast(width), saturate_cast(height)); } template inline bool Rect_<_Tp>::contains(const Point_<_Tp>& pt) const { return x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height; } diff --git a/modules/core/include/opencv2/core/types.hpp b/modules/core/include/opencv2/core/types.hpp index 71857bc..4d4172b 100644 --- a/modules/core/include/opencv2/core/types.hpp +++ b/modules/core/include/opencv2/core/types.hpp @@ -284,6 +284,53 @@ typedef Size_ Size2i; typedef Size_ Size2f; typedef Size2i Size; + + +//////////////////////////////// Rect_ //////////////////////////////// + +/*! + The 2D up-right rectangle class + + The class represents a 2D rectangle with coordinates of the specified data type. + Normally, cv::Rect ~ cv::Rect_ is used. +*/ +template class CV_EXPORTS Rect_ +{ +public: + typedef _Tp value_type; + + //! various constructors + Rect_(); + Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height); + Rect_(const Rect_& r); + Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz); + Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2); + + Rect_& operator = ( const Rect_& r ); + //! the top-left corner + Point_<_Tp> tl() const; + //! the bottom-right corner + Point_<_Tp> br() const; + + //! size (width, height) of the rectangle + Size_<_Tp> size() const; + //! area (width*height) of the rectangle + _Tp area() const; + + //! conversion to another data type + template operator Rect_<_Tp2>() const; + + //! checks whether the rectangle contains the point + bool contains(const Point_<_Tp>& pt) const; + + _Tp x, y, width, height; //< the top-left corner, as well as width and height of the rectangle +}; + +/*! + \typedef +*/ +typedef Rect_ Rect; + } // 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 609dd23..4e15653 100644 --- a/modules/core/include/opencv2/core/types_c.h +++ b/modules/core/include/opencv2/core/types_c.h @@ -685,6 +685,14 @@ typedef struct CvRect int y; int width; int height; + +#ifdef __cplusplus + CvRect(int _x = 0, int _y = 0, int w = 0, int h = 0): x(_x), y(_y), width(w), height(h) {} + template + CvRect(const cv::Rect_<_Tp>& r): x(cv::saturate_cast(r.x)), y(cv::saturate_cast(r.y)), width(cv::saturate_cast(r.width)), height(cv::saturate_cast(r.height)) {} + template + operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); } +#endif } CvRect; diff --git a/modules/core/src/array.cpp b/modules/core/src/array.cpp index f4e3f3a..cf4f202 100644 --- a/modules/core/src/array.cpp +++ b/modules/core/src/array.cpp @@ -3052,7 +3052,7 @@ cvResetImageROI( IplImage* image ) CV_IMPL CvRect cvGetImageROI( const IplImage* img ) { - CvRect rect = { 0, 0, 0, 0 }; + CvRect rect; if( !img ) CV_Error( CV_StsNullPtr, "Null pointer to image" ); diff --git a/modules/imgproc/src/convhull.cpp b/modules/imgproc/src/convhull.cpp index 019c996..b9e1ca0 100644 --- a/modules/imgproc/src/convhull.cpp +++ b/modules/imgproc/src/convhull.cpp @@ -400,7 +400,7 @@ cvConvexHull2( const CvArr* array, void* hull_storage, CvMat* mat = 0; CvContour contour_header; - union { CvContour c; CvSeq s; } hull_header; + CvSeq hull_header; CvSeqBlock block, hullblock; CvSeq* ptseq = 0; CvSeq* hullseq = 0; @@ -456,7 +456,7 @@ cvConvexHull2( const CvArr* array, void* hull_storage, hullseq = cvMakeSeqHeaderForArray( CV_SEQ_KIND_CURVE|CV_MAT_TYPE(mat->type)|CV_SEQ_FLAG_CLOSED, sizeof(contour_header), CV_ELEM_SIZE(mat->type), mat->data.ptr, - mat->cols + mat->rows - 1, &hull_header.s, &hullblock ); + mat->cols + mat->rows - 1, &hull_header, &hullblock ); cvClearSeq( hullseq ); } @@ -522,7 +522,7 @@ CV_IMPL CvSeq* cvConvexityDefects( const CvArr* array, int rev_orientation; CvContour contour_header; - union { CvContour c; CvSeq s; } hull_header; + CvSeq hull_header; CvSeqBlock block, hullblock; CvSeq *ptseq = (CvSeq*)array, *hull = (CvSeq*)hullarray; @@ -575,7 +575,7 @@ CV_IMPL CvSeq* cvConvexityDefects( const CvArr* array, hull = cvMakeSeqHeaderForArray( CV_SEQ_KIND_CURVE|CV_MAT_TYPE(mat->type)|CV_SEQ_FLAG_CLOSED, sizeof(CvContour), CV_ELEM_SIZE(mat->type), mat->data.ptr, - mat->cols + mat->rows - 1, &hull_header.s, &hullblock ); + mat->cols + mat->rows - 1, &hull_header, &hullblock ); } is_index = CV_SEQ_ELTYPE(hull) == CV_SEQ_ELTYPE_INDEX; diff --git a/modules/imgproc/src/shapedescr.cpp b/modules/imgproc/src/shapedescr.cpp index 93368be..59868a2 100644 --- a/modules/imgproc/src/shapedescr.cpp +++ b/modules/imgproc/src/shapedescr.cpp @@ -1046,7 +1046,7 @@ cvFitEllipse2( const CvArr* array ) CV_IMPL CvRect cvBoundingRect( CvArr* array, int update ) { - CvRect rect = { 0, 0, 0, 0 }; + CvRect rect; CvContour contour_header; CvSeq* ptseq = 0; CvSeqBlock block; diff --git a/modules/legacy/src/oneway.cpp b/modules/legacy/src/oneway.cpp index c7bb513..1c8d4bc 100644 --- a/modules/legacy/src/oneway.cpp +++ b/modules/legacy/src/oneway.cpp @@ -529,7 +529,7 @@ namespace cv{ } return; } - CvRect roi={0,0,0,0}; + CvRect roi; if (!CV_IS_MAT(patch)) { roi = cvGetImageROI((IplImage*)patch); diff --git a/modules/legacy/src/snakes.cpp b/modules/legacy/src/snakes.cpp index 4c1a553..1e17b13 100644 --- a/modules/legacy/src/snakes.cpp +++ b/modules/legacy/src/snakes.cpp @@ -292,8 +292,8 @@ icvSnake8uC1R( unsigned char *src, int leftshift = x ? 1 : 0; int bottomshift = MIN( 1, roi.height - (y + 1)*WTILE_SIZE ); int rightshift = MIN( 1, roi.width - (x + 1)*WTILE_SIZE ); - CvRect g_roi = { x*WTILE_SIZE - leftshift, y*WTILE_SIZE - upshift, - leftshift + WTILE_SIZE + rightshift, upshift + WTILE_SIZE + bottomshift }; + CvRect g_roi(x*WTILE_SIZE - leftshift, y*WTILE_SIZE - upshift, + leftshift + WTILE_SIZE + rightshift, upshift + WTILE_SIZE + bottomshift); CvMat _src1; cvGetSubArr( &_src, &_src1, g_roi ); diff --git a/modules/legacy/test/test_pyrsegmentation.cpp b/modules/legacy/test/test_pyrsegmentation.cpp index e52cc4e..3bd278c 100644 --- a/modules/legacy/test/test_pyrsegmentation.cpp +++ b/modules/legacy/test/test_pyrsegmentation.cpp @@ -71,7 +71,7 @@ void CV_PyrSegmentationTest::run( int /*start_from*/ ) CvPoint* cp = _cp; CvPoint* cp2 = _cp2; CvConnectedComp *dst_comp[3]; - CvRect rect[3] = {{50,50,21,21}, {0,0,128,128}, {33,33,11,11}}; + CvRect rect[3] = {CvRect(50,50,21,21), CvRect(0,0,128,128), CvRect(33,33,11,11)}; double a[3] = {441.0, 15822.0, 121.0}; /* ippiPoint cp3[] ={130,130, 150,130, 150,150, 130,150}; */ diff --git a/modules/objdetect/src/haar.cpp b/modules/objdetect/src/haar.cpp index 23e7287..731e981 100644 --- a/modules/objdetect/src/haar.cpp +++ b/modules/objdetect/src/haar.cpp @@ -1574,9 +1574,9 @@ cvHaarDetectObjectsForROC( const CvArr* _img, 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, + CvRect equRect(icv_object_win_border, icv_object_win_border, winSize0.width - icv_object_win_border*2, - winSize0.height - icv_object_win_border*2 }; + winSize0.height - icv_object_win_border*2); CvMat img1, sum1, sqsum1, norm1, tilted1, mask1; CvMat* _tilted = 0; @@ -1658,7 +1658,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img, const double ystep = std::max( 2., factor ); CvSize winSize(cvRound( cascade->orig_window_size.width * factor ), cvRound( cascade->orig_window_size.height * factor )); - CvRect equRect = { 0, 0, 0, 0 }; + CvRect equRect; int *p[4] = {0,0,0,0}; int *pq[4] = {0,0,0,0}; int startX = 0, startY = 0; @@ -1775,7 +1775,7 @@ cvHaarDetectObjectsForROC( const CvArr* _img, if( findBiggestObject && rectList.size() ) { - CvAvgComp result_comp = {{0,0,0,0},0}; + CvAvgComp result_comp = {CvRect(),0}; for( size_t i = 0; i < rectList.size(); i++ ) { diff --git a/modules/objdetect/src/latentsvmdetector.cpp b/modules/objdetect/src/latentsvmdetector.cpp index f4cabc3..5944333 100644 --- a/modules/objdetect/src/latentsvmdetector.cpp +++ b/modules/objdetect/src/latentsvmdetector.cpp @@ -124,9 +124,9 @@ CvSeq* cvLatentSvmDetectObjects(IplImage* image, for (int i = 0; i < numBoxesOut; i++) { - CvObjectDetection detection = {{0, 0, 0, 0}, 0}; + CvObjectDetection detection = {CvRect(), 0}; detection.score = scoreOut[i]; - CvRect bounding_box = {0, 0, 0, 0}; + CvRect bounding_box; bounding_box.x = pointsOut[i].x; bounding_box.y = pointsOut[i].y; bounding_box.width = oppPointsOut[i].x - pointsOut[i].x; diff --git a/modules/ts/src/ts_arrtest.cpp b/modules/ts/src/ts_arrtest.cpp index ec3f183..03a511c 100644 --- a/modules/ts/src/ts_arrtest.cpp +++ b/modules/ts/src/ts_arrtest.cpp @@ -158,7 +158,7 @@ int ArrayTest::prepare_test_case( int test_case_idx ) unsigned t = randInt(rng); bool create_mask = true, use_roi = false; CvSize size = sizes[i][j], whole_size = size; - CvRect roi = {0,0,0,0}; + CvRect roi; is_image = !cvmat_allowed ? true : iplimage_allowed ? (t & 1) != 0 : false; create_mask = (t & 6) == 0; // ~ each of 3 tests will use mask -- 2.7.4