Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
8fd8703c
Commit
8fd8703c
authored
Jun 01, 2015
by
jiaolong_x220
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added PASCAL VOC dataset
parent
860eda95
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
428 additions
and
0 deletions
+428
-0
or_pascal.hpp
modules/datasets/include/opencv2/datasets/or_pascal.hpp
+102
-0
or_pascal.cpp
modules/datasets/samples/or_pascal.cpp
+112
-0
or_pascal.cpp
modules/datasets/src/or_pascal.cpp
+214
-0
No files found.
modules/datasets/include/opencv2/datasets/or_pascal.hpp
0 → 100644
View file @
8fd8703c
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#ifndef OPENCV_DATASETS_VOC_PASCAL_HPP
#define OPENCV_DATASETS_VOC_PASCAL_HPP
#include <string>
#include <vector>
#include "opencv2/datasets/dataset.hpp"
#include <opencv2/core.hpp>
namespace
cv
{
namespace
datasets
{
//! @addtogroup datasets_or
//! @{
struct
PascalPart
:
public
Object
{
std
::
string
name
;
int
xmin
;
int
ymin
;
int
xmax
;
int
ymax
;
};
struct
PascalObj
:
public
PascalPart
{
std
::
string
pose
;
bool
truncated
;
bool
difficult
;
bool
occluded
;
std
::
vector
<
PascalPart
>
parts
;
};
struct
OR_pascalObj
:
public
Object
{
std
::
string
filename
;
int
width
;
int
height
;
int
depth
;
std
::
vector
<
PascalObj
>
objects
;
};
class
CV_EXPORTS
OR_pascal
:
public
Dataset
{
public
:
virtual
void
load
(
const
std
::
string
&
path
)
=
0
;
static
Ptr
<
OR_pascal
>
create
();
};
//! @}
}
// namespace dataset
}
// namespace cv
#endif
modules/datasets/samples/or_pascal.cpp
0 → 100644
View file @
8fd8703c
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/datasets/or_pascal.hpp"
#include <opencv2/core.hpp>
#include <cstdio>
#include <cstdlib> // atoi
#include <string>
#include <vector>
#include <set>
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
datasets
;
int
main
(
int
argc
,
char
*
argv
[])
{
const
char
*
keys
=
"{ help h usage ? | | show this message }"
"{ path p |true| path to folder with dataset }"
;
CommandLineParser
parser
(
argc
,
argv
,
keys
);
string
path
(
parser
.
get
<
string
>
(
"path"
));
if
(
parser
.
has
(
"help"
)
||
path
==
"true"
)
{
parser
.
printMessage
();
return
-
1
;
}
Ptr
<
OR_pascal
>
dataset
=
OR_pascal
::
create
();
dataset
->
load
(
path
);
// Print train/test/validation size and first example
OR_pascalObj
*
example
;
vector
<
Ptr
<
Object
>
>
&
train
=
dataset
->
getTrain
();
printf
(
"
\n
train:
\n
size: %u"
,
(
unsigned
int
)
train
.
size
());
example
=
static_cast
<
OR_pascalObj
*>
(
train
[
0
].
get
());
printf
(
"
\n
first image:
\n
%s"
,
example
->
filename
.
c_str
());
printf
(
"
\n
size:"
);
printf
(
"
\n
- width: %d"
,
example
->
width
);
printf
(
"
\n
- height: %d"
,
example
->
height
);
printf
(
"
\n
- depth: %d"
,
example
->
depth
);
for
(
unsigned
int
i
=
0
;
i
<
example
->
objects
.
size
();
i
++
)
{
printf
(
"
\n
object %d"
,
i
);
printf
(
"
\n
name: %s"
,
example
->
objects
[
i
].
name
.
c_str
());
printf
(
"
\n
pose: %s"
,
example
->
objects
[
i
].
pose
.
c_str
());
printf
(
"
\n
truncated: %d"
,
example
->
objects
[
i
].
truncated
);
printf
(
"
\n
difficult: %d"
,
example
->
objects
[
i
].
difficult
);
printf
(
"
\n
occluded: %d"
,
example
->
objects
[
i
].
occluded
);
printf
(
"
\n
bounding box:"
);
printf
(
"
\n
- xmin: %d"
,
example
->
objects
[
i
].
xmin
);
printf
(
"
\n
- ymin: %d"
,
example
->
objects
[
i
].
ymin
);
printf
(
"
\n
- xmax: %d"
,
example
->
objects
[
i
].
xmax
);
printf
(
"
\n
- ymax: %d"
,
example
->
objects
[
i
].
ymax
);
}
vector
<
Ptr
<
Object
>
>
&
test
=
dataset
->
getTest
();
printf
(
"
\n
test:
\n
size: %u"
,
(
unsigned
int
)
test
.
size
());
example
=
static_cast
<
OR_pascalObj
*>
(
test
[
0
].
get
());
printf
(
"
\n
first image:
\n
%s"
,
example
->
filename
.
c_str
());
vector
<
Ptr
<
Object
>
>
&
validation
=
dataset
->
getValidation
();
printf
(
"
\n
validation:
\n
size: %u"
,
(
unsigned
int
)
validation
.
size
());
example
=
static_cast
<
OR_pascalObj
*>
(
validation
[
0
].
get
());
printf
(
"
\n
first image:
\n
%s
\n
"
,
example
->
filename
.
c_str
());
return
0
;
}
modules/datasets/src/or_pascal.cpp
0 → 100644
View file @
8fd8703c
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2015, Itseez Inc, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
//
// * Redistribution's of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
// This software is provided by the copyright holders and contributors "as is" and
// any express or implied warranties, including, but not limited to, the implied
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the Itseez Inc or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
#include "opencv2/datasets/or_pascal.hpp"
#include "opencv2/datasets/util.hpp"
#include <opencv2/datasets/tinyxml2/tinyxml2.h>
#include <fstream>
namespace
cv
{
namespace
datasets
{
using
namespace
std
;
using
namespace
tinyxml2
;
class
OR_pascalImp
:
public
OR_pascal
{
public
:
OR_pascalImp
()
{}
virtual
void
load
(
const
string
&
path
);
private
:
void
loadDataset
(
const
string
&
path
,
const
string
&
nameImageSet
,
vector
<
Ptr
<
Object
>
>
&
imageSet
);
Ptr
<
Object
>
parseAnnotation
(
const
string
path
,
const
string
id
);
const
char
*
parseNodeText
(
XMLElement
*
node
,
const
string
nodeName
,
const
string
defaultValue
);
};
void
OR_pascalImp
::
load
(
const
string
&
path
)
{
train
.
push_back
(
vector
<
Ptr
<
Object
>
>
());
test
.
push_back
(
vector
<
Ptr
<
Object
>
>
());
validation
.
push_back
(
vector
<
Ptr
<
Object
>
>
());
loadDataset
(
path
,
"train"
,
train
.
back
());
loadDataset
(
path
,
"test"
,
test
.
back
());
loadDataset
(
path
,
"val"
,
validation
.
back
());
}
void
OR_pascalImp
::
loadDataset
(
const
string
&
path
,
const
string
&
nameImageSet
,
vector
<
Ptr
<
Object
>
>
&
imageSet
)
{
string
pathImageSets
(
path
+
"ImageSets/Main/"
);
string
imageList
=
pathImageSets
+
nameImageSet
+
".txt"
;
ifstream
in
(
imageList
.
c_str
());
string
error_message
=
format
(
"Image list not exists!
\n
%s"
,
imageList
.
c_str
());
if
(
!
in
.
is_open
())
CV_Error
(
Error
::
StsBadArg
,
error_message
);
string
id
=
""
;
while
(
getline
(
in
,
id
)
)
{
if
(
strcmp
(
nameImageSet
.
c_str
(),
"test"
)
==
0
)
// test set ground truth is not available
{
Ptr
<
OR_pascalObj
>
annotation
(
new
OR_pascalObj
);
annotation
->
filename
=
path
+
"JPEGImages/"
+
id
+
".jpg"
;
imageSet
.
push_back
(
annotation
);
}
else
{
imageSet
.
push_back
(
parseAnnotation
(
path
,
id
));
}
}
}
const
char
*
OR_pascalImp
::
parseNodeText
(
XMLElement
*
node
,
const
string
nodeName
,
const
string
defaultValue
)
{
const
char
*
e
=
node
->
FirstChildElement
(
nodeName
.
c_str
())
->
GetText
();
if
(
e
!=
0
)
return
e
;
else
return
defaultValue
.
c_str
();
}
Ptr
<
Object
>
OR_pascalImp
::
parseAnnotation
(
const
string
path
,
const
string
id
)
{
string
pathAnnotations
(
path
+
"Annotations/"
);
string
pathImages
(
path
+
"JPEGImages/"
);
Ptr
<
OR_pascalObj
>
annotation
(
new
OR_pascalObj
);
XMLDocument
doc
;
string
xml_file
=
pathAnnotations
+
id
+
".xml"
;
XMLError
error_code
=
doc
.
LoadFile
(
xml_file
.
c_str
());
string
error_message
=
format
(
"Parsing XML failed. Error code = %d.
\n
File = %s"
,
error_code
,
xml_file
.
c_str
());
switch
(
error_code
)
{
case
XML_SUCCESS
:
break
;
case
XML_ERROR_FILE_NOT_FOUND
:
error_message
=
"XML file not found! "
+
error_message
;
CV_Error
(
Error
::
StsParseError
,
error_message
);
return
annotation
;
default
:
CV_Error
(
Error
::
StsParseError
,
error_message
);
break
;
}
// <annotation/>
XMLElement
*
xml_ann
=
doc
.
RootElement
();
// <filename/>
string
img_name
=
xml_ann
->
FirstChildElement
(
"filename"
)
->
GetText
();
annotation
->
filename
=
pathImages
+
img_name
;
// <size/>
XMLElement
*
sz
=
xml_ann
->
FirstChildElement
(
"size"
);
int
width
=
atoi
(
sz
->
FirstChildElement
(
"width"
)
->
GetText
());
int
height
=
atoi
(
sz
->
FirstChildElement
(
"height"
)
->
GetText
());
int
depth
=
atoi
(
sz
->
FirstChildElement
(
"depth"
)
->
GetText
());
annotation
->
width
=
width
;
annotation
->
height
=
height
;
annotation
->
depth
=
depth
;
// <object/>
vector
<
PascalObj
>
objects
;
XMLElement
*
xml_obj
=
xml_ann
->
FirstChildElement
(
"object"
);
while
(
xml_obj
)
{
PascalObj
pascal_obj
;
pascal_obj
.
name
=
xml_obj
->
FirstChildElement
(
"name"
)
->
GetText
();
pascal_obj
.
pose
=
parseNodeText
(
xml_obj
,
"pose"
,
"Unspecified"
);
pascal_obj
.
truncated
=
atoi
(
parseNodeText
(
xml_obj
,
"truncated"
,
"0"
))
>
0
;
pascal_obj
.
difficult
=
atoi
(
parseNodeText
(
xml_obj
,
"difficult"
,
"0"
))
>
0
;
pascal_obj
.
occluded
=
atoi
(
parseNodeText
(
xml_obj
,
"occluded"
,
"0"
))
>
0
;
// <bndbox/>
XMLElement
*
xml_bndbox
=
xml_obj
->
FirstChildElement
(
"bndbox"
);
pascal_obj
.
xmin
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"xmin"
)
->
GetText
());
pascal_obj
.
ymin
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"ymin"
)
->
GetText
());
pascal_obj
.
xmax
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"xmax"
)
->
GetText
());
pascal_obj
.
ymax
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"ymax"
)
->
GetText
());
// <part/>
vector
<
PascalPart
>
parts
;
XMLElement
*
xml_part
=
xml_obj
->
FirstChildElement
(
"part"
);
while
(
xml_part
)
{
PascalPart
pascal_part
;
pascal_part
.
name
=
xml_part
->
FirstChildElement
(
"name"
)
->
GetText
();
xml_bndbox
=
xml_part
->
FirstChildElement
(
"bndbox"
);
pascal_part
.
xmin
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"xmin"
)
->
GetText
());
pascal_part
.
ymin
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"ymin"
)
->
GetText
());
pascal_part
.
xmax
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"xmax"
)
->
GetText
());
pascal_part
.
ymax
=
atoi
(
xml_bndbox
->
FirstChildElement
(
"ymax"
)
->
GetText
());
parts
.
push_back
(
pascal_part
);
xml_part
=
xml_part
->
NextSiblingElement
(
"part"
);
}
pascal_obj
.
parts
=
parts
;
objects
.
push_back
(
pascal_obj
);
xml_obj
=
xml_obj
->
NextSiblingElement
(
"object"
);
}
annotation
->
objects
=
objects
;
return
annotation
;
}
Ptr
<
OR_pascal
>
OR_pascal
::
create
()
{
return
Ptr
<
OR_pascalImp
>
(
new
OR_pascalImp
);
}
}
}
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