cv.Rect/Rect - MATLAB File Help |
Class for 2D rectangles
A rectangle [x,y,w,h]
is described by the following parameters:
[x,y]
in OpenCV. Though, in your algorithms you may count x
and
y
from the bottom-left corner.[w h]
.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 cv.Rect.contains returns true if:
x <= pt.x < x + width , y <= pt.y < y + height
Virtually every loop over an image ROI in OpenCV (where ROI is specified by an integer rectangle) is implemented as:
roi = [x,y,w,h];
for y=roi(2):(roi(2)+roi(4)-1)
for x=roi(1):(roi(1)+roi(3)-1)
%...
end
end
In addition, the following operations on rectangles are implemented:
rect += point
): shifting a rectangle by a
certain offset.rect += size
): expanding or shrinking a rectangle by
a certain amount.rect1 & rect2
): rectangle intersection.rect1 | rect2
): minimum area rectangle containing rect1
and rect2
.This is an example how the partial ordering on rectangles can be
established (rect1 \subseteq rect2
):
function b = rect_le(r1, r2)
b = all(cv.Rect.intersect(r1,r2) == r1);
end