Commit d32ceea1 authored by João Porto's avatar João Porto

implementacao da ferramenta segments-to-xml dentro do pynovisao

parent 58d3ceb4
# Título: Pynovisao
## Autores (ordem alfabética): Adair da Silva Oliveira Junior, Alessandro dos Santos Ferreira, Diego André Sant'Ana(diegoandresantana@gmail.com), Diogo Nunes Gonçalves(dnunesgoncalves@gmail.com), Everton Castelão Tetila(evertontetila@gmail.com), Felipe Silveira(eng.fe.silveira@gmail.com), Gabriel Kirsten Menezes(gabriel.kirsten@hotmail.com), Gilberto Astolfi(gilbertoastolfi@gmail.com), Hemerson Pistori (pistori@ucdb.br), Nícolas Alessandro de Souza Belete(nicolas.belete@gmail.com)
## Autores (ordem alfabética): Adair da Silva Oliveira Junior, Alessandro dos Santos Ferreira, Diego André Sant'Ana(diegoandresantana@gmail.com), Diogo Nunes Gonçalves(dnunesgoncalves@gmail.com), Everton Castelão Tetila(evertontetila@gmail.com), Felipe Silveira(eng.fe.silveira@gmail.com), Gabriel Kirsten Menezes(gabriel.kirsten@hotmail.com), Gilberto Astolfi(gilbertoastolfi@gmail.com), Hemerson Pistori (pistori@ucdb.br), Nícolas Alessandro de Souza Belete(nicolas.belete@gmail.com), Fabio Prestes (fpcrezende@gmail.com), Joao Porto (jvaporto@gmail.com).
## Resumo:
......
......@@ -21,3 +21,4 @@ python-interface
tqdm
sklearn
pyxdg
pascal-voc-writer
......@@ -73,6 +73,7 @@ if __name__ == "__main__":
tk.add_separator()
tk.add_command("Assign using labeled image", act.assign_using_labeled_image, 'l')
tk.add_command("Execute folder", act.run_segmenter_folder)
tk.add_command("Create .XML file", act.create_xml)
tk.add_menu("Feature Extraction")
tk.add_command("Select extractors", act.select_extractors, 'e')
......
......@@ -15,6 +15,8 @@ import types
import cv2
from interface.interface import InterfaceException as IException
from PIL import Image
from pascal_voc_writer import Writer as wr
import shutil
import segmentation
import extraction
......@@ -68,6 +70,7 @@ class Act(object):
self._mask_image = None
self._image_name = None
self._image_path = None
self._xml_file = None
self._init_dataset(args["dataset"])
self._init_classes(args["classes"], args["colors"])
......@@ -127,10 +130,9 @@ class Act(object):
self.add_class(dialog = False, color='Yellow')
self._current_class = 0
def open_image(self, imagename = None):
"""Open a new image.
"""Open a new image and starts a new XML instance for such image.
Parameters
----------
......@@ -146,7 +148,7 @@ class Act(object):
y = int(event.ydata)
self.tk.write_log("Coordinates: x = %d y = %d", x, y)
segment, size_segment, idx_segment, run_time = self.segmenter.get_segment(x, y)
segment, size_segment, self._xml_file, idx_segment, run_time = self.segmenter.get_segment(x, y, self._xml_file, self.classes[self._current_class]["name"].value)
if size_segment > 0:
self.tk.append_log("\nSegment = %d: %0.3f seconds", idx_segment, run_time)
......@@ -162,18 +164,18 @@ class Act(object):
filepath = File.save_class_image(segment, self.dataset, self.classes[self._current_class]["name"].value, self._image_name, idx_segment)
if filepath:
self.tk.append_log("\nSegment saved in %s", filepath)
if imagename is None:
imagename = self.tk.utils.ask_image_name()
if imagename:
self._image = File.open_image(imagename)
self._image_name = File.get_filename(imagename)
self._xml_file=wr(self._image_name,self._image.shape[0],self._image.shape[1])
self.tk.write_log("Opening %s...", self._image_name)
self.tk.add_image(self._image, self._image_name, onclick)
self._const_image = self._image
self.segmenter.reset()
self._gt_segments = None
......@@ -1069,3 +1071,16 @@ class Act(object):
message = header_output + 'Saved in ' + matrix_path
self.tk.write_log(message)
def create_xml(self):
'''
Generate a .XML file, with the file having 'name of the image including its extension'.xml.
This file will take the current xml object from Pascal_Voc_Writer and finalize it,
creating the file in the current directory and moving it towards /pynovisao/data/XML.
'''
self._xml_file.save("{}.xml".format(self._image_name))
current_path=os.getcwd()
current_path=current_path[-1::-1]
current_path=current_path[3::1]
current_path=current_path[-1::-1]
current_path=current_path+"data/XML"
shutil.move(os.getcwd()+"/{}.xml".format(self._image_name),current_path+"/{}.xml".format(self._image_name))
......@@ -54,7 +54,7 @@ class Segmenter(object):
pass
@abstractmethod
def get_segment(self, px, py, idx_segment):
def get_segment(self, px, py, xml_file, name_segment, idx_segment):
"""Return a specified segment using a index or position in image.
Implement this method to extend this class with a new segmenter algorithm.
"""
......
......@@ -58,7 +58,7 @@ class SkimageSegmenter(object):
return np.unique(self._segments)
def get_segment_skimage(self, px = 0, py = 0, idx_segment = None):
def get_segment_skimage(self, px = 0, py = 0, xml_file = None, name_segment = None, idx_segment = None):
"""Return a specified segment using a index or position in image.
Parameters
......@@ -67,6 +67,10 @@ class SkimageSegmenter(object):
Segment point inside the image in x-axis.
py : integer, optional, default = 0
Segment point inside the image in y-axis.
xml_file : pascal_voc_writer file, optional, default = None
Variable used to create a .XML file for the current image.
name_segment : string, optional, default = None
Variable used to name the class of the selected segment for this image.
idx_segment : integer, optional, default = None
Index of segment returned by previous call of this method.
......@@ -76,6 +80,8 @@ class SkimageSegmenter(object):
Rectangle encompassing the segment image.
size_segment : integer
Number of pixels of segment.
xml_file : pascal_voc_writer file
Finalized pascal_voc_writer file.
idx_segment : integer
Index of segment if found, -1 otherwise.
run_time : integer
......@@ -111,12 +117,14 @@ class SkimageSegmenter(object):
# Get the rectangle that encompasses the countour
x,y,w,h = cv2.boundingRect(max_contour)
# Create the object for this segment in the .XML file
xml_file.addObject(name_segment, x, y, x+w, y+h)
segment = segment[y:y+h, x:x+w]
end_time = TimeUtils.get_time()
# Return the rectangle that encompasses the countour
return segment, size_segment, idx_segment, (end_time - start_time)
return segment, size_segment, xml_file, idx_segment, (end_time - start_time)
def paint_segment_skimage(self, image, color, px = 0, py = 0, idx_segment = [], border = True, clear = False):
......
......@@ -113,7 +113,7 @@ class Slic(Segmenter, SkimageSegmenter):
"""
return self.get_list_segments_skimage()
def get_segment(self, px = 0, py = 0, idx_segment = None):
def get_segment(self, px = 0, py = 0, xml_file = None, name_segment = None, idx_segment = None):
"""Return a specified segment using a index or position in image.
Parameters
......@@ -122,6 +122,10 @@ class Slic(Segmenter, SkimageSegmenter):
Segment point inside the image in x-axis.
py : integer, optional, default = 0
Segment point inside the image in y-axis.
xml_file : pascal_voc_writer file, optional, default = None
Variable used to create a .XML file for the current image.
name_segment : string, optional, default = None
Variable used to name the class of the selected segment for this image.
idx_segment : integer, optional, default = None
Index of segment returned by previous call of this method.
......@@ -131,12 +135,14 @@ class Slic(Segmenter, SkimageSegmenter):
Rectangle encompassing the segment image.
size_segment : integer
Number of pixels of segment.
xml_file : pascal_voc_writer file
Finalized pascal_voc_writer file.
idx_segment : integer
Index of segment if found, -1 otherwise.
run_time : integer
Running time spent in milliseconds.
"""
return self.get_segment_skimage(px, py, idx_segment)
return self.get_segment_skimage(px, py, xml_file, name_segment, idx_segment)
def paint_segment(self, image, color, px = 0, py = 0, idx_segment = [], border = True, clear = False):
"""Paint a list of segments using a index or position in image.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment