Package pyvision :: Package types :: Module Rect :: Class Rect
[hide private]
[frames] | no frames]

Class Rect

source code

This is a simple structure that represents a rectangle.

Instance Methods [hide private]
 
__init__(self, x=0.0, y=0.0, w=0.0, h=0.0)
Initialize a rectangle instance.
source code
 
intersect(self, rect)
Compute the intersection of two rectangles.
source code
 
containsRect(self, rect)
Determines if rect is entirely within (contained by) this rectangle.
source code
 
containsPoint(self, point)
Determine if a point is within a rectangle.
source code
 
center(self)
Compute and return a point at the center of the rectangle
source code
 
area(self)
Returns: the area of the rect
source code
 
overlap(self, rect2)
Compute an overlap measure for two detection rectangles.
source code
 
similarity(self, rect)
Compute the similarity of the rectangles in terms of overlap.
source code
 
rescale(self, scale)
Expand or contract the size of the rectangle by a "scale" while keeping the Rect centered at the same location.
source code
 
asInt(self)
Return a dictionary representing the rectangle with integer values
source code
 
__str__(self)
Returns: a string representing this rectangle
source code
 
__repr__(self)
Returns: a string representing this rectangle
source code
 
box(self)
Get this rectangle as a bounding box as expected by many PIL functions.
source code
 
asOpenCV(self)
@returns a representation compatible with opencv.
source code
 
asTuple(self)
@returns a tuple (x,y,w,h).
source code
 
asCenteredTuple(self)
@returns a tuple (cx,cy,w,h).
source code
 
asCorners(self)
Returns the four corners.
source code
 
asPolygon(self)
Returns the four corners with the upper left corner repeated twice.
source code
 
__mul__(self, val)
Multiply the rectangle by a constant.
source code
 
__rmul__(self, val)
Multiply the rectangle by a constant.
source code
 
__div__(self, val)
Divide the rectangle by a constant
source code
Method Details [hide private]

__init__(self, x=0.0, y=0.0, w=0.0, h=0.0)
(Constructor)

source code 

Initialize a rectangle instance.

Arguments:

Parameters:
  • x - top left x coordinate
  • y - top left y coordinate
  • w - width
  • h - height

intersect(self, rect)

source code 

Compute the intersection of two rectangles.

Returns:
a rectangle representing the intersection.

containsRect(self, rect)

source code 

Determines if rect is entirely within (contained by) this rectangle.

Parameters:
  • rect - an object of type pv.Rect
Returns:
True if the rect is entirely within this rectangle's boundaries.

containsPoint(self, point)

source code 

Determine if a point is within a rectangle.

Parameters:
  • point - an object of type pv.Point.
Returns:
True if the point is withen the Rect.

center(self)

source code 

Compute and return a point at the center of the rectangle

Returns:
a pv.Point at the center.

area(self)

source code 
Returns:
the area of the rect

rescale(self, scale)

source code 

Expand or contract the size of the rectangle by a "scale" while keeping the Rect centered at the same location.

Parameters:
  • scale - the scale factor
Returns:
the rescaled rect

__str__(self)
(Informal representation operator)

source code 
Returns:
a string representing this rectangle

__repr__(self)
(Representation operator)

source code 
Returns:
a string representing this rectangle

box(self)

source code 

Get this rectangle as a bounding box as expected by many PIL functions.

Returns:
tuple of (left,top,right,bottom)

asCorners(self)

source code 

Returns the four corners. Can be used to transform this rect through an affine or perspective transformation.

asPolygon(self)

source code 

Returns the four corners with the upper left corner repeated twice. Can be used to transform this rect through an affine or perspective transformations. It can also be plotted with annotatePolygon.