Move cv::Rect_
authorAndrey Kamaev <andrey.kamaev@itseez.com>
Tue, 26 Mar 2013 16:43:27 +0000 (20:43 +0400)
committerAndrey Kamaev <andrey.kamaev@itseez.com>
Mon, 1 Apr 2013 11:24:33 +0000 (15:24 +0400)
13 files changed:
modules/core/include/opencv2/core.hpp
modules/core/include/opencv2/core/operations.hpp
modules/core/include/opencv2/core/types.hpp
modules/core/include/opencv2/core/types_c.h
modules/core/src/array.cpp
modules/imgproc/src/convhull.cpp
modules/imgproc/src/shapedescr.cpp
modules/legacy/src/oneway.cpp
modules/legacy/src/snakes.cpp
modules/legacy/test/test_pyrsegmentation.cpp
modules/objdetect/src/haar.cpp
modules/objdetect/src/latentsvmdetector.cpp
modules/ts/src/ts_arrtest.cpp

index 0b05f77..638f97d 100644 (file)
@@ -524,58 +524,6 @@ typedef Vec<double, 4> Vec4d;
 typedef Vec<double, 6> 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_<int> is used.
-*/
-template<typename _Tp> 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<typename _Tp2> 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_<int> Rect;
-
-
 /*!
   The rotated 2D rectangle.
 
index 4007a3d..ff36cc1 100644 (file)
@@ -1785,7 +1785,6 @@ template<typename _Tp> static inline bool operator != (const Size_<_Tp>& a, cons
 template<typename _Tp> inline Rect_<_Tp>::Rect_() : x(0), y(0), width(0), height(0) {}
 template<typename _Tp> inline Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height) : x(_x), y(_y), width(_width), height(_height) {}
 template<typename _Tp> inline Rect_<_Tp>::Rect_(const Rect_<_Tp>& r) : x(r.x), y(r.y), width(r.width), height(r.height) {}
-template<typename _Tp> inline Rect_<_Tp>::Rect_(const CvRect& r) : x((_Tp)r.x), y((_Tp)r.y), width((_Tp)r.width), height((_Tp)r.height) {}
 template<typename _Tp> 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<typename _Tp> inline Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2)
@@ -1836,9 +1835,6 @@ template<typename _Tp> inline _Tp Rect_<_Tp>::area() const { return width*height
 template<typename _Tp> template<typename _Tp2> 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<typename _Tp> inline Rect_<_Tp>::operator CvRect() const
-{ return cvRect(saturate_cast<int>(x), saturate_cast<int>(y),
-                saturate_cast<int>(width), saturate_cast<int>(height)); }
 
 template<typename _Tp> 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; }
index 71857bc..4d4172b 100644 (file)
@@ -284,6 +284,53 @@ typedef Size_<int> Size2i;
 typedef Size_<float> 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_<int> is used.
+*/
+template<typename _Tp> 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<typename _Tp2> 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_<int> Rect;
+
 } // cv
 
 #endif //__OPENCV_CORE_TYPES_HPP__
\ No newline at end of file
index 609dd23..4e15653 100644 (file)
@@ -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<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)) {}
+    template<typename _Tp>
+    operator cv::Rect_<_Tp>() const { return cv::Rect_<_Tp>((_Tp)x, (_Tp)y, (_Tp)width, (_Tp)height); }
+#endif
 }
 CvRect;
 
index f4e3f3a..cf4f202 100644 (file)
@@ -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" );
 
index 019c996..b9e1ca0 100644 (file)
@@ -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;
index 93368be..59868a2 100644 (file)
@@ -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;
index c7bb513..1c8d4bc 100644 (file)
@@ -529,7 +529,7 @@ namespace cv{
             }
             return;
         }
-        CvRect roi={0,0,0,0};
+        CvRect roi;
         if (!CV_IS_MAT(patch))
         {
             roi = cvGetImageROI((IplImage*)patch);
index 4c1a553..1e17b13 100644 (file)
@@ -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 );
 
index e52cc4e..3bd278c 100644 (file)
@@ -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};  */
index 23e7287..731e981 100644 (file)
@@ -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++ )
         {
index f4cabc3..5944333 100644 (file)
@@ -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;
index ec3f183..03a511c 100644 (file)
@@ -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