UI updated (more layers)
This commit is contained in:
parent
9267e068cc
commit
36d107587f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
out
|
110
src/gui/main.ui
110
src/gui/main.ui
@ -23,7 +23,7 @@
|
||||
</layout>
|
||||
<containerlayout manager="grid">
|
||||
<property name="anchor">n</property>
|
||||
<property type="col" id="all" name="minsize">300</property>
|
||||
<property type="col" id="all" name="pad">20</property>
|
||||
</containerlayout>
|
||||
<child>
|
||||
<object class="ttk.LabeledScale" id="canny_thr1_slider" named="True">
|
||||
@ -34,7 +34,8 @@
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="ipadx">80</property>
|
||||
<property name="ipadx">60</property>
|
||||
<property name="padx">0</property>
|
||||
<property name="row">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -56,7 +57,8 @@
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="ipadx">80</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">60</property>
|
||||
<property name="row">0</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -66,7 +68,8 @@
|
||||
<property name="text" translatable="yes">Canny Edge threshold 2</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipady">5</property>
|
||||
<property name="row">1</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
@ -76,12 +79,12 @@
|
||||
<object class="pygubu.builder.widgets.pathchooserinput" id="img_path_input" named="True">
|
||||
<property name="mustexist">true</property>
|
||||
<property name="textvariable">string:img_path</property>
|
||||
<property name="type">file</property>
|
||||
<property name="type">directory</property>
|
||||
<bind sequence="<<PathChooserPathChanged>>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">200</property>
|
||||
<property name="columnspan">1 </property>
|
||||
<property name="ipadx">30</property>
|
||||
<property name="row">4</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
@ -89,10 +92,10 @@
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Label" id="img_path_label" named="True">
|
||||
<property name="text" translatable="yes">Image path</property>
|
||||
<property name="text" translatable="yes">Dataset path</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="row">5</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -105,7 +108,8 @@
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="ipadx">80</property>
|
||||
<property name="ipadx">60</property>
|
||||
<property name="padx">0</property>
|
||||
<property name="row">2</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -128,8 +132,8 @@
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">230</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="ipadx">60</property>
|
||||
<property name="row">6</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
@ -140,7 +144,7 @@
|
||||
<property name="text" translatable="yes">Size</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">0</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="columnspan">1</property>
|
||||
<property name="row">7</property>
|
||||
<property name="rowspan">1</property>
|
||||
</layout>
|
||||
@ -150,10 +154,11 @@
|
||||
<object class="ttk.Combobox" id="sobel_select_box" named="True">
|
||||
<property name="textvariable">string:sobel_select</property>
|
||||
<property name="values">x y both</property>
|
||||
<bind sequence="<ButtonRelease>" handler="update" add="" />
|
||||
<bind sequence="<Leave>" handler="update" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="ipadx">60</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">40</property>
|
||||
<property name="row">2</property>
|
||||
</layout>
|
||||
</object>
|
||||
@ -163,18 +168,82 @@
|
||||
<property name="text" translatable="yes">Sobel edge</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipady">5</property>
|
||||
<property name="row">3</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Button" id="button1">
|
||||
<property name="text" translatable="yes">Next img</property>
|
||||
<bind sequence="<ButtonPress>" handler="img_next" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="ipadx">10</property>
|
||||
<property name="row">4</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Button" id="button2">
|
||||
<property name="text" translatable="yes">Prev img</property>
|
||||
<bind sequence="<ButtonPress>" handler="img_prev" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">2</property>
|
||||
<property name="ipadx">10</property>
|
||||
<property name="row">4</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Label" id="label2">
|
||||
<property name="text" translatable="yes">Switch image</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="pady">5</property>
|
||||
<property name="row">5</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Button" id="button3">
|
||||
<property name="text" translatable="yes">Export dataset</property>
|
||||
<bind sequence="<ButtonPress>" handler="apply" add="" />
|
||||
<layout manager="grid">
|
||||
<property name="column">2</property>
|
||||
<property name="columnspan">2</property>
|
||||
<property name="ipadx">0</property>
|
||||
<property name="row">6</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Entry" id="entry1">
|
||||
<property name="textvariable">int:export_id</property>
|
||||
<property name="width">15</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="row">6</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Label" id="label1">
|
||||
<property name="text" translatable="yes">Img to export</property>
|
||||
<layout manager="grid">
|
||||
<property name="column">1</property>
|
||||
<property name="row">7</property>
|
||||
</layout>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="ttk.Labelframe" id="output" named="True">
|
||||
<property name="height">200</property>
|
||||
<property name="labelanchor">n</property>
|
||||
<property name="text" translatable="yes">Output</property>
|
||||
<property name="width">200</property>
|
||||
<object class="pygubu.builder.widgets.scrolledframe" id="output" named="True">
|
||||
<property name="scrolltype">both</property>
|
||||
<property name="usemousewheel">false</property>
|
||||
<layout manager="pack">
|
||||
<property name="expand">true</property>
|
||||
<property name="fill">both</property>
|
||||
@ -182,6 +251,7 @@
|
||||
</layout>
|
||||
<child>
|
||||
<object class="tk.Canvas" id="output_canvas" named="True">
|
||||
<property name="relief">flat</property>
|
||||
<layout manager="pack">
|
||||
<property name="expand">true</property>
|
||||
<property name="fill">both</property>
|
||||
|
60
src/suite.py
60
src/suite.py
@ -1,15 +1,16 @@
|
||||
#!/usr/bin/python3
|
||||
import pathlib
|
||||
import pygubu
|
||||
import glob
|
||||
from tkinter import *
|
||||
from PIL import ImageTk, Image
|
||||
import numpy as np
|
||||
import cv2
|
||||
import time
|
||||
|
||||
PROJECT_PATH = pathlib.Path(__file__).parent
|
||||
PROJECT_UI = "./src/gui/main.ui"
|
||||
|
||||
|
||||
class MainApp:
|
||||
def __init__(self, master=None):
|
||||
self.builder = builder = pygubu.Builder()
|
||||
@ -23,30 +24,73 @@ class MainApp:
|
||||
|
||||
self.canny_thr1 = None
|
||||
self.canny_thr2 = None
|
||||
|
||||
self.img_path = None
|
||||
self.img_current = 0
|
||||
self.img_max = 0
|
||||
|
||||
self.blur_rate = None
|
||||
self.img_size = None
|
||||
self.sobel_select = None
|
||||
self.export_id = None
|
||||
builder.import_variables(self,
|
||||
['canny_thr1',
|
||||
'canny_thr2',
|
||||
'img_path',
|
||||
'blur_rate',
|
||||
'img_size',
|
||||
'sobel_select'])
|
||||
|
||||
'sobel_select',
|
||||
'export_id'])
|
||||
builder.connect_callbacks(self)
|
||||
|
||||
def run(self):
|
||||
self.mainwindow.mainloop()
|
||||
|
||||
def img_prev(self, event=None):
|
||||
if self.img_current == 0:
|
||||
self.img_current = self.img_max - 1
|
||||
else:
|
||||
self.img_current = self.img_current - 1
|
||||
self.update(self)
|
||||
|
||||
def img_next(self, event=None):
|
||||
if self.img_current == (self.img_max - 1):
|
||||
self.img_current = 0
|
||||
else:
|
||||
self.img_current = self.img_current + 1
|
||||
self.update(self)
|
||||
|
||||
def apply(self, event=None):
|
||||
img_arr = self.tk_imgs
|
||||
img_id = self.export_id.get()
|
||||
|
||||
if (img_id >= 0 and img_id < len(img_arr)):
|
||||
print("export")
|
||||
else:
|
||||
print("Nothing to export!")
|
||||
|
||||
def update(self, event=None):
|
||||
path = self.img_path.get()
|
||||
print(path)
|
||||
|
||||
drawW = self.canvas.winfo_width()
|
||||
drawX = 0
|
||||
drawY = 0
|
||||
|
||||
if path != None and path != "":
|
||||
# Get all images at current path
|
||||
images = []
|
||||
for file in glob.glob(path + "/*.png"):
|
||||
images.append(file)
|
||||
|
||||
self.img_max = len(images)
|
||||
|
||||
# Get all user vars
|
||||
ct1 = self.canny_thr1.get()
|
||||
ct2 = self.canny_thr2.get()
|
||||
|
||||
print(f"canny 1: {ct1}, canny2: {ct2}")
|
||||
|
||||
br = self.blur_rate.get()
|
||||
sxy = self.sobel_select.get()
|
||||
size = self.img_size.get()
|
||||
@ -58,7 +102,7 @@ class MainApp:
|
||||
self.tk_imgs = []
|
||||
|
||||
# Import and resize image
|
||||
img = cv2.imread(path)
|
||||
img = cv2.imread(images[self.img_current])
|
||||
img = cv2.resize(img, (size, size), interpolation = cv2.INTER_AREA)
|
||||
output.append(img) # First output image is original
|
||||
|
||||
@ -105,8 +149,14 @@ class MainApp:
|
||||
tk_img = ImageTk.PhotoImage(image=Image.fromarray(tk_img))
|
||||
self.tk_imgs.append(tk_img)
|
||||
|
||||
self.canvas.create_image((size * idx),0,anchor=NW,image=self.tk_imgs[idx],tags="og")
|
||||
## Check if next item will be out of range
|
||||
if (drawX + size >= drawW):
|
||||
drawY += size
|
||||
drawX = 0
|
||||
self.canvas.configure(height=(drawY+size))
|
||||
|
||||
self.canvas.create_image(drawX,drawY,anchor=NW,image=self.tk_imgs[idx],tags="og")
|
||||
drawX += size
|
||||
self.canvas.draw()
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user