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?
Asked
Active
Viewed 6.8k times
23
-
1Have you seen [THIS DOC](http://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html) – Jeru Luke Feb 25 '17 at 08:44
-
@JeruLuke : Yes, I did went through it several times. But i need more information about how it works in the background. – vashish doolooa Feb 26 '17 at 11:40
1 Answers
28
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 fromfloattointegerformat.- These points are then used to draw the rectangle. This is depicted by the red rectangle in the documentation.
Sabito 錆兎 stands with Ukraine
- 3,250
- 7
- 26
- 49
Jeru Luke
- 16,909
- 11
- 66
- 79
-
1"draw" and "highlight" would be inaccurate, as those funcions only return objects, but don't draw in the image (you can use them to do that with other functions, though). – alx Mar 04 '20 at 10:51
-
I found [this](https://stackoverflow.com/a/54823710/11573842) answer to be useful. You can refer to it. It demonstrates what Jeru describes here. – Sabito 錆兎 stands with Ukraine Sep 27 '20 at 07:46