Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
25b15405
Commit
25b15405
authored
Jul 08, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an option to convert IDL annotation files to imglab format.
parent
af9071f9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
202 additions
and
2 deletions
+202
-2
CMakeLists.txt
tools/imglab/CMakeLists.txt
+2
-0
convert_idl.cpp
tools/imglab/src/convert_idl.cpp
+182
-0
convert_idl.h
tools/imglab/src/convert_idl.h
+13
-0
main.cpp
tools/imglab/src/main.cpp
+5
-2
No files found.
tools/imglab/CMakeLists.txt
View file @
25b15405
...
...
@@ -22,6 +22,8 @@ ADD_EXECUTABLE(${target_name}
src/convert_pascal_xml.cpp
src/convert_pascal_v1.h
src/convert_pascal_v1.cpp
src/convert_idl.h
src/convert_idl.cpp
src/common.h
src/common.cpp
)
...
...
tools/imglab/src/convert_idl.cpp
0 → 100644
View file @
25b15405
#include "convert_idl.h"
#include "image_dataset_metadata.h"
#include <iostream>
#include <string>
#include <dlib/dir_nav.h>
#include <dlib/time_this.h>
using
namespace
std
;
using
namespace
dlib
;
namespace
{
using
namespace
dlib
::
image_dataset_metadata
;
// ----------------------------------------------------------------------------------------
inline
bool
next_is_number
(
std
::
istream
&
in
)
{
return
(
'0'
<=
in
.
peek
()
&&
in
.
peek
()
<=
'9'
)
||
in
.
peek
()
==
'-'
||
in
.
peek
()
==
'+'
;
}
int
read_int
(
std
::
istream
&
in
)
{
bool
is_neg
=
false
;
if
(
in
.
peek
()
==
'-'
)
{
is_neg
=
true
;
in
.
get
();
}
if
(
in
.
peek
()
==
'+'
)
in
.
get
();
int
val
=
0
;
while
(
'0'
<=
in
.
peek
()
&&
in
.
peek
()
<=
'9'
)
{
val
=
10
*
val
+
in
.
get
()
-
'0'
;
}
if
(
is_neg
)
return
-
val
;
else
return
val
;
}
// ----------------------------------------------------------------------------------------
void
parse_annotation_file
(
const
std
::
string
&
file
,
dlib
::
image_dataset_metadata
::
dataset
&
data
)
{
ifstream
fin
(
file
.
c_str
());
if
(
!
fin
)
throw
dlib
::
error
(
"Unable to open file "
+
file
);
bool
in_quote
=
false
;
int
point_count
=
0
;
bool
in_point_list
=
false
;
bool
saw_any_points
=
false
;
image
img
;
string
label
;
point
p1
,
p2
;
while
(
fin
.
peek
()
!=
EOF
)
{
if
(
in_point_list
&&
next_is_number
(
fin
))
{
const
int
val
=
read_int
(
fin
);
switch
(
point_count
)
{
case
0
:
p1
.
x
()
=
val
;
break
;
case
1
:
p1
.
y
()
=
val
;
break
;
case
2
:
p2
.
x
()
=
val
;
break
;
case
3
:
p2
.
y
()
=
val
;
break
;
default:
throw
dlib
::
error
(
"parse error in file "
+
file
);
}
++
point_count
;
}
char
ch
=
fin
.
get
();
if
(
ch
==
':'
)
continue
;
if
(
ch
==
'"'
)
{
in_quote
=
!
in_quote
;
continue
;
}
if
(
in_quote
)
{
img
.
filename
+=
ch
;
continue
;
}
if
(
ch
==
'('
)
{
in_point_list
=
true
;
point_count
=
0
;
label
.
clear
();
saw_any_points
=
true
;
}
if
(
ch
==
')'
)
{
in_point_list
=
false
;
label
.
clear
();
while
(
fin
.
peek
()
!=
EOF
&&
fin
.
peek
()
!=
';'
&&
fin
.
peek
()
!=
','
)
{
char
ch
=
fin
.
get
();
if
(
ch
==
':'
)
continue
;
label
+=
ch
;
}
}
if
(
ch
==
','
&&
!
in_point_list
)
{
box
b
;
b
.
rect
=
rectangle
(
p1
,
p2
);
b
.
label
=
label
;
img
.
boxes
.
push_back
(
b
);
}
if
(
ch
==
';'
)
{
if
(
saw_any_points
)
{
box
b
;
b
.
rect
=
rectangle
(
p1
,
p2
);
b
.
label
=
label
;
img
.
boxes
.
push_back
(
b
);
}
data
.
images
.
push_back
(
img
);
img
.
filename
.
clear
();
img
.
boxes
.
clear
();
}
}
}
// ----------------------------------------------------------------------------------------
}
void
convert_idl
(
const
parser_type
&
parser
)
{
cout
<<
"Convert from IDL annotation format..."
<<
endl
;
dlib
::
image_dataset_metadata
::
dataset
dataset
;
for
(
unsigned
long
i
=
0
;
i
<
parser
.
number_of_arguments
();
++
i
)
{
parse_annotation_file
(
parser
[
i
],
dataset
);
}
const
std
::
string
filename
=
parser
.
option
(
"c"
).
argument
();
save_image_dataset_metadata
(
dataset
,
filename
);
}
tools/imglab/src/convert_idl.h
0 → 100644
View file @
25b15405
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_IMGLAB_CONVErT_IDL_H__
#define DLIB_IMGLAB_CONVErT_IDL_H__
#include "common.h"
void
convert_idl
(
const
parser_type
&
parser
);
#endif // DLIB_IMGLAB_CONVErT_IDL_H__
tools/imglab/src/main.cpp
View file @
25b15405
...
...
@@ -3,6 +3,7 @@
#include "metadata_editor.h"
#include "convert_pascal_xml.h"
#include "convert_pascal_v1.h"
#include "convert_idl.h"
#include <iostream>
#include <fstream>
...
...
@@ -125,7 +126,7 @@ int main(int argc, char** argv)
parser
.
add_option
(
"rename"
,
"Rename all labels of <arg1> to <arg2>."
,
2
);
parser
.
add_option
(
"v"
,
"Display version."
);
parser
.
add_option
(
"convert"
,
"Convert foreign image Annotations from <arg> format to the imglab format. "
"Supported formats: pascal-xml, pascal-v1"
,
1
);
"Supported formats: pascal-xml, pascal-v1
, idl
"
,
1
);
parser
.
parse
(
argc
,
argv
);
...
...
@@ -138,7 +139,7 @@ int main(int argc, char** argv)
parser
.
check_incompatible_options
(
"l"
,
"rename"
);
parser
.
check_incompatible_options
(
"convert"
,
"l"
);
parser
.
check_incompatible_options
(
"convert"
,
"rename"
);
const
char
*
convert_args
[]
=
{
"pascal-xml"
,
"pascal-v1"
};
const
char
*
convert_args
[]
=
{
"pascal-xml"
,
"pascal-v1"
,
"idl"
};
parser
.
check_option_arg_range
(
"convert"
,
convert_args
);
if
(
parser
.
option
(
"h"
))
...
...
@@ -166,6 +167,8 @@ int main(int argc, char** argv)
convert_pascal_xml
(
parser
);
else
if
(
parser
.
option
(
"convert"
).
argument
()
==
"pascal-v1"
)
convert_pascal_v1
(
parser
);
else
if
(
parser
.
option
(
"convert"
).
argument
()
==
"idl"
)
convert_idl
(
parser
);
}
else
{
...
...
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