Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I need the explanation on boundingRect of OpenCV. I have implemented it, it works great. Is there any reference where this function is fully explained please?

like image 400
vashish doolooa Avatar asked Feb 25 '17 08:02

vashish doolooa


People also ask

How do you make a bounding box in OpenCV?

Working of selectROI() Function in OpenCV The bounding box is an imaginary rectangle drawn around a given object and it serves as the region of interest. To draw a bounding box around an object in the given image, we make use of a function called selectROI() function in OpenCV.


1 Answers

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:

  1. 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.

  1. 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.
like image 71
Jeru Luke Avatar answered Oct 12 '22 14:10

Jeru Luke