itcoder
itcoder

Reputation: 125

OpenCV Bounding Rectangle (Python)

I'm trying to write a report on my Computer Vision project that uses OpenCV's (Python) boundingRect function. However, I am not allowed to say that I used this function, but rather the algorithm/equation that this function uses. I have tried to find this online, but am not particularly good at identifying what it is I'm looking for. Would someone be able to suggest which algorithm the boundingRect equation uses? Thanks

Utilised by: cv2.boundingRect(contour).

Upvotes: 0

Views: 1546

Answers (1)

fmw42
fmw42

Reputation: 53081

In Python/OpenCV, the axes aligned bounding rectangle is defined as X,Y,W,H, where X,Y are the coordinates of the minimum X,Y corner and W,H are the width and height of the box. Those values are found by testing every point (x,y) on the contour to find (the minimum and maximum of x and y each) minX, maxX, minY, maxY. The bounding rectangle values are then X=minX, Y=minY, W=(maxX-minX), H=(maxY-minY). You find the min and max values by looping over each x (or y) and testing it against the previous min or max value. If the current value is lower or higher, respectively, replace the old min or max with the current value.

In other systems, the bounding box is defined by the minimum and maximum diagonally opposite corners (minX,minY) and (maxX,maxY)

Upvotes: 2

Related Questions