Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Commits
4a1c4a98
Commit
4a1c4a98
authored
Nov 05, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
soft cascade become Algorithm
parent
ff8417db
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
124 additions
and
107 deletions
+124
-107
objdetect.hpp
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
+33
-30
perf_cascadeclassifier.cpp
modules/objdetect/perf/perf_cascadeclassifier.cpp
+9
-8
objdetect_init.cpp
modules/objdetect/src/objdetect_init.cpp
+21
-3
softcascade.cpp
modules/objdetect/src/softcascade.cpp
+12
-20
test_softcascade.cpp
modules/objdetect/test/test_softcascade.cpp
+49
-46
No files found.
modules/objdetect/include/opencv2/objdetect/objdetect.hpp
View file @
4a1c4a98
...
@@ -488,52 +488,52 @@ protected:
...
@@ -488,52 +488,52 @@ protected:
Ptr
<
MaskGenerator
>
maskGenerator
;
Ptr
<
MaskGenerator
>
maskGenerator
;
};
};
/**
* \class SoftCascade
// Implementation of soft (stageless) cascaded detector.
* \brief Implement soft (stageless) cascade.
class
CV_EXPORTS
SCascade
:
public
Algorithm
*/
class
CV_EXPORTS
SoftCascade
{
{
public
:
public
:
/**
// Representation of detectors result.
* \class Detection
* \brief Soft cascade detector result represintation.
*/
struct
CV_EXPORTS
Detection
struct
CV_EXPORTS
Detection
{
{
// Default object type.
enum
{
PEDESTRIAN
=
1
};
enum
{
PEDESTRIAN
=
1
};
//! Create detection from an object bounding rectangle and confidence. Only PEDESTRIAN type carrently supported.
// Creates Detection from an object bounding box and confidence.
//! Param r is a boundinf rectangle
// Param b is a bounding box
//! param c is a confidence that object belongs to class k
// Param c is a confidence that object belongs to class k
//! Paral k is an object class
// Paral k is an object class
Detection
(
const
cv
::
Rect
&
b
,
const
float
c
,
int
k
=
PEDESTRIAN
)
:
bb
(
b
),
confidence
(
c
),
kind
(
k
)
{}
Detection
(
const
cv
::
Rect
&
r
,
const
float
c
,
int
k
=
PEDESTRIAN
)
:
rect
(
r
),
confidence
(
c
),
kind
(
k
)
{}
cv
::
Rect
bb
;
cv
::
Rect
rect
;
float
confidence
;
float
confidence
;
int
kind
;
int
kind
;
};
};
//! An empty cascade will be created.
// An empty cascade will be created.
//! Param minScale is a minimum scale relative to the original size of the image on which cascade will be applyed.
// Param minScale is a minimum scale relative to the original size of the image on which cascade will be applyed.
//! Param minScale is a maximum scale relative to the original size of the image on which cascade will be applyed.
// Param minScale is a maximum scale relative to the original size of the image on which cascade will be applyed.
//! Param scales is a number of scales from minScale to maxScale.
// Param scales is a number of scales from minScale to maxScale.
SoftCascade
(
const
float
minScale
=
0.4
f
,
const
float
maxScale
=
5.
f
,
const
int
scales
=
55
);
// Param rejfactor is used for NMS.
SCascade
(
const
float
minScale
=
0.4
f
,
const
float
maxScale
=
5.
f
,
const
int
scales
=
55
,
const
int
rejfactor
=
1
);
//! Cascade will be created for scales from minScale to maxScale.
virtual
~
SCascade
();
//! Param fs is a serialized sacsade.
SoftCascade
(
const
cv
::
FileStorage
&
fs
);
//! cascade will be loaded. The previous cascade will be destroyed.
cv
::
AlgorithmInfo
*
info
()
const
;
//! Param fs is a serialized sacsade.
bool
read
(
const
cv
::
FileStorage
&
fs
);
virtual
~
SoftCascade
();
// Load cascade from FileNode.
// Param fn is a root node for cascade. Should be <cascade>.
virtual
bool
load
(
const
FileNode
&
fn
);
//! return vector of bounding boxes. Each box contains one detected object
// Load cascade config.
virtual
void
detectMultiScale
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
rois
,
std
::
vector
<
Detection
>&
objects
,
virtual
void
read
(
const
FileNode
&
fn
);
int
rejectfactor
=
1
)
const
;
// Return the vector of Decection objcts.
// Param image is a frame on which detector will be applied.
// Param rois is a vector of regions of interest. Only the objects that fall into one of the regions will be returned.
// Param objects is an output array of Detections
virtual
void
detect
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
rois
,
std
::
vector
<
Detection
>&
objects
)
const
;
private
:
private
:
struct
Filds
;
struct
Filds
;
...
@@ -542,8 +542,11 @@ private:
...
@@ -542,8 +542,11 @@ private:
float
minScale
;
float
minScale
;
float
maxScale
;
float
maxScale
;
int
scales
;
int
scales
;
int
rejfactor
;
};
};
CV_EXPORTS
bool
initModule_objdetect
(
void
);
/**
/**
* \class IntegralChannels
* \class IntegralChannels
* \brief Create channel integrals for Soft Cascade detector.
* \brief Create channel integrals for Soft Cascade detector.
...
...
modules/objdetect/perf/perf_cascadeclassifier.cpp
View file @
4a1c4a98
...
@@ -58,35 +58,36 @@ typedef perf::TestBaseWithParam<fixture> detect;
...
@@ -58,35 +58,36 @@ typedef perf::TestBaseWithParam<fixture> detect;
namespace
{
namespace
{
typedef
cv
::
S
oft
Cascade
::
Detection
detection_t
;
typedef
cv
::
SCascade
::
Detection
detection_t
;
void
extractRacts
(
std
::
vector
<
detection_t
>
objectBoxes
,
vector
<
Rect
>
rects
)
void
extractRacts
(
std
::
vector
<
detection_t
>
objectBoxes
,
vector
<
Rect
>
rects
)
{
{
rects
.
clear
();
rects
.
clear
();
for
(
int
i
=
0
;
i
<
(
int
)
objectBoxes
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
(
int
)
objectBoxes
.
size
();
++
i
)
rects
.
push_back
(
objectBoxes
[
i
].
rect
);
rects
.
push_back
(
objectBoxes
[
i
].
bb
);
}
}
}
}
PERF_TEST_P
(
detect
,
S
oft
Cascade
,
PERF_TEST_P
(
detect
,
SCascade
,
testing
::
Combine
(
testing
::
Values
(
std
::
string
(
"cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml"
)),
testing
::
Combine
(
testing
::
Values
(
std
::
string
(
"cv/cascadeandhog/sc_cvpr_2012_to_opencv.xml"
)),
testing
::
Values
(
std
::
string
(
"cv/cascadeandhog/bahnhof/image_00000000_0.png"
))))
testing
::
Values
(
std
::
string
(
"cv/cascadeandhog/bahnhof/image_00000000_0.png"
))))
{
{
typedef
cv
::
S
oftCascade
::
Detection
detection_t
;
typedef
cv
::
S
Cascade
::
Detection
Detection
;
cv
::
Mat
colored
=
imread
(
getDataPath
(
get
<
1
>
(
GetParam
())));
cv
::
Mat
colored
=
imread
(
getDataPath
(
get
<
1
>
(
GetParam
())));
ASSERT_FALSE
(
colored
.
empty
());
ASSERT_FALSE
(
colored
.
empty
());
cv
::
S
oft
Cascade
cascade
;
cv
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
getDataPath
(
get
<
0
>
(
GetParam
())),
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
getDataPath
(
get
<
0
>
(
GetParam
())),
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
cascade
.
read
(
fs
));
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
std
::
vector
<
cv
::
Rect
>
rois
;
std
::
vector
<
cv
::
Rect
>
rois
;
std
::
vector
<
detection_t
>
objectBoxes
;
std
::
vector
<
detection_t
>
objectBoxes
;
cascade
.
detect
MultiScale
(
colored
,
rois
,
objectBoxes
);
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
TEST_CYCLE
()
TEST_CYCLE
()
{
{
cascade
.
detect
MultiScale
(
colored
,
rois
,
objectBoxes
);
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
}
}
vector
<
Rect
>
rects
;
vector
<
Rect
>
rects
;
...
...
modules/objdetect/src/objdetect_init.cpp
View file @
4a1c4a98
...
@@ -7,11 +7,11 @@
...
@@ -7,11 +7,11 @@
// copy or use the software.
// copy or use the software.
//
//
//
//
// License Agreement
//
License Agreement
// For Open Source Computer Vision Library
// For Open Source Computer Vision Library
//
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 200
9
, Willow Garage Inc., all rights reserved.
// Copyright (C) 200
8-2012
, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
// Third party copyrights are property of their respective owners.
//
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without modification,
...
@@ -40,4 +40,21 @@
...
@@ -40,4 +40,21 @@
//
//
//M*/
//M*/
#include "precomp.hpp"
#include <precomp.hpp>
namespace
cv
{
CV_INIT_ALGORITHM
(
SCascade
,
"CascadeDetector.SCascade"
,
obj
.
info
()
->
addParam
(
obj
,
"minScale"
,
obj
.
minScale
));
// obj.info()->addParam(obj, "maxScale", obj.maxScale);
// obj.info()->addParam(obj, "scales", obj.scales);
// obj.info()->addParam(obj, "rejfactor", obj.rejfactor));
bool
initModule_objdetect
(
void
)
{
Ptr
<
Algorithm
>
sc
=
createSCascade
();
return
sc
->
info
()
!=
0
;
}
}
\ No newline at end of file
modules/objdetect/src/softcascade.cpp
View file @
4a1c4a98
...
@@ -175,7 +175,7 @@ struct Level
...
@@ -175,7 +175,7 @@ struct Level
enum
{
R_SHIFT
=
1
<<
15
};
enum
{
R_SHIFT
=
1
<<
15
};
float
scaling
[
2
];
float
scaling
[
2
];
typedef
cv
::
S
oft
Cascade
::
Detection
detection_t
;
typedef
cv
::
SCascade
::
Detection
detection_t
;
Level
(
const
Octave
&
oct
,
const
float
scale
,
const
int
shrinkage
,
const
int
w
,
const
int
h
)
Level
(
const
Octave
&
oct
,
const
float
scale
,
const
int
shrinkage
,
const
int
w
,
const
int
h
)
:
octave
(
&
oct
),
origScale
(
scale
),
relScale
(
scale
/
oct
.
scale
),
:
octave
(
&
oct
),
origScale
(
scale
),
relScale
(
scale
/
oct
.
scale
),
...
@@ -252,7 +252,7 @@ struct ChannelStorage
...
@@ -252,7 +252,7 @@ struct ChannelStorage
}
}
struct
cv
::
S
oft
Cascade
::
Filds
struct
cv
::
SCascade
::
Filds
{
{
float
minScale
;
float
minScale
;
float
maxScale
;
float
maxScale
;
...
@@ -491,33 +491,25 @@ struct cv::SoftCascade::Filds
...
@@ -491,33 +491,25 @@ struct cv::SoftCascade::Filds
}
}
};
};
cv
::
S
oftCascade
::
SoftCascade
(
const
float
mins
,
const
float
maxs
,
const
int
nsc
)
cv
::
S
Cascade
::
SCascade
(
const
float
mins
,
const
float
maxs
,
const
int
nsc
,
const
int
rej
)
:
filds
(
0
),
minScale
(
mins
),
maxScale
(
maxs
),
scales
(
nsc
)
{}
:
filds
(
0
),
minScale
(
mins
),
maxScale
(
maxs
),
scales
(
nsc
)
,
rejfactor
(
rej
)
{}
cv
::
SoftCascade
::
SoftCascade
(
const
cv
::
FileStorage
&
fs
)
:
filds
(
0
)
cv
::
SCascade
::~
SCascade
()
{
delete
filds
;}
{
read
(
fs
);
void
cv
::
SCascade
::
read
(
const
FileNode
&
fn
)
}
cv
::
SoftCascade
::~
SoftCascade
()
{
{
delete
filds
;
Algorithm
::
read
(
fn
)
;
}
}
bool
cv
::
S
oftCascade
::
read
(
const
cv
::
FileStorage
&
fs
)
bool
cv
::
S
Cascade
::
load
(
const
FileNode
&
fn
)
{
{
if
(
!
fs
.
isOpened
())
return
false
;
if
(
filds
)
delete
filds
;
if
(
filds
)
delete
filds
;
filds
=
0
;
filds
=
new
Filds
;
filds
=
new
Filds
;
Filds
&
flds
=
*
filds
;
return
filds
->
fill
(
fn
,
minScale
,
maxScale
);
return
flds
.
fill
(
fs
.
getFirstTopLevelNode
(),
minScale
,
maxScale
);
}
}
void
cv
::
SoftCascade
::
detectMultiScale
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
/*rois*/
,
void
cv
::
SCascade
::
detect
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
/*rois*/
,
std
::
vector
<
Detection
>&
objects
)
const
std
::
vector
<
Detection
>&
objects
,
const
int
/*rejectfactor*/
)
const
{
{
// only color images are supperted
// only color images are supperted
CV_Assert
(
image
.
type
()
==
CV_8UC3
);
CV_Assert
(
image
.
type
()
==
CV_8UC3
);
...
...
modules/objdetect/test/test_softcascade.cpp
View file @
4a1c4a98
/*M///////////////////////////////////////////////////////////////////////////////////////
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
//
// By downloading, copying, installing or using the software you agree to this license.
//
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,
//
If you do not agree to this license, do not download, install,
// copy or use the software.
//
copy or use the software.
//
//
//
//
// License Agreement
//
License Agreement
// For Open Source Computer Vision Library
//
For Open Source Computer Vision Library
//
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2008-201
1
, Willow Garage Inc., all rights reserved.
// Copyright (C) 2008-201
2
, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
// Third party copyrights are property of their respective owners.
//
//
// Redistribution and use in source and binary forms, with or without modification,
// Redistribution and use in source and binary forms, with or without modification,
// are permitted provided that the following conditions are met:
// are permitted provided that the following conditions are met:
//
//
//
* Redistribution
s of source code must retain the above copyright notice,
//
* Redistribution'
s of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
this list of conditions and the following disclaimer.
//
//
//
* Redistribution
s in binary form must reproduce the above copyright notice,
//
* Redistribution'
s in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
//
this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
and/or other materials provided with the distribution.
//
//
// * The name of the copyright holders may not be used to endorse or promote products
//
* The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
//
derived from this software without specific prior written permission.
//
//
// This software is provided by the copyright holders and contributors "as is" and
// 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
// any express or implied warranties, including, but not limited to, the implied
...
@@ -37,60 +37,62 @@
...
@@ -37,60 +37,62 @@
// and on any theory of liability, whether in contract, strict liability,
// and on any theory of liability, whether in contract, strict liability,
// or tort (including negligence or otherwise) arising in any way out of
// 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.
// the use of this software, even if advised of the possibility of such damage.
//
//M*/
//M*/
#include "test_precomp.hpp"
#include "test_precomp.hpp"
TEST
(
S
oft
Cascade
,
readCascade
)
TEST
(
SCascade
,
readCascade
)
{
{
std
::
string
xml
=
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/icf-template.xml"
;
std
::
string
xml
=
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/icf-template.xml"
;
cv
::
S
oft
Cascade
cascade
;
cv
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
cascade
.
read
(
fs
));
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
}
}
TEST
(
S
oft
Cascade
,
detect
)
TEST
(
SCascade
,
detect
)
{
{
typedef
cv
::
S
oftCascade
::
Detection
detection_t
;
typedef
cv
::
S
Cascade
::
Detection
Detection
;
std
::
string
xml
=
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/sc_cvpr_2012_to_opencv.xml"
;
std
::
string
xml
=
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/sc_cvpr_2012_to_opencv.xml"
;
cv
::
S
oft
Cascade
cascade
;
cv
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
cascade
.
read
(
fs
));
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()
));
cv
::
Mat
colored
=
cv
::
imread
(
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/bahnhof/image_00000000_0.png"
);
cv
::
Mat
colored
=
cv
::
imread
(
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/bahnhof/image_00000000_0.png"
);
ASSERT_FALSE
(
colored
.
empty
());
ASSERT_FALSE
(
colored
.
empty
());
std
::
vector
<
detection_t
>
objects
;
std
::
vector
<
Detection
>
objects
;
std
::
vector
<
cv
::
Rect
>
rois
;
std
::
vector
<
cv
::
Rect
>
rois
;
rois
.
push_back
(
cv
::
Rect
(
0
,
0
,
640
,
480
));
rois
.
push_back
(
cv
::
Rect
(
0
,
0
,
640
,
480
));
cascade
.
detect
MultiScale
(
colored
,
rois
,
objects
);
cascade
.
detect
(
colored
,
rois
,
objects
);
//
cv::Mat out = colored.clone();
cv
::
Mat
out
=
colored
.
clone
();
//
int level = 0, total = 0;
int
level
=
0
,
total
=
0
;
// int levelWidth = objects[0].rect
.width;
int
levelWidth
=
objects
[
0
].
bb
.
width
;
//
for(int i = 0 ; i < (int)objects.size(); ++i)
for
(
int
i
=
0
;
i
<
(
int
)
objects
.
size
();
++
i
)
//
{
{
// if (objects[i].rect
.width != levelWidth)
if
(
objects
[
i
].
bb
.
width
!=
levelWidth
)
//
{
{
//
std::cout << "Level: " << level << " total " << total << std::endl;
std
::
cout
<<
"Level: "
<<
level
<<
" total "
<<
total
<<
std
::
endl
;
//
cv::imshow("out", out);
cv
::
imshow
(
"out"
,
out
);
//
cv::waitKey(0);
cv
::
waitKey
(
0
);
//
out = colored.clone();
out
=
colored
.
clone
();
// levelWidth = objects[i].rect
.width;
levelWidth
=
objects
[
i
].
bb
.
width
;
//
total = 0;
total
=
0
;
//
level++;
level
++
;
//
}
}
// cv::rectangle(out, objects[i].rect
, cv::Scalar(255, 0, 0, 255), 1);
cv
::
rectangle
(
out
,
objects
[
i
].
bb
,
cv
::
Scalar
(
255
,
0
,
0
,
255
),
1
);
// std::cout << "detection: " << objects[i].rect
.x
std
::
cout
<<
"detection: "
<<
objects
[
i
].
bb
.
x
// << " " << objects[i].rect
.y
<<
" "
<<
objects
[
i
].
bb
.
y
// << " " << objects[i].rect
.width
<<
" "
<<
objects
[
i
].
bb
.
width
// << " " << objects[i].rect
.height << std::endl;
<<
" "
<<
objects
[
i
].
bb
.
height
<<
std
::
endl
;
//
total++;
total
++
;
//
}
}
//
std::cout << "detected: " << (int)objects.size() << std::endl;
std
::
cout
<<
"detected: "
<<
(
int
)
objects
.
size
()
<<
std
::
endl
;
ASSERT_EQ
((
int
)
objects
.
size
(),
3668
);
ASSERT_EQ
((
int
)
objects
.
size
(),
3668
);
}
}
\ No newline at end of file
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