3.1.3 Rect_ 클래스

    OpenCV에서 사각형의 위치와 크기 정보를 표현할 때에는 Rect_ 클래스를 사용합니다. Rect_ 클래스는 사각형의 좌측 상단 점의 좌표를 나타내는 x, y 멤버 변수와 사각형의 가로 및 세로 크기를 나타내는 width, height 멤버 변수를 가지고 있습니다. 간략화한 Rect_ 클래스 정의를 코드 3-3에 나타냈습니다.

    코드 3-3 간략화한 Rect_ 클래스 정의와 이름 재정의

    01    template<typename _Tp> class Rect_
    02    {
    03    public:
    04        Rect_();
    05        Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
    06        Rect_(const Rect_& r);
    07        Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
    08        Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
    09     
    10        Rect_& operator = ( const Rect_& r );
    11     
    12        Point_<_Tp> tl() const;
    13        Point_<_Tp> br() const;
    14        Size_<_Tp> size() const;
    15        _Tp area() const;
    16        bool empty() const;
    17        bool contains(const Point_<_Tp>& pt) const;
    18     
    19        _Tp x, y, width, height;
    20    };
    21     
    22    typedef Rect_<int>    Rect2i;
    23    typedef Rect_<float>  Rect2f;
    24    typedef Rect_<double> Rect2d;
    25    typedef Rect2i        Rect;

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.