close

How does cv2.boundingRect() function of OpenCV work?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How does cv2.boundingRect() function of OpenCV work in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How does cv2.boundingRect() function of OpenCV work?

  1. How does cv2.boundingRect() function of OpenCV work?

    The cv2.boundingRect() function of OpenCV is used to draw an approximate rectangle around the binary image. This function is used mainly to highlight the region of interest after obtaining contours from an image.

  2. cv2.boundingRect() function of OpenCV work

    The cv2.boundingRect() function of OpenCV is used to draw an approximate rectangle around the binary image. This function is used mainly to highlight the region of interest after obtaining contours from an image.

Method 1

The cv2.boundingRect() function of OpenCV is used to draw an approximate rectangle around the binary image. This function is used mainly to highlight the region of interest after obtaining contours from an image.

As per the documentation there are two types of bounding rectangles:

Straight Bounding Rectangle
Here a simple rectangle is drawn around the contour (ROI). As you can see in the documentation, a green rectangle is drawn around the ROI. Corresponding rectangle coordinates are obtained such that a rectangle completely encloses the contour.

Rotated Rectangle
In this case cv2.minAreaRect() function is used to highlight the minimum rectangular area enclosing a contour.
cv2.boxPoints() obtains the 4 corner points of the obtained rectangle.
np.int0() is done to convert the corrdinates from float to integer format.
These points are then used to draw the rectangle. This is depicted by the red rectangle in the documentation.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read