Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
inovisao
pynovisao
Commits
0c9322be
Commit
0c9322be
authored
8 years ago
by
Alessandro dos Santos Ferreira
Browse files
Options
Download
Email Patches
Plain Diff
Pynovisao - Adicionando toolbar / zoom
parent
d96d7a81
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
39 deletions
+108
-39
src/interface/tk/tk_canvas.py
src/interface/tk/tk_canvas.py
+71
-12
src/interface/tk/tk_utils.py
src/interface/tk/tk_utils.py
+2
-2
src/interface/tk_interface.py
src/interface/tk_interface.py
+16
-18
src/main.py
src/main.py
+12
-5
src/pynovisao.py
src/pynovisao.py
+7
-2
No files found.
src/interface/tk/tk_canvas.py
View file @
0c9322be
...
...
@@ -16,49 +16,108 @@ else:
import
matplotlib
matplotlib
.
use
(
'TkAgg'
)
from
matplotlib.backends.backend_tkagg
import
FigureCanvasTkAgg
from
matplotlib.backends.backend_tkagg
import
FigureCanvasTkAgg
,
NavigationToolbar2TkAgg
from
matplotlib
import
pylab
as
plt
class
Image
(
object
):
def
__init__
(
self
,
parent
,
image
,
onclick
=
None
):
def
__init__
(
self
,
parent
):
self
.
parent
=
parent
self
.
_im
=
None
self
.
_canvas
=
None
self
.
_fig
=
None
self
.
_ax
=
None
self
.
_toolbar
=
None
self
.
_axes_visible
=
True
self
.
_toolbar_visible
=
True
def
toggle_axes
(
self
):
self
.
_axes_visible
=
not
self
.
_axes_visible
if
self
.
_canvas
is
not
None
:
self
.
_ax
.
get_xaxis
().
set_visible
(
self
.
_axes_visible
)
self
.
_ax
.
get_yaxis
().
set_visible
(
self
.
_axes_visible
)
self
.
_fig
.
tight_layout
()
self
.
_canvas
.
draw
()
def
toggle_toolbar
(
self
):
self
.
_toolbar_visible
=
not
self
.
_toolbar_visible
if
self
.
_toolbar_visible
==
True
:
self
.
_show_toolbar
()
else
:
self
.
_hide_toolbar
()
def
render
(
self
,
image
,
onclick
=
None
):
self
.
parent
.
image
=
image
fig
=
plt
.
figure
(
facecolor
=
'white'
,
edgecolor
=
'black'
,
linewidth
=
1
)
self
.
_
fig
=
plt
.
figure
(
facecolor
=
'white'
,
edgecolor
=
'black'
,
linewidth
=
1
)
self
.
_im
=
plt
.
imshow
(
self
.
parent
.
image
)
# later use a.set_data(new_data)
#ax = plt.gca()
#ax.set_xticklabels([])
#ax.set_yticklabels([])
self
.
_ax
=
plt
.
gca
()
self
.
_ax
.
get_xaxis
().
set_visible
(
self
.
_axes_visible
)
self
.
_ax
.
get_yaxis
().
set_visible
(
self
.
_axes_visible
)
# a tk.DrawingArea
self
.
_canvas
=
FigureCanvasTkAgg
(
fig
,
master
=
self
.
parent
)
self
.
_fig
.
tight_layout
()
self
.
_canvas
=
FigureCanvasTkAgg
(
self
.
_fig
,
master
=
self
.
parent
)
self
.
_canvas
.
show
()
self
.
_canvas
.
get_tk_widget
().
pack
(
side
=
Tk
.
TOP
,
fill
=
Tk
.
BOTH
,
expand
=
1
)
if
onclick
is
not
None
:
fig
.
canvas
.
mpl_connect
(
'button_press_event'
,
func
=
onclick
)
self
.
_fig
.
canvas
.
mpl_connect
(
'button_press_event'
,
func
=
onclick
)
if
self
.
_toolbar_visible
==
True
:
self
.
_show_toolbar
()
def
refresh
(
self
,
image
):
if
self
.
_canvas
is
not
None
:
self
.
parent
.
image
=
image
self
.
_im
.
set_data
(
self
.
parent
.
image
)
self
.
_fig
.
tight_layout
()
self
.
_canvas
.
draw
()
def
close
(
self
):
if
self
.
_canvas
is
not
None
:
self
.
parent
.
image
=
None
#self._im.set_data(np.zeros((0,0,3), float))
#self._canvas.draw()
self
.
_canvas
.
get_tk_widget
().
pack_forget
();
self
.
_canvas
.
get_tk_widget
().
destroy
();
self
.
_canvas
.
get_tk_widget
().
pack_forget
()
self
.
_canvas
.
get_tk_widget
().
destroy
()
if
self
.
_toolbar
is
not
None
:
self
.
_toolbar
.
pack_forget
()
self
.
_toolbar
.
destroy
()
self
.
_im
=
None
self
.
_canvas
=
None
self
.
_fig
=
None
self
.
_ax
=
None
self
.
_toolbar
=
None
return
True
return
False
def
_show_toolbar
(
self
):
if
self
.
_toolbar
is
None
and
self
.
_canvas
is
not
None
:
self
.
_toolbar
=
NavigationToolbar2TkAgg
(
self
.
_canvas
,
self
.
parent
)
self
.
_toolbar
.
configure
(
background
=
'white'
,
borderwidth
=
0
)
for
child
in
self
.
_toolbar
.
winfo_children
():
child
.
configure
(
background
=
'white'
,
foreground
=
'black'
)
#self._toolbar.update()
self
.
_toolbar
.
pack
(
side
=
Tk
.
TOP
,
fill
=
Tk
.
X
,
expand
=
False
)
def
_hide_toolbar
(
self
):
if
self
.
_toolbar
is
not
None
:
self
.
_toolbar
.
pack_forget
()
self
.
_toolbar
.
destroy
()
self
.
_toolbar
=
None
This diff is collapsed.
Click to expand it.
src/interface/tk/tk_utils.py
View file @
0c9322be
...
...
@@ -22,8 +22,8 @@ class Utils(object):
def
ask_image_name
(
title
=
'Open a image'
):
file_opt
=
options
=
{}
options
[
'defaultextension'
]
=
'.jpg'
options
[
'filetypes'
]
=
[(
'All supported files'
,
(
"*.
GIF
"
,
"*.
gif
"
,
"*.JPG"
,
"*.jpg"
,
"*.JPEG"
,
"*.jpeg"
,
"*.PNG"
,
"*.png"
,
"*.TIF"
,
"*.tif"
)),
(
'
GIF
'
,
(
"*.
GIF
"
,
"*.
gif
"
)),
options
[
'filetypes'
]
=
[(
'All supported files'
,
(
"*.
BMP
"
,
"*.
bmp
"
,
"*.JPG"
,
"*.jpg"
,
"*.JPEG"
,
"*.jpeg"
,
"*.PNG"
,
"*.png"
,
"*.TIF"
,
"*.tif"
)),
(
'
BMP
'
,
(
"*.
BMP
"
,
"*.
bmp
"
)),
(
'JPEG'
,
(
"*.JPG"
,
"*.jpg"
,
"*.JPEG"
,
"*.jpeg"
)),
(
'PNG'
,
(
"*.PNG"
,
"*.png"
)),
(
'TIF'
,
(
"*.TIF"
,
"*.tif"
))]
...
...
This diff is collapsed.
Click to expand it.
src/interface/tk_interface.py
View file @
0c9322be
...
...
@@ -34,7 +34,7 @@ class TkInterface(Interface):
self
.
_menus
=
[]
self
.
_image
=
None
self
.
_image
=
tk_local
.
Image
(
self
.
_root
)
self
.
_grid
=
None
self
.
_logger
=
None
self
.
_conf_dialog
=
None
...
...
@@ -68,30 +68,28 @@ class TkInterface(Interface):
if
self
.
_image
is
not
None
:
self
.
_image
.
close
()
self
.
_image
=
tk_local
.
Image
(
self
.
_root
,
image
,
lambda
event
,
*
_
:
self
.
_apply
(
onclick
,
event
))
self
.
_image
.
render
(
image
,
lambda
event
,
*
_
:
self
.
_apply
(
onclick
,
event
))
if
title
is
not
None
:
self
.
set_subtitle
(
title
)
def
refresh_image
(
self
,
image
,
title
=
None
):
if
self
.
_image
is
not
None
:
self
.
_image
.
refresh
(
image
)
if
title
is
not
None
:
self
.
set_subtitle
(
title
)
def
toggle_image_toolbar
(
self
):
self
.
_image
.
toggle_toolbar
()
def
toggle_image_axes
(
self
):
self
.
_image
.
toggle_axes
()
def
refresh_image
(
self
,
image
,
title
=
None
):
self
.
_image
.
refresh
(
image
)
if
title
is
not
None
:
self
.
set_subtitle
(
title
)
def
close_image
(
self
):
if
self
.
_image
is
not
None
:
if
tkMessageBox
.
askokcancel
(
"Quit"
,
"Do you want to close the image?"
):
self
.
_image
.
close
()
self
.
_image
=
None
return
True
return
False
if
tkMessageBox
.
askokcancel
(
"Quit"
,
"Do you want to close the image?"
):
return
self
.
_image
.
close
()
def
open_log
(
self
):
self
.
_logger
=
tk_local
.
Log
(
self
.
_root
)
...
...
@@ -107,7 +105,7 @@ class TkInterface(Interface):
if
self
.
_logger
:
self
.
_logger
.
clear_logger
()
def
to
o
gle_log
(
self
):
def
to
g
gle_log
(
self
):
if
self
.
_logger
:
self
.
close_log
()
else
:
...
...
This diff is collapsed.
Click to expand it.
src/main.py
View file @
0c9322be
...
...
@@ -34,15 +34,22 @@ if __name__ == "__main__":
tk
.
add_menu
(
"File"
)
tk
.
add_command
(
"Open a image"
,
act
.
open_image
,
'O'
)
tk
.
add_separator
()
tk
.
add_command
(
"Add new class"
,
act
.
add_class
,
'A'
)
tk
.
add_command
(
"Set dataset path"
,
act
.
set_dataset_path
,
'd'
)
tk
.
add_separator
()
tk
.
add_check_button
(
"Show log"
,
tk
.
toogle_log
)
tk
.
add_separator
()
tk
.
add_command
(
"Close image"
,
act
.
close_image
,
'W'
)
tk
.
add_separator
()
tk
.
add_command
(
"Quit"
,
tk
.
quit
,
'Q'
)
tk
.
add_menu
(
"View"
)
tk
.
add_check_button
(
"Show image axes"
,
tk
.
toggle_image_axes
)
tk
.
add_check_button
(
"Show image toolbar"
,
tk
.
toggle_image_toolbar
)
tk
.
add_separator
()
tk
.
add_check_button
(
"Show log"
,
tk
.
toggle_log
)
tk
.
add_menu
(
"Dataset"
)
tk
.
add_command
(
"Add new class"
,
act
.
add_class
,
'A'
)
tk
.
add_command
(
"Set dataset path"
,
act
.
set_dataset_path
,
'd'
)
tk
.
add_separator
()
tk
.
add_check_button
(
"Dataset generator"
,
act
.
toggle_dataset_generator
,
't'
)
tk
.
add_menu
(
"Segmentation"
)
tk
.
add_command
(
"Choose segmenter"
,
act
.
select_segmenter
)
tk
.
add_command
(
"Configure"
,
act
.
config_segmenter
,
'g'
)
...
...
This diff is collapsed.
Click to expand it.
src/pynovisao.py
View file @
0c9322be
...
...
@@ -39,6 +39,8 @@ class Act(object):
self
.
_init_dataset
(
args
[
"dataset"
])
self
.
_init_classes
(
args
[
"classes"
],
args
[
"colors"
])
self
.
_dataset_generator
=
True
def
_init_dataset
(
self
,
directory
):
...
...
@@ -62,12 +64,12 @@ class Act(object):
self
.
add_class
(
dialog
=
False
,
color
=
'Yellow'
)
self
.
_current_class
=
0
def
open_image
(
self
,
imagename
=
None
):
def
onclick
(
event
):
if
event
.
xdata
!=
None
and
event
.
ydata
!=
None
and
int
(
event
.
ydata
)
!=
0
:
if
event
.
xdata
!=
None
and
event
.
ydata
!=
None
and
int
(
event
.
ydata
)
!=
0
and
self
.
_dataset_generator
==
True
:
x
=
int
(
event
.
xdata
)
y
=
int
(
event
.
ydata
)
self
.
tk
.
write_log
(
"Coordinates: x = %d y = %d"
,
x
,
y
)
...
...
@@ -171,6 +173,9 @@ class Act(object):
self
.
_init_classes
()
self
.
tk
.
refresh_panel_classes
(
self
.
classes
)
def
toggle_dataset_generator
(
self
):
self
.
_dataset_generator
=
not
self
.
_dataset_generator
def
select_segmenter
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment