From 1f4e5d52bd6a991c87469750b720d4359989797f Mon Sep 17 00:00:00 2001 From: Manu NALEPA Date: Sun, 16 Jun 2019 23:45:10 +0200 Subject: [PATCH] add_bounding_box ==> add --- README.md | 9 ++-- bounding_box/bounding_box.py | 2 +- docs/examples.py | 80 ++++++++++++++++++------------------ 3 files changed, 45 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index 40a8a10..bfd4204 100644 --- a/README.md +++ b/README.md @@ -46,9 +46,9 @@ 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). @@ -56,7 +56,7 @@ channels in **BGR** order (same as **openCV** format). - `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. @@ -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: @@ -79,4 +79,3 @@ python docs/examples.py ``` If you run `examples.py` in an other directory it won't work. - diff --git a/bounding_box/bounding_box.py b/bounding_box/bounding_box.py index 999e100..5b93569 100644 --- a/bounding_box/bounding_box.py +++ b/bounding_box/bounding_box.py @@ -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: diff --git a/docs/examples.py b/docs/examples.py index f0e582c..56b8417 100755 --- a/docs/examples.py +++ b/docs/examples.py @@ -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__":