Beispiel #1
0
def sobreescreve(button, control, e):
    """
    Callback para o clique do botão de teste.
    :param button Botão que foi clicado.
    :param control Controlador da página.
    :param e Dados do evento.
    """
    control.soil = control.cane = False
    control.win.i_cane.SetValue(False)
    control.win.i_soil.SetValue(False)
    control.intest = True

    x0 = min(control.selected, key = lambda e: e.pos.x).pos.x
    y0 = min(control.selected, key = lambda e: e.pos.y).pos.y
    x1 = max(control.selected, key = lambda e: e.pos.x).pos.x
    y1 = max(control.selected, key = lambda e: e.pos.y).pos.y

    xdiff = x1 - x0
    ydiff = y1 - y0
    psize = control.parent.im.psize

    img = Image.new(((1 + xdiff) * psize.x, (1 + ydiff) * psize.y))

    comm = SingleStage(high, segment)
    comm.event = False

    x = [[0,128,128]]
    y = [0]

    x = x + control.train[0] + control.train[1]
    y = y + [0] * len(control.train[0]) + [255] * len(control.train[1])
    if len(x) > 2: 
      with open('patchtrain.csv','w') as f:
        for i in range(len(x)):
            tstr = ' '.join(map(str,x[i])) + ' '+ str(y[i])+'\n'
            f.write(tstr)
            

    for elem in control.selected:
        comm.push(patch = elem[0], pos = elem.pos)

    pwork = PatchWork(control.parent.im.psize, img)
    pwork.shred(0)

    control.last = control.sp.im
    control.sp.im = pwork
    update(control, control.win.canvas)

    while comm.pendent:
        data = comm.pop()
        pwork.access(data.pos - control.diff).sew(data.image.colorize())
        update(control, control.win.canvas)
Beispiel #2
0
def end(button, control, e):
    """
    Callback para o evento BUTTON de finalizar.
    :param button Botão responsável pelo evento.
    :param control Controlador de página.
    :param e Dados do evento.
    """
    img = control.im[0].copy()

    pw = PatchWork((200, 200), img)
    pw.shred()

    for patch in control.selected:
        pt = control.im.access(patch)[3].swap()
        pw.access(patch).sew(pt)
        cv.putText(img.raw, control.sp.gettext(patch),
                   (patch[0] * 200 + 10, patch[1] * 200 + 190),
                   cv.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2, cv.CV_AA)

    fdir = os.path.split(os.path.realpath(control.pg.address))
    img.save(fdir[0] + os.path.sep + "processed." + fdir[1])
Beispiel #3
0
    def generate(self):
        """
        Cria uma imagem baseada nos elementos selecionados para
        segmentação avulsa.
        :return Image
        """
        x0 = min(self.selected, key=lambda e: e.pos.x).pos.x
        y0 = min(self.selected, key=lambda e: e.pos.y).pos.y
        x1 = max(self.selected, key=lambda e: e.pos.x).pos.x
        y1 = max(self.selected, key=lambda e: e.pos.y).pos.y

        xdiff = x1 - x0
        ydiff = y1 - y0
        psize = self.parent.im.psize
        self.diff = Point(x0, y0)

        img = Image.new(((1 + xdiff) * psize.x, (1 + ydiff) * psize.y))
        pwork = PatchWork(psize, img)
        pwork.shred(0)

        for elem in self.selected:
            pwork.access((elem.pos - self.diff)).sew(elem[1])

        return pwork
Beispiel #4
0
    def generate(self):
        """
        Cria uma imagem baseada nos elementos selecionados para
        segmentação avulsa.
        :return Image
        """
        x0 = min(self.selected, key = lambda e: e.pos.x).pos.x
        y0 = min(self.selected, key = lambda e: e.pos.y).pos.y
        x1 = max(self.selected, key = lambda e: e.pos.x).pos.x
        y1 = max(self.selected, key = lambda e: e.pos.y).pos.y

        xdiff = x1 - x0
        ydiff = y1 - y0
        psize = self.parent.im.psize
        self.diff = Point(x0, y0)

        img = Image.new(((1 + xdiff) * psize.x, (1 + ydiff) * psize.y))
        pwork = PatchWork(psize, img)
        pwork.shred(0)

        for elem in self.selected:
            pwork.access((elem.pos - self.diff)).sew(elem[1])

        return pwork