Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
6088abce
Commit
6088abce
authored
Jun 19, 2011
by
Davis King
Browse files
Made the window auto-size itself on startup depending on the size of the
first image.
parent
b090ef89
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
14 deletions
+46
-14
tools/imglab/src/metadata_editor.cpp
tools/imglab/src/metadata_editor.cpp
+45
-14
tools/imglab/src/metadata_editor.h
tools/imglab/src/metadata_editor.h
+1
-0
No files found.
tools/imglab/src/metadata_editor.cpp
View file @
6088abce
...
@@ -28,8 +28,10 @@ metadata_editor(
...
@@ -28,8 +28,10 @@ metadata_editor(
{
{
file
metadata_file
(
filename_
);
file
metadata_file
(
filename_
);
filename
=
metadata_file
.
full_name
();
filename
=
metadata_file
.
full_name
();
// Make our current directory be the one that contains the metadata file. We
// do this because that file might contain relative paths to the image files
// we are supposed to be loading.
set_current_dir
(
get_parent_directory
(
metadata_file
).
full_name
());
set_current_dir
(
get_parent_directory
(
metadata_file
).
full_name
());
cout
<<
"current dir: "
<<
get_current_dir
()
<<
endl
;
load_image_dataset_metadata
(
metadata
,
filename
);
load_image_dataset_metadata
(
metadata
,
filename
);
...
@@ -56,19 +58,24 @@ metadata_editor(
...
@@ -56,19 +58,24 @@ metadata_editor(
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_separator
());
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_separator
());
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_text
(
"Remove Selected Images"
,
*
this
,
&
metadata_editor
::
remove_selected_images
,
'R'
));
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_text
(
"Remove Selected Images"
,
*
this
,
&
metadata_editor
::
remove_selected_images
,
'R'
));
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_separator
());
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_separator
());
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_text
(
"
Qu
it"
,
static_cast
<
base_window
&>
(
*
this
),
&
drawable_window
::
close_window
,
'
Q
'
));
mbar
.
menu
(
0
).
add_menu_item
(
menu_item_text
(
"
Ex
it"
,
static_cast
<
base_window
&>
(
*
this
),
&
drawable_window
::
close_window
,
'
x
'
));
// set the size of this window and center on the screen .
// set the size of this window.
set_size
(
500
,
400
);
unsigned
long
width
,
height
;
get_display_size
(
width
,
height
);
set_pos
((
width
-
500
)
/
2
,
(
height
-
400
)
/
2
);
on_window_resized
();
on_window_resized
();
select_image
(
0
);
load_image_and_set_size
(
image_pos
);
on_window_resized
();
if
(
image_pos
<
lb_images
.
size
()
)
lb_images
.
select
(
image_pos
);
set_title
(
"Image Dataset Metadata Editor"
);
// make sure the window is centered on the screen.
unsigned
long
width
,
height
;
get_size
(
width
,
height
);
unsigned
long
screen_width
,
screen_height
;
get_display_size
(
screen_width
,
screen_height
);
set_pos
((
screen_width
-
width
)
/
2
,
(
screen_height
-
height
)
/
2
);
set_title
(
"Image Labeler - "
+
metadata
.
name
);
show
();
show
();
}
}
...
@@ -265,24 +272,48 @@ load_image(
...
@@ -265,24 +272,48 @@ load_image(
message_box
(
"Error loading image"
,
e
.
what
());
message_box
(
"Error loading image"
,
e
.
what
());
}
}
display
.
set_image
(
img
);
}
// ----------------------------------------------------------------------------------------
void
metadata_editor
::
load_image_and_set_size
(
unsigned
long
idx
)
{
if
(
idx
>=
metadata
.
images
.
size
())
return
;
array2d
<
rgb_pixel
>
img
;
display
.
clear_overlay
();
try
{
dlib
::
load_image
(
img
,
metadata
.
images
[
idx
].
filename
);
}
catch
(
exception
&
e
)
{
message_box
(
"Error loading image"
,
e
.
what
());
}
if
(
display
.
width
()
<
img
.
nc
()
||
if
(
display
.
width
()
<
img
.
nc
()
||
display
.
height
()
<
img
.
nr
()
)
display
.
height
()
<
img
.
nr
()
)
{
{
unsigned
long
screen_width
,
screen_height
;
unsigned
long
screen_width
,
screen_height
;
get_display_size
(
screen_width
,
screen_height
);
get_display_size
(
screen_width
,
screen_height
);
unsigned
long
needed_width
=
display
.
left
()
+
img
.
nc
()
+
4
;
unsigned
long
needed_width
=
display
.
left
()
+
img
.
nc
()
+
4
;
unsigned
long
needed_height
=
display
.
top
()
+
img
.
nr
()
+
4
;
unsigned
long
needed_height
=
display
.
top
()
+
img
.
nr
()
+
4
;
if
(
needed_width
<
screen_width
*
0.8
&&
if
(
needed_width
+
50
<
screen_width
&&
needed_height
<
screen_height
*
0.8
)
needed_height
+
50
<
screen_height
)
{
{
set_size
(
needed_width
,
needed_height
);
set_size
(
needed_width
,
needed_height
);
on_window_resized
();
}
}
}
}
display
.
set_image
(
img
);
display
.
set_image
(
img
);
}
}
...
...
tools/imglab/src/metadata_editor.h
View file @
6088abce
...
@@ -34,6 +34,7 @@ private:
...
@@ -34,6 +34,7 @@ private:
void
select_image
(
unsigned
long
idx
);
void
select_image
(
unsigned
long
idx
);
void
save_metadata_to_file
(
const
std
::
string
&
file
);
void
save_metadata_to_file
(
const
std
::
string
&
file
);
void
load_image
(
unsigned
long
idx
);
void
load_image
(
unsigned
long
idx
);
void
load_image_and_set_size
(
unsigned
long
idx
);
std
::
string
filename
;
std
::
string
filename
;
dlib
::
image_dataset_metadata
::
dataset
metadata
;
dlib
::
image_dataset_metadata
::
dataset
metadata
;
...
...
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