Bounding box, minimum area rectangle, and minimum enclosing circle

Finding the contours of a square is a simple task; irregular, skewed, and rotated shapes bring out the full potential of OpenCV's cv2.findContours function. Let's take a look at the following image:

In a real-life application, we would be most interested in determining the bounding box of the subject, its minimum enclosing rectangle, and its enclosing circle. The cv2.findContours function, in conjunction with a few other OpenCV utilities, makes this very easy to accomplish. First, the following code reads an image from a file, converts it into grayscale, applies a threshold ...

Get Learning OpenCV 4 Computer Vision with Python 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.