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
d8513d62
Commit
d8513d62
authored
Dec 12, 2013
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
continue adding OpenCL optimization to cascade classifier
parent
302a5adc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
273 additions
and
116 deletions
+273
-116
objdetect.hpp
modules/objdetect/include/opencv2/objdetect.hpp
+8
-5
cascadedetect.cpp
modules/objdetect/src/cascadedetect.cpp
+210
-76
cascadedetect.hpp
modules/objdetect/src/cascadedetect.hpp
+55
-35
No files found.
modules/objdetect/include/opencv2/objdetect.hpp
View file @
d8513d62
...
@@ -111,12 +111,15 @@ public:
...
@@ -111,12 +111,15 @@ public:
};
};
CV_EXPORTS
void
groupRectangles
(
std
::
vector
<
Rect
>&
rectList
,
int
groupThreshold
,
double
eps
=
0.2
);
CV_EXPORTS
void
groupRectangles
(
std
::
vector
<
Rect
>&
rectList
,
int
groupThreshold
,
double
eps
=
0.2
);
CV_EXPORTS_W
void
groupRectangles
(
CV_IN_OUT
std
::
vector
<
Rect
>&
rectList
,
CV_OUT
std
::
vector
<
int
>&
weights
,
int
groupThreshold
,
double
eps
=
0.2
);
CV_EXPORTS_W
void
groupRectangles
(
CV_IN_OUT
std
::
vector
<
Rect
>&
rectList
,
CV_OUT
std
::
vector
<
int
>&
weights
,
CV_EXPORTS
void
groupRectangles
(
std
::
vector
<
Rect
>&
rectList
,
int
groupThreshold
,
double
eps
,
std
::
vector
<
int
>*
weights
,
std
::
vector
<
double
>*
levelWeights
);
int
groupThreshold
,
double
eps
=
0.2
);
CV_EXPORTS
void
groupRectangles
(
std
::
vector
<
Rect
>&
rectList
,
int
groupThreshold
,
double
eps
,
std
::
vector
<
int
>*
weights
,
std
::
vector
<
double
>*
levelWeights
);
CV_EXPORTS
void
groupRectangles
(
std
::
vector
<
Rect
>&
rectList
,
std
::
vector
<
int
>&
rejectLevels
,
CV_EXPORTS
void
groupRectangles
(
std
::
vector
<
Rect
>&
rectList
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
int
groupThreshold
,
double
eps
=
0.2
);
std
::
vector
<
double
>&
levelWeights
,
int
groupThreshold
,
double
eps
=
0.2
);
CV_EXPORTS
void
groupRectangles_meanshift
(
std
::
vector
<
Rect
>&
rectList
,
std
::
vector
<
double
>&
foundWeights
,
std
::
vector
<
double
>&
foundScales
,
CV_EXPORTS
void
groupRectangles_meanshift
(
std
::
vector
<
Rect
>&
rectList
,
std
::
vector
<
double
>&
foundWeights
,
double
detectThreshold
=
0.0
,
Size
winDetSize
=
Size
(
64
,
128
));
std
::
vector
<
double
>&
foundScales
,
double
detectThreshold
=
0.0
,
Size
winDetSize
=
Size
(
64
,
128
));
class
CV_EXPORTS
FeatureEvaluator
class
CV_EXPORTS
FeatureEvaluator
{
{
...
@@ -132,7 +135,7 @@ public:
...
@@ -132,7 +135,7 @@ public:
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
int
getFeatureType
()
const
;
virtual
int
getFeatureType
()
const
;
virtual
bool
setImage
(
const
Mat
&
img
,
Size
origWinSize
);
virtual
bool
setImage
(
InputArray
img
,
Size
origWinSize
);
virtual
bool
setWindow
(
Point
p
);
virtual
bool
setWindow
(
Point
p
);
virtual
double
calcOrd
(
int
featureIdx
)
const
;
virtual
double
calcOrd
(
int
featureIdx
)
const
;
...
...
modules/objdetect/src/cascadedetect.cpp
View file @
d8513d62
...
@@ -7,10 +7,10 @@
...
@@ -7,10 +7,10 @@
// copy or use the software.
// copy or use the software.
//
//
//
//
//
Intel
License Agreement
//
License Agreement
// For Open Source Computer Vision Library
// For Open Source Computer Vision Library
//
//
// Copyright (C) 200
0, Intel Corporation
, all rights reserved.
// Copyright (C) 200
8-2013, Itseez 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,
...
@@ -23,13 +23,13 @@
...
@@ -23,13 +23,13 @@
// 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 I
ntel Corporation
may not be used to endorse or promote products
// * The name of I
tseez Inc.
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
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// warranties of merchantability and fitness for a particular purpose are disclaimed.
// In no event shall the
Intel Corporation
or contributors be liable for any direct,
// In no event shall the
copyright holders
or contributors be liable for any direct,
// indirect, incidental, special, exemplary, or consequential damages
// indirect, incidental, special, exemplary, or consequential damages
// (including, but not limited to, procurement of substitute goods or services;
// (including, but not limited to, procurement of substitute goods or services;
// loss of use, data, or profits; or business interruption) however caused
// loss of use, data, or profits; or business interruption) however caused
...
@@ -434,7 +434,7 @@ FeatureEvaluator::~FeatureEvaluator() {}
...
@@ -434,7 +434,7 @@ FeatureEvaluator::~FeatureEvaluator() {}
bool
FeatureEvaluator
::
read
(
const
FileNode
&
)
{
return
true
;}
bool
FeatureEvaluator
::
read
(
const
FileNode
&
)
{
return
true
;}
Ptr
<
FeatureEvaluator
>
FeatureEvaluator
::
clone
()
const
{
return
Ptr
<
FeatureEvaluator
>
();
}
Ptr
<
FeatureEvaluator
>
FeatureEvaluator
::
clone
()
const
{
return
Ptr
<
FeatureEvaluator
>
();
}
int
FeatureEvaluator
::
getFeatureType
()
const
{
return
-
1
;}
int
FeatureEvaluator
::
getFeatureType
()
const
{
return
-
1
;}
bool
FeatureEvaluator
::
setImage
(
const
Mat
&
,
Size
)
{
return
true
;}
bool
FeatureEvaluator
::
setImage
(
InputArray
,
Size
)
{
return
true
;}
bool
FeatureEvaluator
::
setWindow
(
Point
)
{
return
true
;
}
bool
FeatureEvaluator
::
setWindow
(
Point
)
{
return
true
;
}
double
FeatureEvaluator
::
calcOrd
(
int
)
const
{
return
0.
;
}
double
FeatureEvaluator
::
calcOrd
(
int
)
const
{
return
0.
;
}
int
FeatureEvaluator
::
calcCat
(
int
)
const
{
return
0
;
}
int
FeatureEvaluator
::
calcCat
(
int
)
const
{
return
0
;
}
...
@@ -466,7 +466,9 @@ bool HaarEvaluator::Feature :: read( const FileNode& node )
...
@@ -466,7 +466,9 @@ bool HaarEvaluator::Feature :: read( const FileNode& node )
HaarEvaluator
::
HaarEvaluator
()
HaarEvaluator
::
HaarEvaluator
()
{
{
features
=
makePtr
<
std
::
vector
<
Feature
>
>
();
optfeaturesPtr
=
0
;
pwin
=
0
;
pqwin
=
0
;
}
}
HaarEvaluator
::~
HaarEvaluator
()
HaarEvaluator
::~
HaarEvaluator
()
{
{
...
@@ -476,16 +478,16 @@ bool HaarEvaluator::read(const FileNode& node)
...
@@ -476,16 +478,16 @@ bool HaarEvaluator::read(const FileNode& node)
{
{
size_t
i
,
n
=
node
.
size
();
size_t
i
,
n
=
node
.
size
();
CV_Assert
(
n
>
0
);
CV_Assert
(
n
>
0
);
features
.
resize
(
n
);
features
->
resize
(
n
);
featuresPtr
=
&
features
[
0
];
FileNodeIterator
it
=
node
.
begin
();
FileNodeIterator
it
=
node
.
begin
();
hasTiltedFeatures
=
false
;
hasTiltedFeatures
=
false
;
std
::
vector
<
Feature
>
ff
=
*
features
;
for
(
i
=
0
;
i
<
n
;
i
++
,
++
it
)
for
(
i
=
0
;
i
<
n
;
i
++
,
++
it
)
{
{
if
(
!
f
eatures
[
i
].
read
(
*
it
))
if
(
!
f
f
[
i
].
read
(
*
it
))
return
false
;
return
false
;
if
(
f
eatures
[
i
].
tilted
)
if
(
f
f
[
i
].
tilted
)
hasTiltedFeatures
=
true
;
hasTiltedFeatures
=
true
;
}
}
return
true
;
return
true
;
...
@@ -496,55 +498,60 @@ Ptr<FeatureEvaluator> HaarEvaluator::clone() const
...
@@ -496,55 +498,60 @@ Ptr<FeatureEvaluator> HaarEvaluator::clone() const
Ptr
<
HaarEvaluator
>
ret
=
makePtr
<
HaarEvaluator
>
();
Ptr
<
HaarEvaluator
>
ret
=
makePtr
<
HaarEvaluator
>
();
ret
->
origWinSize
=
origWinSize
;
ret
->
origWinSize
=
origWinSize
;
ret
->
features
=
features
;
ret
->
features
=
features
;
ret
->
optfeatures
=
optfeatures
;
ret
->
optfeaturesPtr
=
optfeatures
->
empty
()
?
0
:
&
(
*
(
ret
->
optfeatures
))[
0
];
ret
->
hasTiltedFeatures
=
hasTiltedFeatures
;
ret
->
hasTiltedFeatures
=
hasTiltedFeatures
;
ret
->
sum0
=
sum0
,
ret
->
sqsum0
=
sqsum0
,
ret
->
tilted0
=
tilted
0
;
ret
->
sum0
=
sum0
;
ret
->
sqsum0
=
sqsum
0
;
ret
->
sum
=
sum
,
ret
->
sqsum
=
sqsum
,
ret
->
tilted
=
tilted
;
ret
->
sum
=
sum
;
ret
->
sqsum
=
sqsum
;
ret
->
tilted
=
tilted
;
ret
->
normrect
=
normrect
;
ret
->
normrect
=
normrect
;
memcpy
(
ret
->
p
,
p
,
4
*
sizeof
(
p
[
0
])
);
memcpy
(
ret
->
nofs
,
nofs
,
4
*
sizeof
(
nofs
[
0
])
);
memcpy
(
ret
->
pq
,
pq
,
4
*
sizeof
(
pq
[
0
])
);
memcpy
(
ret
->
nqofs
,
nqofs
,
4
*
sizeof
(
nqofs
[
0
])
);
ret
->
offset
=
offset
;
ret
->
pwin
=
pwin
;
ret
->
pqwin
=
pqwin
;
ret
->
varianceNormFactor
=
varianceNormFactor
;
ret
->
varianceNormFactor
=
varianceNormFactor
;
return
ret
;
return
ret
;
}
}
bool
HaarEvaluator
::
setImage
(
const
Mat
&
image
,
Size
_origWinSize
)
bool
HaarEvaluator
::
setImage
(
InputArray
_
image
,
Size
_origWinSize
)
{
{
int
rn
=
image
.
rows
+
1
,
cn
=
image
.
cols
+
1
;
Size
imgsz
=
_image
.
size
();
int
rn
=
imgsz
.
height
+
1
,
cn
=
imgsz
.
width
+
1
,
rnt
=
rn
;
origWinSize
=
_origWinSize
;
origWinSize
=
_origWinSize
;
normrect
=
Rect
(
1
,
1
,
origWinSize
.
width
-
2
,
origWinSize
.
height
-
2
);
normrect
=
Rect
(
1
,
1
,
origWinSize
.
width
-
2
,
origWinSize
.
height
-
2
);
if
(
im
age
.
cols
<
origWinSize
.
width
||
image
.
rows
<
origWinSize
.
height
)
if
(
im
gsz
.
width
<
origWinSize
.
width
||
imgsz
.
height
<
origWinSize
.
height
)
return
false
;
return
false
;
if
(
sum0
.
rows
<
rn
||
sum0
.
cols
<
cn
)
if
(
hasTiltedFeatures
)
rnt
=
rn
*
2
;
if
(
sum0
.
rows
<
rnt
||
sum0
.
cols
<
cn
)
{
{
sum0
.
create
(
rn
,
cn
,
CV_32S
);
sum0
.
create
(
rn
t
,
cn
,
CV_32S
);
sqsum0
.
create
(
rn
,
cn
,
CV_64F
);
sqsum0
.
create
(
rn
,
cn
,
CV_64F
);
if
(
hasTiltedFeatures
)
tilted0
.
create
(
rn
,
cn
,
CV_32S
);
}
}
sum
=
Mat
(
rn
,
cn
,
CV_32S
,
sum0
.
data
);
sum
=
Mat
(
rn
,
cn
,
CV_32S
,
sum0
.
data
);
sqsum
=
Mat
(
rn
,
cn
,
CV_64F
,
sqsum0
.
data
);
sqsum
=
Mat
(
rn
,
cn
,
CV_64F
,
sqsum0
.
data
);
if
(
hasTiltedFeatures
)
if
(
hasTiltedFeatures
)
{
{
tilted
=
Mat
(
rn
,
cn
,
CV_32S
,
tilted0
.
data
);
tilted
=
Mat
(
rn
,
cn
,
CV_32S
,
sum0
.
data
+
rn
*
sum
.
step
);
integral
(
image
,
sum
,
sqsum
,
tilted
);
integral
(
_
image
,
sum
,
sqsum
,
tilted
);
}
}
else
else
integral
(
image
,
sum
,
sqsum
);
integral
(
_image
,
sum
,
sqsum
);
const
int
*
sdata
=
(
const
int
*
)
sum
.
data
;
int
sumStep
=
(
int
)(
sum
.
step
/
sum
.
elemSize
());
const
double
*
sqdata
=
(
const
double
*
)
sqsum
.
data
;
int
sqsumStep
=
(
int
)(
sqsum
.
step
/
sqsum
.
elemSize
());
size_t
sumStep
=
sum
.
step
/
sizeof
(
sdata
[
0
]);
int
tofs
=
hasTiltedFeatures
?
sumStep
*
rn
:
0
;
size_t
sqsumStep
=
sqsum
.
step
/
sizeof
(
sqdata
[
0
]);
CV_SUM_
PTRS
(
p
[
0
],
p
[
1
],
p
[
2
],
p
[
3
],
sdata
,
normrect
,
sumStep
);
CV_SUM_
OFS
(
nofs
[
0
],
nofs
[
1
],
nofs
[
2
],
nofs
[
3
],
0
,
normrect
,
sumStep
);
CV_SUM_
PTRS
(
pq
[
0
],
pq
[
1
],
pq
[
2
],
pq
[
3
],
sqdata
,
normrect
,
sqsumStep
);
CV_SUM_
OFS
(
nqofs
[
0
],
nqofs
[
1
],
nqofs
[
2
],
nqofs
[
3
],
0
,
normrect
,
sqsumStep
);
size_t
fi
,
nfeatures
=
features
.
size
();
size_t
fi
,
nfeatures
=
features
->
size
();
optfeatures
->
resize
(
nfeatures
);
optfeaturesPtr
=
&
(
*
optfeatures
)[
0
];
const
std
::
vector
<
Feature
>&
ff
=
*
features
;
for
(
fi
=
0
;
fi
<
nfeatures
;
fi
++
)
for
(
fi
=
0
;
fi
<
nfeatures
;
fi
++
)
optfeaturesPtr
[
fi
].
updatePtrs
(
!
featuresPtr
[
fi
].
tilted
?
sum
:
tilted
);
optfeaturesPtr
[
fi
].
setOffsets
(
ff
[
fi
],
sumStep
,
tofs
);
return
true
;
return
true
;
}
}
...
@@ -555,10 +562,10 @@ bool HaarEvaluator::setWindow( Point pt )
...
@@ -555,10 +562,10 @@ bool HaarEvaluator::setWindow( Point pt )
pt
.
y
+
origWinSize
.
height
>=
sum
.
rows
)
pt
.
y
+
origWinSize
.
height
>=
sum
.
rows
)
return
false
;
return
false
;
size_t
pOffset
=
pt
.
y
*
(
sum
.
step
/
sizeof
(
int
))
+
pt
.
x
;
const
int
*
p
=
&
sum
.
at
<
int
>
(
pt
)
;
size_t
pqOffset
=
pt
.
y
*
(
sqsum
.
step
/
sizeof
(
double
))
+
pt
.
x
;
const
double
*
pq
=
&
sqsum
.
at
<
double
>
(
pt
)
;
int
valsum
=
CALC_SUM
(
p
,
pOffset
);
int
valsum
=
CALC_SUM
_OFS
(
nofs
,
p
);
double
valsqsum
=
CALC_SUM
(
pq
,
pqOffset
);
double
valsqsum
=
CALC_SUM
_OFS
(
nqofs
,
pq
);
double
nf
=
(
double
)
normrect
.
area
()
*
valsqsum
-
(
double
)
valsum
*
valsum
;
double
nf
=
(
double
)
normrect
.
area
()
*
valsqsum
-
(
double
)
valsum
*
valsum
;
if
(
nf
>
0.
)
if
(
nf
>
0.
)
...
@@ -566,7 +573,7 @@ bool HaarEvaluator::setWindow( Point pt )
...
@@ -566,7 +573,7 @@ bool HaarEvaluator::setWindow( Point pt )
else
else
nf
=
1.
;
nf
=
1.
;
varianceNormFactor
=
1.
/
nf
;
varianceNormFactor
=
1.
/
nf
;
offset
=
(
int
)
pOffset
;
pwin
=
p
;
return
true
;
return
true
;
}
}
...
@@ -613,8 +620,9 @@ Ptr<FeatureEvaluator> LBPEvaluator::clone() const
...
@@ -613,8 +620,9 @@ Ptr<FeatureEvaluator> LBPEvaluator::clone() const
return
ret
;
return
ret
;
}
}
bool
LBPEvaluator
::
setImage
(
const
Mat
&
image
,
Size
_origWinSize
)
bool
LBPEvaluator
::
setImage
(
InputArray
_
image
,
Size
_origWinSize
)
{
{
Mat
image
=
_image
.
getMat
();
int
rn
=
image
.
rows
+
1
,
cn
=
image
.
cols
+
1
;
int
rn
=
image
.
rows
+
1
,
cn
=
image
.
cols
+
1
;
origWinSize
=
_origWinSize
;
origWinSize
=
_origWinSize
;
...
@@ -694,8 +702,9 @@ Ptr<FeatureEvaluator> HOGEvaluator::clone() const
...
@@ -694,8 +702,9 @@ Ptr<FeatureEvaluator> HOGEvaluator::clone() const
return
ret
;
return
ret
;
}
}
bool
HOGEvaluator
::
setImage
(
const
Mat
&
image
,
Size
winSize
)
bool
HOGEvaluator
::
setImage
(
InputArray
_
image
,
Size
winSize
)
{
{
Mat
image
=
_image
.
getMat
();
int
rows
=
image
.
rows
+
1
;
int
rows
=
image
.
rows
+
1
;
int
cols
=
image
.
cols
+
1
;
int
cols
=
image
.
cols
+
1
;
origWinSize
=
winSize
;
origWinSize
=
winSize
;
...
@@ -1011,11 +1020,11 @@ struct getRect { Rect operator ()(const CvAvgComp& e) const { return e.rect; } }
...
@@ -1011,11 +1020,11 @@ struct getRect { Rect operator ()(const CvAvgComp& e) const { return e.rect; } }
struct
getNeighbors
{
int
operator
()(
const
CvAvgComp
&
e
)
const
{
return
e
.
neighbors
;
}
};
struct
getNeighbors
{
int
operator
()(
const
CvAvgComp
&
e
)
const
{
return
e
.
neighbors
;
}
};
bool
CascadeClassifierImpl
::
detectSingleScale
(
const
Mat
&
image
,
int
stripCount
,
Size
processingRectSize
,
bool
CascadeClassifierImpl
::
detectSingleScale
(
InputArray
_image
,
Size
processingRectSize
,
int
stripSize
,
int
yStep
,
double
factor
,
std
::
vector
<
Rect
>&
candidates
,
int
yStep
,
double
factor
,
std
::
vector
<
Rect
>&
candidates
,
std
::
vector
<
int
>&
levels
,
std
::
vector
<
double
>&
weights
,
bool
outputRejectLevels
)
std
::
vector
<
int
>&
levels
,
std
::
vector
<
double
>&
weights
,
bool
outputRejectLevels
)
{
{
if
(
!
featureEvaluator
->
setImage
(
image
,
data
.
origWinSize
)
)
if
(
!
featureEvaluator
->
setImage
(
_
image
,
data
.
origWinSize
)
)
return
false
;
return
false
;
#if defined (LOG_CASCADE_STATISTIC)
#if defined (LOG_CASCADE_STATISTIC)
...
@@ -1024,13 +1033,21 @@ bool CascadeClassifierImpl::detectSingleScale( const Mat& image, int stripCount,
...
@@ -1024,13 +1033,21 @@ bool CascadeClassifierImpl::detectSingleScale( const Mat& image, int stripCount,
Mat
currentMask
;
Mat
currentMask
;
if
(
maskGenerator
)
{
if
(
maskGenerator
)
{
Mat
image
=
_image
.
getMat
();
currentMask
=
maskGenerator
->
generateMask
(
image
);
currentMask
=
maskGenerator
->
generateMask
(
image
);
}
}
std
::
vector
<
Rect
>
candidatesVector
;
std
::
vector
<
Rect
>
candidatesVector
;
std
::
vector
<
int
>
rejectLevels
;
std
::
vector
<
int
>
rejectLevels
;
std
::
vector
<
double
>
levelWeights
;
std
::
vector
<
double
>
levelWeights
;
Mutex
mtx
;
int
stripCount
,
stripSize
;
const
int
PTS_PER_THREAD
=
1000
;
stripCount
=
((
processingRectSize
.
width
/
yStep
)
*
(
processingRectSize
.
height
+
yStep
-
1
)
/
yStep
+
PTS_PER_THREAD
/
2
)
/
PTS_PER_THREAD
;
stripCount
=
std
::
min
(
std
::
max
(
stripCount
,
1
),
100
);
stripSize
=
(((
processingRectSize
.
height
+
stripCount
-
1
)
/
stripCount
+
yStep
-
1
)
/
yStep
)
*
yStep
;
if
(
outputRejectLevels
)
if
(
outputRejectLevels
)
{
{
parallel_for_
(
Range
(
0
,
stripCount
),
CascadeClassifierInvoker
(
*
this
,
processingRectSize
,
stripSize
,
yStep
,
factor
,
parallel_for_
(
Range
(
0
,
stripCount
),
CascadeClassifierInvoker
(
*
this
,
processingRectSize
,
stripSize
,
yStep
,
factor
,
...
@@ -1052,6 +1069,70 @@ bool CascadeClassifierImpl::detectSingleScale( const Mat& image, int stripCount,
...
@@ -1052,6 +1069,70 @@ bool CascadeClassifierImpl::detectSingleScale( const Mat& image, int stripCount,
return
true
;
return
true
;
}
}
bool
CascadeClassifierImpl
::
ocl_detectSingleScale
(
InputArray
_image
,
Size
processingRectSize
,
int
yStep
,
double
factor
,
std
::
vector
<
Rect
>&
candidates
,
std
::
vector
<
int
>&
,
std
::
vector
<
double
>&
,
bool
)
{
Ptr
<
HaarEvaluator
>
haar
=
featureEvaluator
.
dynamicCast
<
HaarEvaluator
>
();
if
(
haar
.
empty
()
)
return
false
;
if
(
cascadeKernel
.
empty
()
)
{
//cascadeKernel.create(")
if
(
cascadeKernel
.
empty
()
)
return
false
;
}
if
(
ustages
.
empty
()
)
{
#define UPLOAD_CASCADE_PART(NAME) \
Mat(1, (int)(data.NAME.size()*sizeof(data.NAME[0])), CV_8U, &data.NAME[0]).copyTo(u##NAME)
UPLOAD_CASCADE_PART
(
stages
);
UPLOAD_CASCADE_PART
(
classifiers
);
UPLOAD_CASCADE_PART
(
nodes
);
UPLOAD_CASCADE_PART
(
leaves
);
ufacepos
.
create
();
}
haar
->
setUMat
(
_image
,
data
.
origWinSize
,
ugrayImage
.
size
());
std
::
vector
<
UMat
>
bufs
;
haar
->
getUMats
(
bufs
);
CV_Assert
(
bufs
.
size
()
==
5
);
size_t
globalsize
[]
=
{
processingRectSize
.
width
,
processingRectSize
.
height
};
if
(
!
cascadeKernel
.
args
(
ocl
::
KernelArg
::
PtrReadOnly
(
bufs
[
0
]),
// sum
ocl
::
KernelArg
::
PtrReadOnly
(
bufs
[
1
]),
// sqsum
ocl
::
KernelArg
::
PtrReadOnly
(
bufs
[
2
]),
// optfeatures
// cascade classifier
ocl
::
KernelArg
::
PtrReadOnly
(
ustages
),
ocl
::
KernelArg
::
PtrReadOnly
(
uclassifiers
),
ocl
::
KernelArg
::
PtrReadOnly
(
unodes
),
ocl
::
KernelArg
::
PtrReadOnly
(
uleaves
),
ocl
::
KernelArg
::
WriteOnly
(
ufacepos
),
// positions
ocl
::
KernelArg
::
ReadWrite
(
umisc
),
processingRectSize
.
width
,
processingRectSize
.
height
).
run
(
2
,
globalsize
,
0
,
false
))
return
false
;
Mat
facepos
=
ufacepos
.
getMat
(
ACCESS_READ
);
const
int
*
fptr
=
facepos
.
ptr
<
int
>
();
int
nfaces
=
fptr
[
0
];
for
(
i
=
0
;
i
<
nfaces
;
i
++
)
{
int
pos
=
fptr
[
i
+
1
];
int
x
=
candidates
.
push_back
(
Rect
()
return
false
;
}
bool
CascadeClassifierImpl
::
isOldFormatCascade
()
const
bool
CascadeClassifierImpl
::
isOldFormatCascade
()
const
{
{
return
!
oldCascade
.
empty
();
return
!
oldCascade
.
empty
();
...
@@ -1097,36 +1178,65 @@ static void detectMultiScaleOldFormat( const Mat& image, Ptr<CvHaarClassifierCas
...
@@ -1097,36 +1178,65 @@ static void detectMultiScaleOldFormat( const Mat& image, Ptr<CvHaarClassifierCas
std
::
transform
(
vecAvgComp
.
begin
(),
vecAvgComp
.
end
(),
objects
.
begin
(),
getRect
());
std
::
transform
(
vecAvgComp
.
begin
(),
vecAvgComp
.
end
(),
objects
.
begin
(),
getRect
());
}
}
void
CascadeClassifierImpl
::
detectMultiScaleNoGrouping
(
const
Mat
&
image
,
std
::
vector
<
Rect
>&
candidates
,
void
CascadeClassifierImpl
::
detectMultiScaleNoGrouping
(
InputArray
_image
,
std
::
vector
<
Rect
>&
candidates
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
double
scaleFactor
,
Size
minObjectSize
,
Size
maxObjectSize
,
double
scaleFactor
,
Size
minObjectSize
,
Size
maxObjectSize
,
bool
outputRejectLevels
)
bool
outputRejectLevels
)
{
{
Size
imgsz
=
_image
.
size
();
int
imgtype
=
_image
.
type
();
Mat
grayImage
,
imageBuffer
;
candidates
.
clear
();
candidates
.
clear
();
rejectLevels
.
clear
();
if
(
maskGenerator
)
levelWeights
.
clear
();
maskGenerator
->
initializeMask
(
image
);
if
(
maxObjectSize
.
height
==
0
||
maxObjectSize
.
width
==
0
)
if
(
maxObjectSize
.
height
==
0
||
maxObjectSize
.
width
==
0
)
maxObjectSize
=
image
.
size
();
maxObjectSize
=
imgsz
;
bool
use_ocl
=
ocl
::
useOpenCL
()
&&
getFeatureType
()
==
FeatureEvaluator
::
HAAR
&&
!
isOldFormatCascade
()
&&
maskGenerator
.
empty
()
&&
!
outputRejectLevels
&&
tryOpenCL
;
if
(
!
use_ocl
)
{
Mat
image
=
_image
.
getMat
();
if
(
maskGenerator
)
maskGenerator
->
initializeMask
(
image
);
grayImage
=
image
;
if
(
CV_MAT_CN
(
imgtype
)
>
1
)
{
Mat
temp
;
cvtColor
(
grayImage
,
temp
,
COLOR_BGR2GRAY
);
grayImage
=
temp
;
}
Mat
grayImage
=
image
;
imageBuffer
.
create
(
imgsz
.
height
+
1
,
imgsz
.
width
+
1
,
CV_8U
);
if
(
grayImage
.
channels
()
>
1
)
}
else
{
{
Mat
temp
;
UMat
uimage
=
_image
.
getUMat
();
cvtColor
(
grayImage
,
temp
,
COLOR_BGR2GRAY
);
if
(
CV_MAT_CN
(
imgtype
)
>
1
)
grayImage
=
temp
;
cvtColor
(
uimage
,
ugrayImage
,
COLOR_BGR2GRAY
);
else
uimage
.
copyTo
(
ugrayImage
);
uimageBuffer
.
create
(
imgsz
.
height
+
1
,
imgsz
.
width
+
1
,
CV_8U
);
}
}
Mat
imageBuffer
(
image
.
rows
+
1
,
image
.
cols
+
1
,
CV_8U
);
for
(
double
factor
=
1
;
;
factor
*=
scaleFactor
)
for
(
double
factor
=
1
;
;
factor
*=
scaleFactor
)
{
{
Size
originalWindowSize
=
getOriginalWindowSize
();
Size
originalWindowSize
=
getOriginalWindowSize
();
Size
windowSize
(
cvRound
(
originalWindowSize
.
width
*
factor
),
cvRound
(
originalWindowSize
.
height
*
factor
)
);
Size
windowSize
(
cvRound
(
originalWindowSize
.
width
*
factor
),
cvRound
(
originalWindowSize
.
height
*
factor
)
);
Size
scaledImageSize
(
cvRound
(
grayImage
.
cols
/
factor
),
cvRound
(
grayImage
.
rows
/
factor
)
);
Size
scaledImageSize
(
cvRound
(
grayImage
.
cols
/
factor
),
cvRound
(
grayImage
.
rows
/
factor
)
);
Size
processingRectSize
(
scaledImageSize
.
width
-
originalWindowSize
.
width
,
scaledImageSize
.
height
-
originalWindowSize
.
height
);
Size
processingRectSize
(
scaledImageSize
.
width
-
originalWindowSize
.
width
,
scaledImageSize
.
height
-
originalWindowSize
.
height
);
if
(
processingRectSize
.
width
<=
0
||
processingRectSize
.
height
<=
0
)
if
(
processingRectSize
.
width
<=
0
||
processingRectSize
.
height
<=
0
)
break
;
break
;
...
@@ -1134,10 +1244,7 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( const Mat& image, std::v
...
@@ -1134,10 +1244,7 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( const Mat& image, std::v
break
;
break
;
if
(
windowSize
.
width
<
minObjectSize
.
width
||
windowSize
.
height
<
minObjectSize
.
height
)
if
(
windowSize
.
width
<
minObjectSize
.
width
||
windowSize
.
height
<
minObjectSize
.
height
)
continue
;
continue
;
Mat
scaledImage
(
scaledImageSize
,
CV_8U
,
imageBuffer
.
data
);
resize
(
grayImage
,
scaledImage
,
scaledImageSize
,
0
,
0
,
INTER_LINEAR
);
int
yStep
;
int
yStep
;
if
(
getFeatureType
()
==
cv
::
FeatureEvaluator
::
HOG
)
if
(
getFeatureType
()
==
cv
::
FeatureEvaluator
::
HOG
)
{
{
...
@@ -1148,16 +1255,36 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( const Mat& image, std::v
...
@@ -1148,16 +1255,36 @@ void CascadeClassifierImpl::detectMultiScaleNoGrouping( const Mat& image, std::v
yStep
=
factor
>
2.
?
1
:
2
;
yStep
=
factor
>
2.
?
1
:
2
;
}
}
int
stripCount
,
stripSize
;
if
(
use_ocl
)
{
const
int
PTS_PER_THREAD
=
1000
;
UMat
uscaledImage
(
uimageBuffer
,
Rect
(
0
,
0
,
scaledImageSize
.
width
,
scaledImageSize
.
height
));
stripCount
=
((
processingRectSize
.
width
/
yStep
)
*
(
processingRectSize
.
height
+
yStep
-
1
)
/
yStep
+
PTS_PER_THREAD
/
2
)
/
PTS_PER_THREAD
;
resize
(
ugrayImage
,
uscaledImage
,
scaledImageSize
,
0
,
0
,
INTER_LINEAR
);
stripCount
=
std
::
min
(
std
::
max
(
stripCount
,
1
),
100
);
stripSize
=
(((
processingRectSize
.
height
+
stripCount
-
1
)
/
stripCount
+
yStep
-
1
)
/
yStep
)
*
yStep
;
if
(
ocl_detectSingleScale
(
uscaledImage
,
processingRectSize
,
yStep
,
factor
,
candidates
,
rejectLevels
,
levelWeights
,
outputRejectLevels
)
)
if
(
!
detectSingleScale
(
scaledImage
,
stripCount
,
processingRectSize
,
stripSize
,
yStep
,
factor
,
candidates
,
continue
;
rejectLevels
,
levelWeights
,
outputRejectLevels
)
)
break
;
/////// if the OpenCL branch has been executed but failed, fall back to CPU: /////
tryOpenCL
=
false
;
// for this cascade do not try OpenCL anymore
// since we may already have some partial results from OpenCL code (unlikely, but still),
// we just recursively call the function again, but with tryOpenCL==false it will
// go with CPU route, so there is no infinite recursion
detectMultiScaleNoGrouping
(
_image
,
candidates
,
rejectLevels
,
levelWeights
,
scaleFactor
,
minObjectSize
,
maxObjectSize
,
outputRejectLevels
);
return
;
}
else
{
Mat
scaledImage
(
scaledImageSize
,
CV_8U
,
imageBuffer
.
data
);
resize
(
grayImage
,
scaledImage
,
scaledImageSize
,
0
,
0
,
INTER_LINEAR
);
if
(
!
detectSingleScale
(
scaledImage
,
processingRectSize
,
yStep
,
factor
,
candidates
,
rejectLevels
,
levelWeights
,
outputRejectLevels
)
)
break
;
}
}
}
}
}
...
@@ -1168,21 +1295,21 @@ void CascadeClassifierImpl::detectMultiScale( InputArray _image, std::vector<Rec
...
@@ -1168,21 +1295,21 @@ void CascadeClassifierImpl::detectMultiScale( InputArray _image, std::vector<Rec
int
flags
,
Size
minObjectSize
,
Size
maxObjectSize
,
int
flags
,
Size
minObjectSize
,
Size
maxObjectSize
,
bool
outputRejectLevels
)
bool
outputRejectLevels
)
{
{
Mat
image
=
_image
.
getMat
();
CV_Assert
(
scaleFactor
>
1
&&
_image
.
depth
()
==
CV_8U
);
CV_Assert
(
scaleFactor
>
1
&&
image
.
depth
()
==
CV_8U
);
if
(
empty
()
)
if
(
empty
()
)
return
;
return
;
if
(
isOldFormatCascade
()
)
if
(
isOldFormatCascade
()
)
{
{
Mat
image
=
_image
.
getMat
();
std
::
vector
<
CvAvgComp
>
fakeVecAvgComp
;
std
::
vector
<
CvAvgComp
>
fakeVecAvgComp
;
detectMultiScaleOldFormat
(
image
,
oldCascade
,
objects
,
rejectLevels
,
levelWeights
,
fakeVecAvgComp
,
scaleFactor
,
detectMultiScaleOldFormat
(
image
,
oldCascade
,
objects
,
rejectLevels
,
levelWeights
,
fakeVecAvgComp
,
scaleFactor
,
minNeighbors
,
flags
,
minObjectSize
,
maxObjectSize
,
outputRejectLevels
);
minNeighbors
,
flags
,
minObjectSize
,
maxObjectSize
,
outputRejectLevels
);
}
}
else
else
{
{
detectMultiScaleNoGrouping
(
image
,
objects
,
rejectLevels
,
levelWeights
,
scaleFactor
,
minObjectSize
,
maxObjectSize
,
detectMultiScaleNoGrouping
(
_
image
,
objects
,
rejectLevels
,
levelWeights
,
scaleFactor
,
minObjectSize
,
maxObjectSize
,
outputRejectLevels
);
outputRejectLevels
);
const
double
GROUP_EPS
=
0.2
;
const
double
GROUP_EPS
=
0.2
;
if
(
outputRejectLevels
)
if
(
outputRejectLevels
)
...
@@ -1346,8 +1473,15 @@ bool CascadeClassifierImpl::Data::read(const FileNode &root)
...
@@ -1346,8 +1473,15 @@ bool CascadeClassifierImpl::Data::read(const FileNode &root)
return
true
;
return
true
;
}
}
bool
CascadeClassifierImpl
::
read_
(
const
FileNode
&
root
)
bool
CascadeClassifierImpl
::
read_
(
const
FileNode
&
root
)
{
{
tryOpenCL
=
true
;
cascadeKernel
=
ocl
::
Kernel
();
ustages
.
release
();
uclassifiers
.
release
();
unodes
.
release
();
uleaves
.
release
();
if
(
!
data
.
read
(
root
)
)
if
(
!
data
.
read
(
root
)
)
return
false
;
return
false
;
...
...
modules/objdetect/src/cascadedetect.hpp
View file @
d8513d62
...
@@ -49,11 +49,17 @@ public:
...
@@ -49,11 +49,17 @@ public:
Ptr
<
MaskGenerator
>
getMaskGenerator
();
Ptr
<
MaskGenerator
>
getMaskGenerator
();
protected
:
protected
:
bool
detectSingleScale
(
const
Mat
&
image
,
int
stripCount
,
Size
processingRectSize
,
bool
detectSingleScale
(
InputArray
image
,
Size
processingRectSize
,
int
stripSize
,
int
yStep
,
double
factor
,
std
::
vector
<
Rect
>&
candidates
,
int
yStep
,
double
factor
,
std
::
vector
<
Rect
>&
candidates
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
bool
outputRejectLevels
=
false
);
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
bool
outputRejectLevels
=
false
);
void
detectMultiScaleNoGrouping
(
const
Mat
&
image
,
std
::
vector
<
Rect
>&
candidates
,
bool
ocl_detectSingleScale
(
InputArray
image
,
Size
processingRectSize
,
int
yStep
,
double
factor
,
std
::
vector
<
Rect
>&
candidates
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
bool
outputRejectLevels
=
false
);
void
detectMultiScaleNoGrouping
(
InputArray
image
,
std
::
vector
<
Rect
>&
candidates
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
std
::
vector
<
int
>&
rejectLevels
,
std
::
vector
<
double
>&
levelWeights
,
double
scaleFactor
,
Size
minObjectSize
,
Size
maxObjectSize
,
double
scaleFactor
,
Size
minObjectSize
,
Size
maxObjectSize
,
bool
outputRejectLevels
=
false
);
bool
outputRejectLevels
=
false
);
...
@@ -127,6 +133,12 @@ protected:
...
@@ -127,6 +133,12 @@ protected:
Ptr
<
CvHaarClassifierCascade
>
oldCascade
;
Ptr
<
CvHaarClassifierCascade
>
oldCascade
;
Ptr
<
MaskGenerator
>
maskGenerator
;
Ptr
<
MaskGenerator
>
maskGenerator
;
UMat
ugrayImage
,
uimageBuffer
;
UMat
ufacepos
,
ustages
,
uclassifiers
,
unodes
,
uleaves
,
usubsets
;
ocl
::
Kernel
cascadeKernel
;
bool
tryOpenCL
;
Mutex
mtx
;
};
};
#define CC_CASCADE_PARAMS "cascadeParams"
#define CC_CASCADE_PARAMS "cascadeParams"
...
@@ -212,6 +224,10 @@ protected:
...
@@ -212,6 +224,10 @@ protected:
#define CALC_SUM(rect,offset) CALC_SUM_((rect)[0], (rect)[1], (rect)[2], (rect)[3], offset)
#define CALC_SUM(rect,offset) CALC_SUM_((rect)[0], (rect)[1], (rect)[2], (rect)[3], offset)
#define CALC_SUM_OFS_(p0, p1, p2, p3, ptr) \
((ptr)[p0] - (ptr)[p1] - (ptr)[p2] + (ptr)[p3])
#define CALC_SUM_OFS(rect, ptr) CALC_SUM_OFS_((rect)[0], (rect)[1], (rect)[2], (rect)[3], ptr)
//---------------------------------------------- HaarEvaluator ---------------------------------------
//---------------------------------------------- HaarEvaluator ---------------------------------------
class
HaarEvaluator
:
public
FeatureEvaluator
class
HaarEvaluator
:
public
FeatureEvaluator
...
@@ -241,10 +257,10 @@ public:
...
@@ -241,10 +257,10 @@ public:
enum
{
RECT_NUM
=
Feature
::
RECT_NUM
};
enum
{
RECT_NUM
=
Feature
::
RECT_NUM
};
float
calc
(
const
int
*
pwin
)
const
;
float
calc
(
const
int
*
pwin
)
const
;
void
set
Ptrs
(
const
Mat
&
sum
,
const
Feature
&
f
);
void
set
Offsets
(
const
Feature
&
_f
,
int
step
,
int
tofs
);
int
ofs
[
RECT_NUM
][
4
];
int
ofs
[
RECT_NUM
][
4
];
float
weight
[
RECT_NUM
];
float
weight
[
4
];
};
};
HaarEvaluator
();
HaarEvaluator
();
...
@@ -254,8 +270,11 @@ public:
...
@@ -254,8 +270,11 @@ public:
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
int
getFeatureType
()
const
{
return
FeatureEvaluator
::
HAAR
;
}
virtual
int
getFeatureType
()
const
{
return
FeatureEvaluator
::
HAAR
;
}
virtual
bool
setImage
(
const
Mat
&
,
Size
origWinSize
);
virtual
bool
setImage
(
InputArray
,
Size
origWinSize
);
virtual
bool
setWindow
(
Point
pt
);
virtual
bool
setWindow
(
Point
pt
);
virtual
bool
setUMat
(
InputArray
,
Size
origWinSize
,
Size
origImgSize
);
virtual
void
getUMats
(
std
::
vector
<
UMat
>&
bufs
);
double
operator
()(
int
featureIdx
)
const
double
operator
()(
int
featureIdx
)
const
{
return
optfeaturesPtr
[
featureIdx
].
calc
(
pwin
)
*
varianceNormFactor
;
}
{
return
optfeaturesPtr
[
featureIdx
].
calc
(
pwin
)
*
varianceNormFactor
;
}
...
@@ -263,22 +282,22 @@ public:
...
@@ -263,22 +282,22 @@ public:
{
return
(
*
this
)(
featureIdx
);
}
{
return
(
*
this
)(
featureIdx
);
}
protected
:
protected
:
Size
origWinSize
;
Size
origWinSize
,
origImgSize
;
std
::
vector
<
Feature
>
features
;
Ptr
<
std
::
vector
<
Feature
>
>
features
;
std
::
vector
<
OptFeature
>
optfeatures
;
Ptr
<
std
::
vector
<
OptFeature
>
>
optfeatures
;
OptFeature
*
optfeaturesPtr
;
// optimization
OptFeature
*
optfeaturesPtr
;
// optimization
bool
hasTiltedFeatures
;
bool
hasTiltedFeatures
;
Mat
sum0
,
sqsum0
,
tilted0
;
Mat
sum0
,
sqsum0
;
Mat
sum
,
sqsum
,
tilted
;
Mat
sum
,
sqsum
,
tilted
;
UMat
usum
,
usqsum
,
fbuf
;
Rect
normrect
;
Rect
normrect
;
int
p
[
4
];
int
nofs
[
4
];
int
pq
[
4
];
int
nqofs
[
4
];
const
int
*
pwin
;
const
int
*
pwin
;
const
double
*
pqwin
;
const
double
*
pqwin
;
int
offset
;
double
varianceNormFactor
;
double
varianceNormFactor
;
};
};
...
@@ -298,34 +317,35 @@ inline HaarEvaluator::OptFeature :: OptFeature()
...
@@ -298,34 +317,35 @@ inline HaarEvaluator::OptFeature :: OptFeature()
ofs
[
2
][
0
]
=
ofs
[
2
][
1
]
=
ofs
[
2
][
2
]
=
ofs
[
2
][
3
]
=
0
;
ofs
[
2
][
0
]
=
ofs
[
2
][
1
]
=
ofs
[
2
][
2
]
=
ofs
[
2
][
3
]
=
0
;
}
}
/*inline float HaarEvaluator::Feature :: calc( int _offset
) const
inline
float
HaarEvaluator
::
OptFeature
::
calc
(
const
int
*
ptr
)
const
{
{
float ret = rect[0].weight * CALC_SUM(p[0], _offset) + rect[1].weight * CALC_SUM(p[1], _offset);
float
ret
=
weight
[
0
]
*
CALC_SUM_OFS
(
ofs
[
0
],
ptr
)
+
weight
[
1
]
*
CALC_SUM_OFS
(
ofs
[
1
],
ptr
);
if(
rect[2].weight
!= 0.0f )
if
(
weight
[
2
]
!=
0.0
f
)
ret +=
rect[2].weight * CALC_SUM(p[2], _offset
);
ret
+=
weight
[
2
]
*
CALC_SUM_OFS
(
ofs
[
2
],
ptr
);
return
ret
;
return
ret
;
}
*/
}
inline
void
HaarEvaluator
::
OptFeature
::
set
Ptrs
(
const
Mat
&
_sum
,
const
Feature
&
_f
)
inline
void
HaarEvaluator
::
OptFeature
::
set
Offsets
(
const
Feature
&
_f
,
int
step
,
int
tofs
)
{
{
const
int
*
ptr
=
(
const
int
*
)
_sum
.
data
;
weight
[
0
]
=
_f
.
rect
[
0
].
weight
;
size_t
step
=
_sum
.
step
/
sizeof
(
ptr
[
0
])
;
weight
[
1
]
=
_f
.
rect
[
1
].
weight
;
size_t
tiltedofs
=
weight
[
2
]
=
_f
.
rect
[
2
].
weight
;
if
(
tilted
)
if
(
_f
.
tilted
)
{
{
CV_TILTED_
PTRS
(
p
[
0
][
0
],
p
[
0
][
1
],
p
[
0
][
2
],
p
[
0
][
3
],
ptr
,
rect
[
0
].
r
,
step
);
CV_TILTED_
OFS
(
ofs
[
0
][
0
],
ofs
[
0
][
1
],
ofs
[
0
][
2
],
ofs
[
0
][
3
],
tofs
,
_f
.
rect
[
0
].
r
,
step
);
CV_TILTED_
PTRS
(
p
[
1
][
0
],
p
[
1
][
1
],
p
[
1
][
2
],
p
[
1
][
3
],
ptr
,
rect
[
1
].
r
,
step
);
CV_TILTED_
OFS
(
ofs
[
1
][
0
],
ofs
[
1
][
1
],
ofs
[
1
][
2
],
ofs
[
1
][
3
],
tofs
,
_f
.
rect
[
1
].
r
,
step
);
if
(
rect
[
2
].
weight
)
if
(
weight
[
2
]
)
CV_TILTED_PTRS
(
p
[
2
][
0
],
p
[
2
][
1
],
p
[
2
][
2
],
p
[
2
][
3
],
ptr
,
rect
[
2
].
r
,
step
);
CV_TILTED_PTRS
(
ofs
[
2
][
0
],
ofs
[
2
][
1
],
ofs
[
2
][
2
],
ofs
[
2
][
3
],
tofs
,
_f
.
rect
[
2
].
r
,
step
);
}
}
else
else
{
{
CV_SUM_
PTRS
(
p
[
0
][
0
],
p
[
0
][
1
],
p
[
0
][
2
],
p
[
0
][
3
],
ptr
,
rect
[
0
].
r
,
step
);
CV_SUM_
OFS
(
ofs
[
0
][
0
],
ofs
[
0
][
1
],
ofs
[
0
][
2
],
ofs
[
0
][
3
],
0
,
_f
.
rect
[
0
].
r
,
step
);
CV_SUM_
PTRS
(
p
[
1
][
0
],
p
[
1
][
1
],
p
[
1
][
2
],
p
[
1
][
3
],
ptr
,
rect
[
1
].
r
,
step
);
CV_SUM_
OFS
(
ofs
[
1
][
0
],
ofs
[
1
][
1
],
ofs
[
1
][
2
],
ofs
[
1
][
3
],
0
,
_f
.
rect
[
1
].
r
,
step
);
if
(
rect
[
2
].
weight
)
if
(
weight
[
2
]
)
CV_SUM_
PTRS
(
p
[
2
][
0
],
p
[
2
][
1
],
p
[
2
][
2
],
p
[
2
][
3
],
ptr
,
rect
[
2
].
r
,
step
);
CV_SUM_
OFS
(
ofs
[
2
][
0
],
ofs
[
2
][
1
],
ofs
[
2
][
2
],
ofs
[
2
][
3
],
0
,
_f
.
rect
[
2
].
r
,
step
);
}
}
}
}
...
@@ -356,7 +376,7 @@ public:
...
@@ -356,7 +376,7 @@ public:
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
int
getFeatureType
()
const
{
return
FeatureEvaluator
::
LBP
;
}
virtual
int
getFeatureType
()
const
{
return
FeatureEvaluator
::
LBP
;
}
virtual
bool
setImage
(
const
Mat
&
image
,
Size
_origWinSize
);
virtual
bool
setImage
(
InputArray
image
,
Size
_origWinSize
);
virtual
bool
setWindow
(
Point
pt
);
virtual
bool
setWindow
(
Point
pt
);
int
operator
()(
int
featureIdx
)
const
int
operator
()(
int
featureIdx
)
const
...
@@ -433,7 +453,7 @@ public:
...
@@ -433,7 +453,7 @@ public:
virtual
bool
read
(
const
FileNode
&
node
);
virtual
bool
read
(
const
FileNode
&
node
);
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
Ptr
<
FeatureEvaluator
>
clone
()
const
;
virtual
int
getFeatureType
()
const
{
return
FeatureEvaluator
::
HOG
;
}
virtual
int
getFeatureType
()
const
{
return
FeatureEvaluator
::
HOG
;
}
virtual
bool
setImage
(
const
Mat
&
image
,
Size
winSize
);
virtual
bool
setImage
(
InputArray
image
,
Size
winSize
);
virtual
bool
setWindow
(
Point
pt
);
virtual
bool
setWindow
(
Point
pt
);
double
operator
()(
int
featureIdx
)
const
double
operator
()(
int
featureIdx
)
const
{
{
...
...
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