Object Detection utilites
Kano aims to support visualization and extract bounding boxes without the need to handle various box formats, such as xyxy, xywh, or scaled xywh:
xywh2xyxy
: convert box with xywh format (x_center, y_center, width, height - which is model input/output format) to xyxy format(x_min, y_min, x_max, y_max - which used to draw boxes).extract_bbox_area
: get cropped box image from the imagedraw_bbox
: draw bounding box on the image.
kano.detect_utils.xywh2xyxy(xywh)
Converts bounding box coordinates from (x_center, y_center, width, height) format to (x_min, y_min, x_max, y_max) format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
xywh |
np.array) with shape (4,
|
A tuple containing (x_center, y_center, width, height) of the bounding box. |
required |
Returns:
Name | Type | Description |
---|---|---|
xyxy |
tuple(int)
|
xyxy location of the bounding box. |
Source code in kano\detect_utils.py
kano.detect_utils.extract_bbox_area(image, bbox)
Return cropped image from the given bounding box area
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
np.array) with shape (H, W, 3
|
image to extract the box |
required |
bbox |
np.array) with shape (4,
|
xyxy location of the box |
required |
Returns:
Name | Type | Description |
---|---|---|
cropped_image |
array
|
with shape (new_H, new_W, 3) based on bbox |
Source code in kano\detect_utils.py
kano.detect_utils.draw_bbox(image, bbox, bbox_type='xyxy', bbox_color=(0, 0, 255), label=None)
Draws a bounding box on the image and optionally draws a multi-line label.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
image |
ndarray or str
|
The image on which the bounding box will be drawn. |
required |
bbox |
list or tuple or ndarray
|
The bounding box coordinates. If it's a list, it should be in the format specified by bbox_type. |
required |
bbox_type |
str
|
Type of bounding box coordinates. Should be either "xyxy" or "xywh" or "s_xywh". |
'xyxy'
|
bbox_color |
tuple
|
Color of the bounding box in BGR format. |
(0, 0, 255)
|
label |
str
|
Label to be displayed alongside the bounding box. Supports multiple lines with '/n' separating lines. |
None
|
Returns:
Type | Description |
---|---|
ndarray
|
np.ndarray: Image with the bounding box and label drawn. |
Source code in kano\detect_utils.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|