cv.Rect/Rect - MATLAB File Help
cv.Rect/Rect

Class for 2D rectangles

A rectangle [x,y,w,h] is described by the following parameters:

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:

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
See also