diff --git a/dlib/geometry.h b/dlib/geometry.h index 4dd123894..9d326b150 100644 --- a/dlib/geometry.h +++ b/dlib/geometry.h @@ -4,6 +4,7 @@ #define DLIB_GEOMETRy_HEADER #include "geometry/rectangle.h" +#include "geometry/drectangle.h" #include "geometry/vector.h" #include "geometry/border_enumerator.h" #include "geometry/point_transforms.h" diff --git a/dlib/geometry/drectangle.h b/dlib/geometry/drectangle.h new file mode 100644 index 000000000..4af7cced8 --- /dev/null +++ b/dlib/geometry/drectangle.h @@ -0,0 +1,373 @@ +// Copyright (C) 2015 Davis E. King (davis@dlib.net) +// License: Boost Software License See LICENSE.txt for the full license. +#ifndef DLIB_DRECTANGLe_ +#define DLIB_DRECTANGLe_ + +#include "drectangle_abstract.h" +#include "rectangle.h" + +namespace dlib +{ + class drectangle; + drectangle operator* ( + const drectangle& rect, + const double& scale + ); + +// ---------------------------------------------------------------------------------------- + + class drectangle + { + public: + + drectangle ( + ) : l(0), t(0), r(-1), b(-1) {} + + drectangle ( + double l_, + double t_, + double r_, + double b_ + ) : + l(l_), + t(t_), + r(r_), + b(b_) + {} + + drectangle ( + const dlib::vector& p + ) : + l(p.x()), + t(p.y()), + r(p.x()), + b(p.y()) + { + } + + template + drectangle ( + const vector& p1, + const vector& p2 + ) + { + *this = drectangle(p1) + drectangle(p2); + } + + drectangle ( + const rectangle& rect + ) : l(rect.left()), + t(rect.top()), + r(rect.right()), + b(rect.bottom()) {} + + operator rectangle ( + ) const + { + return rectangle((long)std::floor(l+0.5), + (long)std::floor(t+0.5), + (long)std::floor(r+0.5), + (long)std::floor(b+0.5)); + } + + double left() const { return l; } + double top() const { return t; } + double right() const { return r; } + double bottom() const { return b; } + + double& left() { return l; } + double& top() { return t; } + double& right() { return r; } + double& bottom() { return b; } + + const dlib::vector tl_corner ( + ) const { return dlib::vector(left(), top()); } + + const dlib::vector bl_corner ( + ) const { return dlib::vector(left(), bottom()); } + + const dlib::vector tr_corner ( + ) const { return dlib::vector(right(), top()); } + + const dlib::vector br_corner ( + ) const { return dlib::vector(right(), bottom()); } + + double width ( + ) const + { + if (is_empty()) + return 0; + else + return r - l; + } + + double height ( + ) const + { + if (is_empty()) + return 0; + else + return b - t; + } + + double area ( + ) const + { + return width()*height(); + } + + bool is_empty ( + ) const { return (t > b || l > r); } + + drectangle operator + ( + const drectangle& rhs + ) const + { + if (rhs.is_empty()) + return *this; + else if (is_empty()) + return rhs; + + return drectangle ( + std::min(l,rhs.l), + std::min(t,rhs.t), + std::max(r,rhs.r), + std::max(b,rhs.b) + ); + } + + drectangle intersect ( + const drectangle& rhs + ) const + { + return drectangle ( + std::max(l,rhs.l), + std::max(t,rhs.t), + std::min(r,rhs.r), + std::min(b,rhs.b) + ); + } + + bool contains ( + const dlib::vector& p + ) const + { + if (p.x() < l || p.x() > r || p.y() < t || p.y() > b) + return false; + return true; + } + + bool contains ( + const drectangle& rect + ) const + { + if (rect.is_empty()) + return true; + if (l <= rect.left() && + r >= rect.right() && + t <= rect.top() && + b >= rect.bottom()) + return true; + return false; + } + + drectangle& operator *= ( + const double& scale + ) + { + *this = *this*scale; + return *this; + } + + drectangle& operator /= ( + const double& scale + ) + { + *this = *this*(1.0/scale); + return *this; + } + + private: + double l; + double t; + double r; + double b; + }; + +// ---------------------------------------------------------------------------------------- + + inline void serialize ( + const drectangle& item, + std::ostream& out + ) + { + try + { + serialize(item.left(),out); + serialize(item.top(),out); + serialize(item.right(),out); + serialize(item.bottom(),out); + } + catch (serialization_error& e) + { + throw serialization_error(e.info + "\n while serializing an object of type drectangle"); + } + } + + inline void deserialize ( + drectangle& item, + std::istream& in + ) + { + try + { + deserialize(item.left(),in); + deserialize(item.top(),in); + deserialize(item.right(),in); + deserialize(item.bottom(),in); + } + catch (serialization_error& e) + { + throw serialization_error(e.info + "\n while deserializing an object of type drectangle"); + } + } + + inline std::ostream& operator<< ( + std::ostream& out, + const drectangle& item + ) + { + out << "[(" << item.left() << ", " << item.top() << ") (" << item.right() << ", " << item.bottom() << ")]"; + return out; + } + + inline std::istream& operator>>( + std::istream& in, + drectangle& item + ) + { + // ignore any whitespace + while (in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\r' || in.peek() == '\n') + in.get(); + // now eat the leading '[' character + if (in.get() != '[') + { + in.setstate(in.rdstate() | std::ios::failbit); + return in; + } + + dlib::vector p1, p2; + in >> p1; + in >> p2; + item = drectangle(p1) + drectangle(p2); + + // ignore any whitespace + while (in.peek() == ' ' || in.peek() == '\t' || in.peek() == '\r' || in.peek() == '\n') + in.get(); + // now eat the trailing ']' character + if (in.get() != ']') + { + in.setstate(in.rdstate() | std::ios::failbit); + } + return in; + } + +// ---------------------------------------------------------------------------------------- + + inline dlib::vector center ( + const drectangle& rect + ) + { + dlib::vector temp(rect.left() + rect.right(), + rect.top() + rect.bottom()); + + return temp/2.0; + } + + inline dlib::vector dcenter ( + const drectangle& rect + ) + { + return center(rect); + } + + inline drectangle operator* ( + const drectangle& rect, + const double& scale + ) + { + const double width = rect.width()*scale; + const double height = rect.height()*scale; + const dlib::vector p = center(rect); + return drectangle(p.x()-width/2, p.y()-height/2, p.x()+width/2, p.y()+height/2); + } + + inline drectangle operator* ( + const double& scale, + const drectangle& rect + ) + { + return rect*scale; + } + + inline drectangle operator/ ( + const drectangle& rect, + const double& scale + ) + { + return rect*(1.0/scale); + } + + inline drectangle operator+ ( + const drectangle& r, + const dlib::vector& p + ) + { + return r + drectangle(p); + } + + inline drectangle operator+ ( + const dlib::vector& p, + const drectangle& r + ) + { + return r + drectangle(p); + } + + inline drectangle translate_rect ( + const drectangle& rect, + const dlib::vector& p + ) + { + drectangle result; + result.top () = rect.top() + p.y(); + result.bottom () = rect.bottom() + p.y(); + result.left () = rect.left() + p.x(); + result.right () = rect.right() + p.x(); + return result; + } + + inline drectangle intersect ( + const drectangle& a, + const drectangle& b + ) { return a.intersect(b); } + + inline double area ( + const drectangle& a + ) { return a.area(); } + + inline drectangle centered_drect ( + const dlib::vector& p, + const double& width, + const double& height + ) + { + return drectangle(p.x()-width/2, p.y()-height/2, p.x()+width/2, p.y()+height/2); + } + +// ---------------------------------------------------------------------------------------- + +} + +#endif // DLIB_DRECTANGLe_ + diff --git a/dlib/geometry/drectangle_abstract.h b/dlib/geometry/drectangle_abstract.h new file mode 100644 index 000000000..ddf059495 --- /dev/null +++ b/dlib/geometry/drectangle_abstract.h @@ -0,0 +1,498 @@ +// Copyright (C) 2015 Davis E. King (davis@dlib.net) +// License: Boost Software License See LICENSE.txt for the full license. +#undef DLIB_DRECTANGLe_ABSTRACT_H_ +#ifdef DLIB_DRECTANGLe_ABSTRACT_H_ + +#include "rectangle_abstract.h" + +namespace dlib +{ + +// ---------------------------------------------------------------------------------------- + + class drectangle + { + /*! + INITIAL VALUE + The initial value of this object is defined by its constructor. + + WHAT THIS OBJECT REPRESENTS + This object is just like dlib::rectangle except that it stores the + coordinates of the rectangle using double rather than long variables. As + such, this object represents a rectangular region inside a Cartesian + coordinate system. The region is the rectangle with its top left corner at + position (left(),top()) and its bottom right corner at (right(),bottom()). + + Note that the origin of the coordinate system, i.e. (0,0), is located at + the upper left corner. That is, points such as (1,1) or (3,5) represent + locations that are below and to the right of the origin. + + Also note that rectangles where top() > bottom() or left() > right() + represent empty rectangles. + !*/ + public: + + drectangle ( + ); + /*! + ensures + - #left() == 0 + - #top() == 0 + - #right() == -1 + - #bottom() == -1 + - #is_empty() == true + !*/ + + drectangle ( + double left_, + double top_, + double right_, + double bottom_ + ); + /*! + ensures + - #left() == left_ + - #top() == top_ + - #right() == right_ + - #bottom() == bottom_ + !*/ + + drectangle ( + const vector& p + ); + /*! + ensures + - #left() == p.x() + - #top() == p.y() + - #right() == p.x() + - #bottom() == p.y() + !*/ + + template + drectangle ( + const vector& p1, + const vector& p2 + ); + /*! + ensures + - #*this == drectangle(p1) + drectangle(p2) + !*/ + + drectangle ( + const drectangle& rect + ); + /*! + ensures + - #*this represents the same rectangle as rect + !*/ + + drectangle ( + const rectangle& rect + ); + /*! + ensures + - left() == rect.left() + - top() == rect.top() + - right() == rect.right() + - bottom() == rect.bottom() + !*/ + + operator rectangle ( + ) const; + /*! + ensures + - rounds the left, top, right, and bottom coordinates of *this to the + nearest integers and returns the resulting rectangle. + !*/ + + double left ( + ) const; + /*! + ensures + - returns the x coordinate for the left side of this rectangle + !*/ + + double& left ( + ); + /*! + ensures + - returns a non-const reference to the x coordinate for the left side + of this rectangle + !*/ + + double top ( + ) const; + /*! + ensures + - returns the y coordinate for the top of this rectangle + !*/ + + double& top ( + ); + /*! + ensures + - returns a non-const reference to the y coordinate for the + top of this rectangle + !*/ + + double right ( + ) const; + /*! + ensures + - returns the x coordinate for the right side of this rectangle + !*/ + + double& right ( + ); + /*! + ensures + - returns a non-const reference to the x coordinate for the right + side of this rectangle + !*/ + + double bottom ( + ) const; + /*! + ensures + - returns the y coordinate for the bottom of this rectangle + !*/ + + double& bottom ( + ); + /*! + ensures + - returns a non-const reference to the y coordinate for the bottom + of this rectangle + !*/ + + const vector tl_corner ( + ) const; + /*! + ensures + - returns vector(left(), top()) + (i.e. returns the top left corner point for this rectangle) + !*/ + + const vector bl_corner ( + ) const; + /*! + ensures + - returns vector(left(), bottom()) + (i.e. returns the bottom left corner point for this rectangle) + !*/ + + const vector tr_corner ( + ) const; + /*! + ensures + - returns vector(right(), top()) + (i.e. returns the top right corner point for this rectangle) + !*/ + + const vector br_corner ( + ) const; + /*! + ensures + - returns vector(right(), bottom()) + (i.e. returns the bottom right corner point for this rectangle) + !*/ + + double width ( + ) const; + /*! + ensures + - if (is_empty()) then + - returns 0 + - else + - returns the width of this rectangle. + (i.e. right() - left()) + !*/ + + double height ( + ) const; + /*! + ensures + - if (is_empty()) then + - returns 0 + - else + - returns the height of this rectangle. + (i.e. bottom() - top()) + !*/ + + double area ( + ) const; + /*! + ensures + - returns width()*height() + !*/ + + bool is_empty ( + ) const; + /*! + ensures + - if (top() > bottom() || left() > right()) then + - returns true + - else + - returns false + !*/ + + drectangle operator + ( + const drectangle& rhs + ) const; + /*! + ensures + - if (rhs.is_empty() == false && this->is_empty() == false) then + - returns the smallest rectangle that contains both *this and + rhs. + - if (rhs.is_empty() == true && this->is_empty() == false) then + - returns *this + - if (rhs.is_empty() == false && this->is_empty() == true) then + - returns rhs + - if (rhs.is_empty() == true && this->is_empty() == true) then + - returns a rectangle that has is_empty() == true + !*/ + + drectangle intersect ( + const drectangle& rhs + ) const; + /*! + ensures + - if (there is a region of intersection between *this and rhs) then + - returns a rectangle that represents the intersection of *this + and rhs. + - else + - returns a rectangle where is_empty() == true + !*/ + + bool contains ( + const vector& p + ) const; + /*! + ensures + - if (the point (p.x(),p.y()) is contained in this rectangle) then + - returns true + - else + - returns false + !*/ + + bool contains ( + const drectangle& rect + ) const + /*! + ensures + - if (rect + *this == *this) then + - returns true + (i.e. returns true if *this contains the given rectangle) + - else + - returns false + !*/ + + drectangle& operator *= ( + const double& scale + ); + /*! + ensures + - performs: *this = *this*scale; + - returns #*this + !*/ + + drectangle& operator /= ( + const double& scale + ); + /*! + requires + - scale != 0 + ensures + - performs: *this = *this*(1.0/scale); + - returns #*this + !*/ + + }; + +// ---------------------------------------------------------------------------------------- + + void serialize ( + const drectangle& item, + std::ostream& out + ); + /*! + provides serialization support + !*/ + + void deserialize ( + drectangle& item, + std::istream& in + ); + /*! + provides deserialization support + !*/ + +// ---------------------------------------------------------------------------------------- + + std::ostream& operator<< ( + std::ostream& out, + const drectangle& item + ); + /*! + ensures + - writes item to out in the form "[(left, top) (right, bottom)]" + !*/ + +// ---------------------------------------------------------------------------------------- + + std::istream& operator>>( + std::istream& in, + drectangle& item + ); + /*! + ensures + - reads a drectangle from the input stream in and stores it in #item. The data + in the input stream should be of the form [(left, top) (right, bottom)] + !*/ + +// ---------------------------------------------------------------------------------------- + + vector center ( + const drectangle& rect + ); + /*! + ensures + - returns the center of the given rectangle + !*/ + +// ---------------------------------------------------------------------------------------- + + vector dcenter ( + const drectangle& rect + ); + /*! + ensures + - returns the center of the given rectangle. (Both center() and dcenter() are + identical when applied to drectangle objects) + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle operator* ( + const drectangle& rect, + const double& scale + ); + /*! + ensures + - This function returns a rectangle that has the same center as rect but with a + width and height that are scale times larger. That is, we return a new + rectangle R such that: + - center(R) == center(rect) + - R.width() == rect.width()*scale + - R.height() == rect.height()*scale + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle operator* ( + const double& scale, + const drectangle& rect + ); + /*! + ensures + - returns rect*scale + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle operator/ ( + const drectangle& rect, + const double& scale + ); + /*! + ensures + - returns rect*(1.0/scale) + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle operator+ ( + const drectangle& r, + const vector& p + ); + /*! + ensures + - returns r + drectangle(p) + (i.e. returns the rectangle that contains both r and p) + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle operator+ ( + const vector& p, + const drectangle& r + ); + /*! + ensures + - returns r + drectangle(p) + (i.e. returns the rectangle that contains both r and p) + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle translate_rect ( + const drectangle& rect, + const vector& p + ); + /*! + ensures + - returns a rectangle R such that: + - R.left() == rect.left() + p.x() + - R.right() == rect.right() + p.x() + - R.top() == rect.top() + p.y() + - R.bottom() == rect.bottom() + p.y() + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle intersect ( + const drectangle& a, + const drectangle& b + ); + /*! + ensures + - returns a.intersect(b) + (i.e. returns a rectangle representing the intersection of a and b) + !*/ + +// ---------------------------------------------------------------------------------------- + + double area ( + const drectangle& a + ); + /*! + ensures + - returns a.area() + !*/ + +// ---------------------------------------------------------------------------------------- + + drectangle centered_drect ( + const vector& p, + const double& width, + const double& height + ); + /*! + ensures + - returns a rectangle R such that: + - center(R) == p + - if (width == 0 || height == 0) + - R.width() == 0 + - R.height() == 0 + - else + - R.width() == width + - R.height() == height + - R.tl_corner() == point(p.x()-width/2, p.y()-height/2) + !*/ + +// ---------------------------------------------------------------------------------------- + +} + +#endif // DLIB_DRECTANGLe_ABSTRACT_H_ + diff --git a/dlib/image_transforms/image_pyramid.h b/dlib/image_transforms/image_pyramid.h index a3248317a..807432cb3 100644 --- a/dlib/image_transforms/image_pyramid.h +++ b/dlib/image_transforms/image_pyramid.h @@ -62,36 +62,36 @@ namespace dlib // ----------------------------- - rectangle rect_up ( - const rectangle& rect + drectangle rect_up ( + const drectangle& rect ) const { - return rectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); + return drectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); } - rectangle rect_up ( - const rectangle& rect, + drectangle rect_up ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); + return drectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); } // ----------------------------- - rectangle rect_down ( - const rectangle& rect + drectangle rect_down ( + const drectangle& rect ) const { - return rectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); + return drectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); } - rectangle rect_down ( - const rectangle& rect, + drectangle rect_down ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); + return drectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); } // ----------------------------- @@ -196,36 +196,36 @@ namespace dlib // ----------------------------- - rectangle rect_up ( - const rectangle& rect + drectangle rect_up ( + const drectangle& rect ) const { - return rectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); + return drectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); } - rectangle rect_up ( - const rectangle& rect, + drectangle rect_up ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); + return drectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); } // ----------------------------- - rectangle rect_down ( - const rectangle& rect + drectangle rect_down ( + const drectangle& rect ) const { - return rectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); + return drectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); } - rectangle rect_down ( - const rectangle& rect, + drectangle rect_down ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); + return drectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); } // ----------------------------- @@ -538,36 +538,36 @@ namespace dlib // ----------------------------- - rectangle rect_up ( - const rectangle& rect + drectangle rect_up ( + const drectangle& rect ) const { - return rectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); + return drectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); } - rectangle rect_up ( - const rectangle& rect, + drectangle rect_up ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); + return drectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); } // ----------------------------- - rectangle rect_down ( - const rectangle& rect + drectangle rect_down ( + const drectangle& rect ) const { - return rectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); + return drectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); } - rectangle rect_down ( - const rectangle& rect, + drectangle rect_down ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); + return drectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); } // ----------------------------- @@ -889,36 +889,36 @@ namespace dlib // ----------------------------- - rectangle rect_up ( - const rectangle& rect + drectangle rect_up ( + const drectangle& rect ) const { - return rectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); + return drectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); } - rectangle rect_up ( - const rectangle& rect, + drectangle rect_up ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); + return drectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); } // ----------------------------- - rectangle rect_down ( - const rectangle& rect + drectangle rect_down ( + const drectangle& rect ) const { - return rectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); + return drectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); } - rectangle rect_down ( - const rectangle& rect, + drectangle rect_down ( + const drectangle& rect, unsigned int levels ) const { - return rectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); + return drectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); } template < diff --git a/dlib/image_transforms/image_pyramid_abstract.h b/dlib/image_transforms/image_pyramid_abstract.h index 8df393a4a..f11dd619d 100644 --- a/dlib/image_transforms/image_pyramid_abstract.h +++ b/dlib/image_transforms/image_pyramid_abstract.h @@ -109,21 +109,21 @@ namespace dlib point_up(point_down(P)) == P !*/ - rectangle rect_down ( - const rectangle& rect + drectangle rect_down ( + const drectangle& rect ) const; /*! ensures - - returns rectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); + - returns drectangle(point_down(rect.tl_corner()), point_down(rect.br_corner())); (i.e. maps rect into a downsampled) !*/ - rectangle rect_up ( - const rectangle& rect + drectangle rect_up ( + const drectangle& rect ) const; /*! ensures - - returns rectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); + - returns drectangle(point_up(rect.tl_corner()), point_up(rect.br_corner())); (i.e. maps rect into a parent image) !*/ @@ -155,23 +155,23 @@ namespace dlib point_up(p,0) == p, etc. ) !*/ - rectangle rect_down ( - const rectangle& rect, + drectangle rect_down ( + const drectangle& rect, unsigned int levels ) const; /*! ensures - - returns rectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); + - returns drectangle(point_down(rect.tl_corner(),levels), point_down(rect.br_corner(),levels)); (i.e. Basically applies rect_down() to rect levels times and returns the result.) !*/ - rectangle rect_up ( - const rectangle& rect, + drectangle rect_up ( + const drectangle& rect, unsigned int levels ) const; /*! ensures - - returns rectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); + - returns drectangle(point_up(rect.tl_corner(),levels), point_up(rect.br_corner(),levels)); (i.e. Basically applies rect_up() to rect levels times and returns the result.) !*/ diff --git a/dlib/image_transforms/interpolation.h b/dlib/image_transforms/interpolation.h index 083d1daac..fb44dcfaf 100644 --- a/dlib/image_transforms/interpolation.h +++ b/dlib/image_transforms/interpolation.h @@ -1426,15 +1426,15 @@ namespace dlib struct chip_details { chip_details() : angle(0), rows(0), cols(0) {} - chip_details(const rectangle& rect_) : rect(rect_),angle(0), rows(rect_.height()), cols(rect_.width()) {} - chip_details(const rectangle& rect_, unsigned long size) : rect(rect_),angle(0) + chip_details(const drectangle& rect_) : rect(rect_),angle(0), rows(rect_.height()), cols(rect_.width()) {} + chip_details(const drectangle& rect_, unsigned long size) : rect(rect_),angle(0) { compute_dims_from_size(size); } - chip_details(const rectangle& rect_, unsigned long size, double angle_) : rect(rect_),angle(angle_) + chip_details(const drectangle& rect_, unsigned long size, double angle_) : rect(rect_),angle(angle_) { compute_dims_from_size(size); } - chip_details(const rectangle& rect_, const chip_dims& dims) : + chip_details(const drectangle& rect_, const chip_dims& dims) : rect(rect_),angle(0),rows(dims.rows), cols(dims.cols) {} - chip_details(const rectangle& rect_, const chip_dims& dims, double angle_) : + chip_details(const drectangle& rect_, const chip_dims& dims, double angle_) : rect(rect_),angle(angle_),rows(dims.rows), cols(dims.cols) {} template @@ -1463,13 +1463,13 @@ namespace dlib // Note that the translation and scale part are represented by the extraction // rectangle. So here we build the appropriate rectangle. const double scale = length(p); - rect = centered_rect(tform(point(dims.cols,dims.rows)/2.0), - static_cast(dims.cols*scale + 0.5), - static_cast(dims.rows*scale + 0.5)); + rect = centered_drect(tform(point(dims.cols,dims.rows)/2.0), + dims.cols*scale, + dims.rows*scale); } - rectangle rect; + drectangle rect; double angle; unsigned long rows; unsigned long cols; @@ -1611,7 +1611,7 @@ namespace dlib for (unsigned long i = 0; i < chip_locations.size(); ++i) { long depth = 0; - rectangle rect = pyr.rect_down(chip_locations[i].rect); + drectangle rect = pyr.rect_down(chip_locations[i].rect); while (rect.area() > chip_locations[i].size()) { rect = pyr.rect_down(rect); @@ -1647,7 +1647,7 @@ namespace dlib // figure out which level in the pyramid to use to extract the chip int level = -1; - rectangle rect = chip_locations[i].rect; + drectangle rect = chip_locations[i].rect; while (pyr.rect_down(rect).area() > chip_locations[i].size()) { ++level; diff --git a/dlib/image_transforms/interpolation_abstract.h b/dlib/image_transforms/interpolation_abstract.h index 176ebeac4..3cd3e4005 100644 --- a/dlib/image_transforms/interpolation_abstract.h +++ b/dlib/image_transforms/interpolation_abstract.h @@ -923,7 +923,7 @@ namespace dlib !*/ chip_details( - const rectangle& rect_ + const drectangle& rect_ ); /*! ensures @@ -935,7 +935,7 @@ namespace dlib !*/ chip_details( - const rectangle& rect_, + const drectangle& rect_, unsigned long size_ ); /*! @@ -956,7 +956,7 @@ namespace dlib !*/ chip_details( - const rectangle& rect_, + const drectangle& rect_, unsigned long size_, double angle_ ); @@ -978,7 +978,7 @@ namespace dlib !*/ chip_details( - const rectangle& rect_, + const drectangle& rect_, const chip_dims& dims ); /*! @@ -991,7 +991,7 @@ namespace dlib !*/ chip_details( - const rectangle& rect_, + const drectangle& rect_, const chip_dims& dims, double angle_ ); @@ -1034,7 +1034,7 @@ namespace dlib - returns the number of pixels in this chip. This is just rows*cols. !*/ - rectangle rect; + drectangle rect; double angle; unsigned long rows; unsigned long cols;