contour2bbox
- tomni.transformers.contour2bbox(contour: numpy.ndarray) tuple [source]
Convert OpenCV contours into a bounding box format (xmin, ymin, xmax, ymax).
- Parameters
contour (np.ndarray) – An array with coordinates defining the contour of an object.
- Returns
A tuple containing the bounding box coordinates (xmin, ymin, xmax, ymax).
- Return type
tuple
Example:
contour = np.array([[[3, 3]], [[3, 5]], [[5, 5]], [[5, 3]]], dtype=np.int32) bbox = contour2bbox(contour) print(bbox) (3, 3, 6, 6)
Note
The function uses OpenCV’s cv2.boundingRect to compute the bounding box.