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

janela de configuracao de diretorio e execucao de conversao de superpixel para xml implementada

parent d32ceea1
......@@ -79,7 +79,6 @@ if __name__ == "__main__":
tk.add_command("Select extractors", act.select_extractors, 'e')
tk.add_separator()
tk.add_command("Execute", act.run_extractors, 'F')
tk.add_separator()
tk.add_command("Extract frames", act.run_extract_frame, 'V')
......@@ -102,6 +101,11 @@ if __name__ == "__main__":
tk.add_command("Cross Validation", act.cross_validation, 'X')
tk.add_command("Experimenter All", act.experimenter_all, 'p')
tk.add_menu("XML")
tk.add_command("Configure Folders", act.config_xml)
tk.add_separator()
tk.add_command("Execute Conversion", act.run_xml_converter)
tk.add_menu("Help")
tk.add_command("About Pynovisao", act.about, 'b')
......
......@@ -17,11 +17,11 @@ from interface.interface import InterfaceException as IException
from PIL import Image
from pascal_voc_writer import Writer as wr
import shutil
from tkinter import *
import segmentation
import extraction
from extraction import FeatureExtractor
import time
import classification
from classification import Classifier
......@@ -33,6 +33,7 @@ from util.file_utils import File
from util.utils import TimeUtils
from util.utils import MetricUtils
from util.x11_colors import X11Colors
import functools as ft
import multiprocessing
from multiprocessing import Process, Manager
import threading
......@@ -71,6 +72,8 @@ class Act(object):
self._image_name = None
self._image_path = None
self._xml_file = None
self._seg_folder = os.getcwd()
self._img_folder = os.getcwd()
self._init_dataset(args["dataset"])
self._init_classes(args["classes"], args["colors"])
......@@ -164,7 +167,6 @@ 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()
......@@ -1084,3 +1086,119 @@ class Act(object):
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))
def run_xml_converter(self):
def arrasteSeg(imgog, imgseg, LinhaOg, ColunaOg, LinhaSeg, ColunaSeg):
#arraste do superpixel sobre a imagem original
l = 0
while(l <= (LinhaOg - LinhaSeg)):
c = 0
while(c <= (ColunaOg - ColunaSeg)):
i = 0
igual = True
#verificacao pixel a pixel de igualdade entre superpixel e imagem original
while(igual and i < LinhaSeg):
j = 0
while(igual and j < ColunaSeg):
if(imgog[l+i,c+j,0] != imgseg[i,j,0] or imgog[l+i,c+j,1] != imgseg[i,j,1] or imgog[l+i,c+j,2] != imgseg[i,j,2]): ##(-i)
if(imgseg[i,j,0] != 0 and imgseg[i,j,1] != 0 and imgseg[i,j,2] != 0): #verificacao de nao igualdade para pixels nao irrelevantes
igual = False
i = LinhaOg+1
j = i
j = j + 5
i = i + 5
if(igual):
return l, c, i, j, igual
c = c + 1
l = l + 1
def achaImg(pathS, pathIO):
tottime = 0
arquivos = []
#verificar arquivos em todas as pastas partindo de um diretório raiz
for pog, _, files in os.walk(os.path.abspath(pathIO)):
#acha os arquivos de imagem na pasta de segmentos
for file in files:
if(file.endswith('.jpeg') or file.endswith('.tif') or file.endswith('.jpg') or file.endswith('.png')):##(-f)
#leitura dos arquivos de imagem na pasta original
arquivo=os.path.join(pog, file)
imgog=cv2.imread(arquivo,-1)
LinhaOg,ColunaOg,_=imgog.shape
# Writer(path, width, height) para iniciar o geramento do xml
print("criando xml para a imagem {}".format(file))
writer = wr(pog, LinhaOg, ColunaOg)
for pseg, _,filesIO in os.walk(os.path.abspath(pathS)):
pasta=pseg#pega o nome da pasta (classe do segmento)
pasta = pasta[-1::-1]
pasta = pasta[:pasta.index('/')]
pasta = pasta[-1::-1]
for fileIO in filesIO:
if(fileIO.endswith('.jpeg') or fileIO.endswith('.tif') or fileIO.endswith('.jpg') or fileIO.endswith('.png')):##(-f)
if (fileIO.startswith(file)): #verifica se eh o segmento desta imagem ou nao.
#leitura dos segmentos em seus diretorios
arquivo=os.path.join(pseg,fileIO)
imgseg=cv2.imread(arquivo,-1)
LinhaSeg,ColunaSeg,_=imgseg.shape
l=0
print("buscando encaixe do superpixel {}".format(fileIO))
#arraste do superpixel sobre a imagem original
starttime = time.time()
l,c,i,j,igual=arrasteSeg(imgog, imgseg, LinhaOg, ColunaOg, LinhaSeg, ColunaSeg)
if(igual): #Se o segmento esta igual a sua posicao no original
igual=False
#tudo isso pra terminar o loop desse segmento
if not(fileIO in arquivos): #Se o segmento atual ja foi visto
# ::addObject(name, xmin, ymin, xmax, ymax)
print("adicionando anotacao, superpixel {} encontrado em {}".format(fileIO,file))
tottime = tottime + time.time() - starttime
arquivos.append(fileIO) #Adiciona nos segmentos ja vistos
writer.addObject(pasta, c, l, c + ColunaSeg, l + LinhaSeg) #adiciona o objeto no xml
l=LinhaOg+1
c=ColunaOg+1
#save(path) termina o salvamento do xml
print("salvando xml")
print("Tempo decorrido em segundos: {}".format(tottime))
writer.save('{}.{}'.format(file,'xml'))
#gera o xml com as medidas
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(file),current_path+"/{}.xml".format(file))
print("Processo finalizado")
achaImg(self._seg_folder,self._img_folder)
def config_xml(self):
config_xml = Toplevel()
def close_config_xml(config_xml):
config_xml.destroy()
def config_xml_directory(Button, E):
path = self.tk.utils.ask_directory(default_dir = os.getcwd())
if(Button == 1):
self._img_folder = path
E.delete(0,END)
E.insert(0, path)
else:
self._seg_folder = path
E.delete(0,END)
E.insert(0, path)
config_xml.title("Directory configuration for XML conversion")
L1=Label(config_xml, text="Directory of the main images: ")
L2=Label(config_xml, text="Directory of the segments: ")
E1=Entry(config_xml, width= 50)
E2=Entry(config_xml, width= 50)
B1=Button(config_xml, text="Change directory", command = ft.partial(config_xml_directory,1,E1))
B2=Button(config_xml, text="Change directory", command = ft.partial(config_xml_directory,0,E2))
BS=Button(config_xml, text="Save all directories", command = ft.partial(close_config_xml, config_xml))
E1.insert(0, self._img_folder)
E2.insert(0, self._seg_folder)
L1.grid(row=1,column=1)
L2.grid(row=2,column=1)
E1.grid(row=1,column=2)
E2.grid(row=2,column=2)
B1.grid(row=1,column=3)
B2.grid(row=2,column=3)
BS.grid(row=3,column=2)
config_xml.mainloop()
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