Skip to content

Commit

Permalink
Fix create a bounding box label creationg and test it in data generation
Browse files Browse the repository at this point in the history
  • Loading branch information
divait committed Aug 10, 2020
1 parent 878bd28 commit b511f4f
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 30 deletions.
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ channels:
- conda-forge

dependencies:
- python=3.7
- python=3.7
- opencv-python=4.3
7 changes: 3 additions & 4 deletions examples/data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]
)

Expand Down
2 changes: 1 addition & 1 deletion flip/transformers/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions flip/transformers/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .save_image import SaveImage
from . import json
from . import csv
from .json import CreateJson
from .csv import CreateCSV
2 changes: 1 addition & 1 deletion flip/transformers/labeler/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .core import *
from .create_bounding_boxes import CreateBoundingBoxes
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -16,29 +15,28 @@ 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

array.append(data)

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
Expand All @@ -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]
File renamed without changes.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down

0 comments on commit b511f4f

Please sign in to comment.