template<typename T>
class nndeploy::base::Rect< T >
Template class for 2D rectangles described by the following parameters:
- Coordinates of the top-left corner. This is a default interpretation of Rect::x_ and Rect::y_ in OpenCV. Though, in your algorithms you may count x_ and y_ from the bottom-left corner.
- Rectangle width_ and height_.
OpenCV typically assumes that the top and left boundary of the rectangle are inclusive, while the right and bottom boundaries are not. For example, the method Rect::contains returns true if
Virtually every loop over an image ROI in OpenCV (where ROI is specified by Rect<int> ) is implemented as:
for(
int y_ = roi.y_;
y_ < roi.y_ + roi.height_;
y_++)
for(
int x_ = roi.x_;
x_ < roi.x_ + roi.width_;
x_++)
{
}
T x_
x_ coordinate of the top-left corner
T y_
y_ coordinate of the top-left corner
In addition to the class members, the following operations on rectangles are implemented:
(shifting a rectangle by a certain offset)
(expanding or shrinking a rectangle by a certain amount)
- rect += point, rect -= point, rect += size, rect -= size (augmenting operations)
- rect = rect1 & rect2 (rectangle intersection)
- rect = rect1 | rect2 (minimum area rectangle containing rect1 and rect2 )
- rect &= rect1, rect |= rect1 (and the corresponding augmenting operations)
- rect == rect1, rect != rect1 (rectangle comparison)
This is an example how the partial ordering on rectangles can be established (rect1
rect2):
template<typename T> inline bool
operator <= (const Rect<T>& r1, const Rect<T>& r2)
{
return (r1 & r2) == r1;
}
For your convenience, the Rect<> alias is available: Rect
Definition at line 335 of file type.h.