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:
Ptr
<
MaskGenerator
>
maskGenerator
;
};
/**
* \class SoftCascade
* \brief Implement soft (stageless) cascade.
*/
class
CV_EXPORTS
SoftCascade
// Implementation of soft (stageless) cascaded detector.
class
CV_EXPORTS
SCascade
:
public
Algorithm
{
public
:
/**
* \class Detection
* \brief Soft cascade detector result represintation.
*/
// Representation of detectors result.
struct
CV_EXPORTS
Detection
{
// Default object type.
enum
{
PEDESTRIAN
=
1
};
//! Create detection from an object bounding rectangle and confidence. Only PEDESTRIAN type carrently supported.
//! Param r is a boundinf rectangle
//! param c is a confidence that object belongs to class k
//! Paral k is an object class
// Creates Detection from an object bounding box and confidence.
// Param b is a bounding box
// Param c is a confidence that object belongs to class k
// 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
rect
;
cv
::
Rect
bb
;
float
confidence
;
int
kind
;
};
//! 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 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.
SoftCascade
(
const
float
minScale
=
0.4
f
,
const
float
maxScale
=
5.
f
,
const
int
scales
=
55
);
// 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 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 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.
//! Param fs is a serialized sacsade.
SoftCascade
(
const
cv
::
FileStorage
&
fs
);
virtual
~
SCascade
();
//! cascade will be loaded. The previous cascade will be destroyed.
//! Param fs is a serialized sacsade.
bool
read
(
const
cv
::
FileStorage
&
fs
);
cv
::
AlgorithmInfo
*
info
()
const
;
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
virtual
void
detectMultiScale
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
rois
,
std
::
vector
<
Detection
>&
objects
,
int
rejectfactor
=
1
)
const
;
// Load cascade config.
virtual
void
read
(
const
FileNode
&
fn
);
// 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
:
struct
Filds
;
...
...
@@ -542,8 +542,11 @@ private:
float
minScale
;
float
maxScale
;
int
scales
;
int
rejfactor
;
};
CV_EXPORTS
bool
initModule_objdetect
(
void
);
/**
* \class IntegralChannels
* \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;
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
)
{
rects
.
clear
();
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
::
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
())));
ASSERT_FALSE
(
colored
.
empty
());
cv
::
S
oft
Cascade
cascade
;
cv
::
SCascade
cascade
;
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
<
detection_t
>
objectBoxes
;
cascade
.
detect
MultiScale
(
colored
,
rois
,
objectBoxes
);
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
TEST_CYCLE
()
{
cascade
.
detect
MultiScale
(
colored
,
rois
,
objectBoxes
);
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
}
vector
<
Rect
>
rects
;
...
...
modules/objdetect/src/objdetect_init.cpp
View file @
4a1c4a98
...
...
@@ -7,11 +7,11 @@
// copy or use the software.
//
//
// License Agreement
//
License Agreement
// For Open Source Computer Vision Library
//
// 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.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -40,4 +40,21 @@
//
//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
enum
{
R_SHIFT
=
1
<<
15
};
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
)
:
octave
(
&
oct
),
origScale
(
scale
),
relScale
(
scale
/
oct
.
scale
),
...
...
@@ -252,7 +252,7 @@ struct ChannelStorage
}
struct
cv
::
S
oft
Cascade
::
Filds
struct
cv
::
SCascade
::
Filds
{
float
minScale
;
float
maxScale
;
...
...
@@ -491,33 +491,25 @@ struct cv::SoftCascade::Filds
}
};
cv
::
S
oftCascade
::
SoftCascade
(
const
float
mins
,
const
float
maxs
,
const
int
nsc
)
:
filds
(
0
),
minScale
(
mins
),
maxScale
(
maxs
),
scales
(
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
)
,
rejfactor
(
rej
)
{}
cv
::
SoftCascade
::
SoftCascade
(
const
cv
::
FileStorage
&
fs
)
:
filds
(
0
)
{
read
(
fs
);
}
cv
::
SoftCascade
::~
SoftCascade
()
cv
::
SCascade
::~
SCascade
()
{
delete
filds
;}
void
cv
::
SCascade
::
read
(
const
FileNode
&
fn
)
{
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
;
filds
=
0
;
if
(
filds
)
delete
filds
;
filds
=
new
Filds
;
Filds
&
flds
=
*
filds
;
return
flds
.
fill
(
fs
.
getFirstTopLevelNode
(),
minScale
,
maxScale
);
return
filds
->
fill
(
fn
,
minScale
,
maxScale
);
}
void
cv
::
SoftCascade
::
detectMultiScale
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
/*rois*/
,
std
::
vector
<
Detection
>&
objects
,
const
int
/*rejectfactor*/
)
const
void
cv
::
SCascade
::
detect
(
const
Mat
&
image
,
const
std
::
vector
<
cv
::
Rect
>&
/*rois*/
,
std
::
vector
<
Detection
>&
objects
)
const
{
// only color images are supperted
CV_Assert
(
image
.
type
()
==
CV_8UC3
);
...
...
modules/objdetect/test/test_softcascade.cpp
View file @
4a1c4a98
/*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.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
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
//
License Agreement
//
For Open Source Computer Vision Library
//
// 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.
//
// 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 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.
//
* 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.
//
* 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
...
...
@@ -37,60 +37,62 @@
// 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 "test_precomp.hpp"
TEST
(
S
oft
Cascade
,
readCascade
)
TEST
(
SCascade
,
readCascade
)
{
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
);
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"
;
cv
::
S
oft
Cascade
cascade
;
cv
::
SCascade
cascade
;
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"
);
ASSERT_FALSE
(
colored
.
empty
());
std
::
vector
<
detection_t
>
objects
;
std
::
vector
<
Detection
>
objects
;
std
::
vector
<
cv
::
Rect
>
rois
;
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();
//
int level = 0, total = 0;
// int levelWidth = objects[0].rect
.width;
cv
::
Mat
out
=
colored
.
clone
();
int
level
=
0
,
total
=
0
;
int
levelWidth
=
objects
[
0
].
bb
.
width
;
//
for(int i = 0 ; i < (int)objects.size(); ++i)
//
{
// if (objects[i].rect
.width != levelWidth)
//
{
//
std::cout << "Level: " << level << " total " << total << std::endl;
//
cv::imshow("out", out);
//
cv::waitKey(0);
//
out = colored.clone();
// levelWidth = objects[i].rect
.width;
//
total = 0;
//
level++;
//
}
// cv::rectangle(out, objects[i].rect
, cv::Scalar(255, 0, 0, 255), 1);
// std::cout << "detection: " << objects[i].rect
.x
// << " " << objects[i].rect
.y
// << " " << objects[i].rect
.width
// << " " << objects[i].rect
.height << std::endl;
//
total++;
//
}
//
std::cout << "detected: " << (int)objects.size() << std::endl;
for
(
int
i
=
0
;
i
<
(
int
)
objects
.
size
();
++
i
)
{
if
(
objects
[
i
].
bb
.
width
!=
levelWidth
)
{
std
::
cout
<<
"Level: "
<<
level
<<
" total "
<<
total
<<
std
::
endl
;
cv
::
imshow
(
"out"
,
out
);
cv
::
waitKey
(
0
);
out
=
colored
.
clone
();
levelWidth
=
objects
[
i
].
bb
.
width
;
total
=
0
;
level
++
;
}
cv
::
rectangle
(
out
,
objects
[
i
].
bb
,
cv
::
Scalar
(
255
,
0
,
0
,
255
),
1
);
std
::
cout
<<
"detection: "
<<
objects
[
i
].
bb
.
x
<<
" "
<<
objects
[
i
].
bb
.
y
<<
" "
<<
objects
[
i
].
bb
.
width
<<
" "
<<
objects
[
i
].
bb
.
height
<<
std
::
endl
;
total
++
;
}
std
::
cout
<<
"detected: "
<<
(
int
)
objects
.
size
()
<<
std
::
endl
;
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