Skip to content

Commit

Permalink
add_bounding_box ==> add
Browse files Browse the repository at this point in the history
  • Loading branch information
nalepae committed Jun 16, 2019
1 parent 2dbc431 commit 1f4e5d5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 46 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ from bounding_box import bounding_box as bb

Then, just add the bounding box on an image.
```python
bb.add_bounding_box(image, left, top, right, bottom, label, color)
bb.add(image, left, top, right, bottom, label, color)
```

This method takes 5 mandatory parameters:
- `image`: A numpy array, channel last (ie. height x width x colors) with
channels in **BGR** order (same as **openCV** format).
- `left`: A integer representing the left side of the bounding box.
- `top`: A integer representing the top side of the bounding box.
- `right`: A integer representing the right side of the bounding box.
- `bottom`: A integer representing the bottom side of the bounding box.

This method takes also 2 optional parameters:
- `label`: A string representing the label of the bounding box.
If not specified, then no label is displayed.
Expand All @@ -70,7 +70,7 @@ If neither `color` and `label` is specified then the bounding box
color is defaulted to `green`.

## Examples
The script to plot exemples of this **README** is available
The script to plot exemples of this **README** is available
[here](https://github.com/nalepae/bounding-box/blob/master/docs/examples.py).

To run it, go in top level of this git repository then write:
Expand All @@ -79,4 +79,3 @@ python docs/examples.py
```

If you run `examples.py` in an other directory it won't work.

2 changes: 1 addition & 1 deletion bounding_box/bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _get_label_image(text, font_color_tuple_bgr, background_color_tuple_bgr):

return np.concatenate(image).transpose(1, 2, 0)

def add_bounding_box(image, left, top, right, bottom, label=None, color=None):
def add(image, left, top, right, bottom, label=None, color=None):
if type(image) is not _np.ndarray:
raise TypeError("'image' parameter must be a numpy.ndarray")
try:
Expand Down
80 changes: 40 additions & 40 deletions docs/examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,81 +16,81 @@ def main():
in_path = os.path.join("docs", "images", "winton.jpg")
out_path = os.path.join("docs", "images", "winton_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 281, 12, 744, 431, "Winton", "maroon")
bb.add_bounding_box(image, 166, 149, 500, 297, "Trumpet", "yellow")
bb.add(image, 281, 12, 744, 431, "Winton", "maroon")
bb.add(image, 166, 149, 500, 297, "Trumpet", "yellow")
show_and_save("Winton MARSALIS", image, out_path)

in_path = os.path.join("docs", "images", "khatia.jpg")
out_path = os.path.join("docs", "images", "khatia_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 280, 24, 802, 593, "Khatia", "maroon")
bb.add_bounding_box(image, 687, 1, 1448, 648, "Piano", "gray")
bb.add_bounding_box(image, 888, 492, 1190, 536, "Text")
bb.add(image, 280, 24, 802, 593, "Khatia", "maroon")
bb.add(image, 687, 1, 1448, 648, "Piano", "gray")
bb.add(image, 888, 492, 1190, 536, "Text")
show_and_save("Khatia BUNIATISHVILI", image, out_path)

in_path = os.path.join("docs", "images", "clarifloue.jpg")
out_path = os.path.join("docs", "images", "clarifloue_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 69, 86, 470, 136, label="Headache designer")
bb.add_bounding_box(image, 136, 196, 406, 234, "Text")
bb.add_bounding_box(image, 67, 351, 471, 400, "Headache designer")
bb.add_bounding_box(image, 130, 456, 390, 494, "Text")
bb.add(image, 69, 86, 470, 136, label="Headache designer")
bb.add(image, 136, 196, 406, 234, "Text")
bb.add(image, 67, 351, 471, 400, "Headache designer")
bb.add(image, 130, 456, 390, 494, "Text")
show_and_save("Clarinet", image, out_path)

in_path = os.path.join("docs", "images", "nao-romeo-pepper.jpg")
out_path = os.path.join("docs", "images", "nao-romeo-pepper_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 155, 152, 244, 297, "Nao")
bb.add_bounding_box(image, 260, 6, 423, 416, "Romeo")
bb.add_bounding_box(image, 421, 76, 547, 402, "Pepper")
bb.add(image, 155, 152, 244, 297, "Nao")
bb.add(image, 260, 6, 423, 416, "Romeo")
bb.add(image, 421, 76, 547, 402, "Pepper")
show_and_save("Robots", image, out_path)

in_path = os.path.join("docs", "images", "ski-paraglider.jpg")
out_path = os.path.join("docs", "images", "ski-paraglider_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 0, 128, 645, 589, "Paraglider", "orange")
bb.add_bounding_box(image, 689, 442, 818, 566, "Skier", "gray")
bb.add(image, 0, 128, 645, 589, "Paraglider", "orange")
bb.add(image, 689, 442, 818, 566, "Skier", "gray")
show_and_save("Ski and paraglider", image, out_path)

in_path = os.path.join("docs", "images", "paragliders.jpg")
out_path = os.path.join("docs", "images", "paragliders_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 90, 228, 318, 428, "Paraglider")
bb.add_bounding_box(image, 521, 110, 656, 415, "Paraglider")
bb.add(image, 90, 228, 318, 428, "Paraglider")
bb.add(image, 521, 110, 656, 415, "Paraglider")
show_and_save("Pretty Bounding Box", image, out_path)

in_path = os.path.join("docs", "images", "selfie.jpg")
out_path = os.path.join("docs", "images", "selfie_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 5, 7, 150, 169, "Female", "fuchsia")
bb.add_bounding_box(image, 116, 7, 193, 113, "Male", "blue")
bb.add_bounding_box(image, 189, 7, 291, 124, "Female", "fuchsia")
bb.add_bounding_box(image, 288, 25, 355, 114, "Male", "blue")
bb.add_bounding_box(image, 367, 0, 448, 92, "Male", "blue")
bb.add_bounding_box(image, 435, 29, 506, 104, "Female", "fuchsia")
bb.add_bounding_box(image, 497, 3, 597, 111, "Female", "fuchsia")
bb.add_bounding_box(image, 110, 133, 213, 245, "Female", "fuchsia")
bb.add_bounding_box(image, 176, 120, 293, 289, "Female", "fuchsia")
bb.add_bounding_box(image, 314, 115, 470, 357, "Male", "blue")
bb.add_bounding_box(image, 468, 72, 577, 226, "Male", "blue")
bb.add(image, 5, 7, 150, 169, "Female", "fuchsia")
bb.add(image, 116, 7, 193, 113, "Male", "blue")
bb.add(image, 189, 7, 291, 124, "Female", "fuchsia")
bb.add(image, 288, 25, 355, 114, "Male", "blue")
bb.add(image, 367, 0, 448, 92, "Male", "blue")
bb.add(image, 435, 29, 506, 104, "Female", "fuchsia")
bb.add(image, 497, 3, 597, 111, "Female", "fuchsia")
bb.add(image, 110, 133, 213, 245, "Female", "fuchsia")
bb.add(image, 176, 120, 293, 289, "Female", "fuchsia")
bb.add(image, 314, 115, 470, 357, "Male", "blue")
bb.add(image, 468, 72, 577, 226, "Male", "blue")
show_and_save("The Selfie", image, out_path)

in_path = os.path.join("docs", "images", "pobb.jpg")
out_path = os.path.join("docs", "images", "pobb_bb.png")
image = cv2.imread(in_path, cv2.IMREAD_COLOR)
bb.add_bounding_box(image, 76, 62, 155, 271, "Female", "fuchsia")
bb.add_bounding_box(image, 157, 44, 288, 274, "Male", "blue")
bb.add_bounding_box(image, 224, 64, 317, 274, "Male", "blue")
bb.add_bounding_box(image, 290, 48, 383, 277, "Male", "blue")
bb.add_bounding_box(image, 350, 42, 458, 276, "Female", "fuchsia")
bb.add_bounding_box(image, 416, 17, 510, 279, "Male", "blue")
bb.add_bounding_box(image, 482, 55, 573, 278, "Female", "fuchsia")
bb.add_bounding_box(image, 547, 63, 615, 277, "Female", "fuchsia")
bb.add_bounding_box(image, 608, 49, 704, 275, "Female", "fuchsia")
bb.add_bounding_box(image, 672, 34, 767, 274, "Male", "blue")
bb.add_bounding_box(image, 725, 62, 813, 273, "Female", "fuchsia")
bb.add_bounding_box(image, 786, 38, 887, 267, "Male", "blue")
bb.add_bounding_box(image, 864, 51, 959, 266, "Male", "blue")
bb.add(image, 76, 62, 155, 271, "Female", "fuchsia")
bb.add(image, 157, 44, 288, 274, "Male", "blue")
bb.add(image, 224, 64, 317, 274, "Male", "blue")
bb.add(image, 290, 48, 383, 277, "Male", "blue")
bb.add(image, 350, 42, 458, 276, "Female", "fuchsia")
bb.add(image, 416, 17, 510, 279, "Male", "blue")
bb.add(image, 482, 55, 573, 278, "Female", "fuchsia")
bb.add(image, 547, 63, 615, 277, "Female", "fuchsia")
bb.add(image, 608, 49, 704, 275, "Female", "fuchsia")
bb.add(image, 672, 34, 767, 274, "Male", "blue")
bb.add(image, 725, 62, 813, 273, "Female", "fuchsia")
bb.add(image, 786, 38, 887, 267, "Male", "blue")
bb.add(image, 864, 51, 959, 266, "Male", "blue")
show_and_save("POBB", image, out_path)

if __name__ == "__main__":
Expand Down

0 comments on commit 1f4e5d5

Please sign in to comment.