diff --git a/environment.yml b/environment.yml index 444b84c..cec77e8 100644 --- a/environment.yml +++ b/environment.yml @@ -4,4 +4,5 @@ channels: - conda-forge dependencies: - - python=3.7 \ No newline at end of file + - python=3.7 + - opencv-python=4.3 \ No newline at end of file diff --git a/examples/data_generator.py b/examples/data_generator.py index 89ab464..cd9422c 100644 --- a/examples/data_generator.py +++ b/examples/data_generator.py @@ -138,12 +138,11 @@ def create_element(objects_paths, backgrounds_paths): ), flip.transformers.data_augmentation.Flip('x'), # ts.ObjectsGetBGColor(), TODO: Modify to work with Apply to Objects - # lr.CreateTags(), flip.transformers.domain_randomization.Draw(), - # lr.CreateTags(), + flip.transformers.labeler.CreateBoundingBoxes(), flip.transformers.io.SaveImage(OUT_DIR, name), - # sr.csv.CreateCSV(OUT_DIR, name) - # sr.json.CreateJson(OUT_DIR, name), + # flip.transformers.io.CreateCSV(OUT_DIR, name) + flip.transformers.io.CreateJson(OUT_DIR, name), ] ) diff --git a/flip/transformers/__init__.py b/flip/transformers/__init__.py index 4ed84b4..c55763c 100644 --- a/flip/transformers/__init__.py +++ b/flip/transformers/__init__.py @@ -1,4 +1,4 @@ -from . import data_augmentation, domain_randomization, io +from . import data_augmentation, domain_randomization, io, labeler from .transformer import Transformer, Compose from .element import Element diff --git a/flip/transformers/io/__init__.py b/flip/transformers/io/__init__.py index e84cb2f..eaf6345 100644 --- a/flip/transformers/io/__init__.py +++ b/flip/transformers/io/__init__.py @@ -1,3 +1,3 @@ from .save_image import SaveImage -from . import json -from . import csv +from .json import CreateJson +from .csv import CreateCSV diff --git a/flip/transformers/labeler/__init__.py b/flip/transformers/labeler/__init__.py index a8ce586..8b1b0be 100644 --- a/flip/transformers/labeler/__init__.py +++ b/flip/transformers/labeler/__init__.py @@ -1 +1 @@ -from .core import * \ No newline at end of file +from .create_bounding_boxes import CreateBoundingBoxes \ No newline at end of file diff --git a/flip/transformers/labeler/core.py b/flip/transformers/labeler/create_bounding_boxes.py similarity index 64% rename from flip/transformers/labeler/core.py rename to flip/transformers/labeler/create_bounding_boxes.py index e7c8030..d1db304 100644 --- a/flip/transformers/labeler/core.py +++ b/flip/transformers/labeler/create_bounding_boxes.py @@ -1,11 +1,10 @@ -import json -from ..transforms import Element -from ..common import Transformer import cv2 -import matplotlib.pyplot as plt +from flip.transformers.element import Element +from flip.transformers.transformer import Transformer -class CreateTags(Transformer): + +class CreateBoundingBoxes(Transformer): def map(self, element: Element) -> Element: assert element, "element cannot be None" @@ -16,12 +15,10 @@ def map(self, element: Element) -> Element: def create(self, element): array = [] for obj in element.objects: - new_x, new_y, new_w, new_h = self.boundingBox(obj.image) - data = {} - data["name"] = obj.name - data["pos"] = {} - data["pos"]["x"] = obj.x + new_x - data["pos"]["y"] = obj.y + new_y + new_x, new_y, new_w, new_h = self.bounding_box(obj.image) + data = {"name": obj.name, "pos": {}} + data["pos"]["x"] = (obj.x or 0) + new_x + data["pos"]["y"] = (obj.y or 0) + new_y data["pos"]["w"] = new_w data["pos"]["h"] = new_h @@ -29,16 +26,17 @@ def create(self, element): return array - def boundingBox(self, img): + def bounding_box(self, image): + """ + Args: + image: image to process its width and height + Description: + This function + Returns: """ - Args: - image: image to process its width and height - Description: - This function - Returns: - """ + # Canny edge detection - edge gradient - edged = cv2.Canny(img, 10, 250) + edged = cv2.Canny(image, 10, 250) # Morphological Transformations # applying closing function @@ -61,6 +59,6 @@ def boundingBox(self, img): x, y, w, h = cv2.boundingRect(c) if w > 50 and h > 50: - new_img = img[y : y + h, x : x + w] + new_img = image[y: y + h, x: x + w] return x, y, new_img.shape[1], new_img.shape[0] diff --git a/flip/transformers/labeler/test.py b/flip/transformers/labeler/under_development.py similarity index 100% rename from flip/transformers/labeler/test.py rename to flip/transformers/labeler/under_development.py diff --git a/pyproject.toml b/pyproject.toml index 4e5853d..06a7892 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ author-email = "diego@linked.ai" classifiers = ["License :: OSI Approved :: MIT License"] requires-python=">=3.7" requires = [ - "opencv-python>=3.4,<4", + "opencv-python>=4.3", "pyyaml", "jinja2" ]