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
fa62e2b7
Commit
fa62e2b7
authored
Oct 11, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move preprocessing into separate function
parent
312a58fc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
72 additions
and
62 deletions
+72
-62
softcascade.cpp
modules/gpu/src/softcascade.cpp
+72
-62
No files found.
modules/gpu/src/softcascade.cpp
View file @
fa62e2b7
...
...
@@ -93,6 +93,10 @@ namespace icf {
PtrStepSzi
counter
,
const
int
downscales
);
}
namespace
imgproc
{
void
meanShiftFiltering_gpu
(
const
PtrStepSzb
&
src
,
PtrStepSzb
dst
,
int
sp
,
int
sr
,
int
maxIter
,
float
eps
,
cudaStream_t
stream
);
}
}}}
struct
cv
::
gpu
::
SoftCascade
::
Filds
...
...
@@ -104,8 +108,8 @@ struct cv::gpu::SoftCascade::Filds
fplane
.
create
(
FRAME_HEIGHT
*
6
,
FRAME_WIDTH
,
CV_32FC1
);
luv
.
create
(
FRAME_HEIGHT
,
FRAME_WIDTH
,
CV_8UC3
);
shrunk
.
create
(
FRAME_HEIGHT
/
4
*
HOG_LUV_BINS
,
FRAME_WIDTH
/
4
,
CV_8UC1
);
integralBuffer
.
create
(
shrunk
.
rows
+
1
*
HOG_LUV_BINS
,
shrunk
.
cols
+
1
,
CV_32SC1
);
hogluv
.
create
((
FRAME_HEIGHT
/
4
+
1
)
*
HOG_LUV_BINS
,
FRAME_WIDTH
/
4
+
1
,
CV_32SC1
);
integralBuffer
.
create
(
1
,
(
shrunk
.
rows
+
1
)
*
HOG_LUV_BINS
*
(
shrunk
.
cols
+
1
)
,
CV_32SC1
);
hogluv
.
create
((
FRAME_HEIGHT
/
4
+
1
)
*
HOG_LUV_BINS
,
FRAME_WIDTH
/
4
+
64
,
CV_32SC1
);
detCounter
.
create
(
1
,
1
,
CV_32SC1
);
}
...
...
@@ -146,6 +150,8 @@ struct cv::gpu::SoftCascade::Filds
std
::
vector
<
float
>
scales
;
static
const
int
shrinkage
=
4
;
enum
{
BOOST
=
0
};
enum
{
...
...
@@ -160,19 +166,80 @@ struct cv::gpu::SoftCascade::Filds
};
bool
fill
(
const
FileNode
&
root
,
const
float
mins
,
const
float
maxs
);
void
detect
(
c
v
::
gpu
::
GpuMat
roi
,
cv
::
gpu
::
GpuMat
objects
,
cudaStream_t
stream
)
const
void
detect
(
c
onst
cv
::
gpu
::
GpuMat
&
roi
,
cv
::
gpu
::
GpuMat
&
objects
,
cudaStream_t
stream
)
const
{
cudaMemset
(
detCounter
.
data
,
0
,
detCounter
.
step
*
detCounter
.
rows
*
sizeof
(
int
));
device
::
icf
::
detect
(
roi
,
levels
,
octaves
,
stages
,
nodes
,
leaves
,
hogluv
,
objects
,
detCounter
,
downscales
);
}
void
detectAtScale
(
int
scale
,
c
v
::
gpu
::
GpuMat
roi
,
cv
::
gpu
::
GpuMat
objects
,
cudaStream_t
stream
)
const
void
detectAtScale
(
int
scale
,
c
onst
cv
::
gpu
::
GpuMat
&
roi
,
cv
::
gpu
::
GpuMat
&
objects
,
cudaStream_t
stream
)
const
{
cudaMemset
(
detCounter
.
data
,
0
,
detCounter
.
step
*
detCounter
.
rows
*
sizeof
(
int
));
device
::
icf
::
detectAtScale
(
scale
,
roi
,
levels
,
octaves
,
stages
,
nodes
,
leaves
,
hogluv
,
objects
,
detCounter
,
downscales
);
}
void
preprocess
(
const
cv
::
gpu
::
GpuMat
&
colored
)
{
cudaMemset
(
plane
.
data
,
0
,
plane
.
step
*
plane
.
rows
);
int
fw
=
Filds
::
FRAME_WIDTH
;
int
fh
=
Filds
::
FRAME_HEIGHT
;
GpuMat
gray
(
plane
,
cv
::
Rect
(
0
,
fh
*
Filds
::
HOG_LUV_BINS
,
fw
,
fh
));
cv
::
gpu
::
cvtColor
(
colored
,
gray
,
CV_BGR2GRAY
);
//create hog
GpuMat
dfdx
(
fplane
,
cv
::
Rect
(
0
,
0
,
fw
,
fh
));
GpuMat
dfdy
(
fplane
,
cv
::
Rect
(
0
,
fh
,
fw
,
fh
));
cv
::
gpu
::
Sobel
(
gray
,
dfdx
,
CV_32F
,
1
,
0
,
3
,
0.125
f
);
cv
::
gpu
::
Sobel
(
gray
,
dfdy
,
CV_32F
,
0
,
1
,
3
,
0.125
f
);
GpuMat
mag
(
fplane
,
cv
::
Rect
(
0
,
2
*
fh
,
fw
,
fh
));
GpuMat
ang
(
fplane
,
cv
::
Rect
(
0
,
3
*
fh
,
fw
,
fh
));
cv
::
gpu
::
cartToPolar
(
dfdx
,
dfdy
,
mag
,
ang
,
true
);
// normolize magnitude to uchar interval and angles to 6 bins
GpuMat
nmag
(
fplane
,
cv
::
Rect
(
0
,
4
*
fh
,
fw
,
fh
));
GpuMat
nang
(
fplane
,
cv
::
Rect
(
0
,
5
*
fh
,
fw
,
fh
));
cv
::
gpu
::
multiply
(
mag
,
cv
::
Scalar
::
all
(
1.
f
/
::
log
(
2
)),
nmag
);
cv
::
gpu
::
multiply
(
ang
,
cv
::
Scalar
::
all
(
1.
f
/
60.
f
),
nang
);
//create uchar magnitude
GpuMat
cmag
(
plane
,
cv
::
Rect
(
0
,
fh
*
Filds
::
HOG_BINS
,
fw
,
fh
));
nmag
.
convertTo
(
cmag
,
CV_8UC1
);
// create luv
cv
::
gpu
::
cvtColor
(
colored
,
luv
,
CV_BGR2Luv
);
std
::
vector
<
GpuMat
>
splited
;
for
(
int
i
=
0
;
i
<
Filds
::
LUV_BINS
;
++
i
)
{
splited
.
push_back
(
GpuMat
(
plane
,
cv
::
Rect
(
0
,
fh
*
(
7
+
i
),
fw
,
fh
)));
}
cv
::
gpu
::
split
(
luv
,
splited
);
device
::
icf
::
fillBins
(
plane
,
nang
,
fw
,
fh
,
Filds
::
HOG_BINS
);
GpuMat
channels
(
plane
,
cv
::
Rect
(
0
,
0
,
fw
,
fh
*
Filds
::
HOG_LUV_BINS
));
cv
::
gpu
::
resize
(
channels
,
shrunk
,
cv
::
Size
(),
0.25
,
0.25
,
CV_INTER_AREA
);
fw
/=
shrinkage
;
fh
/=
shrinkage
;
for
(
int
i
=
0
;
i
<
Filds
::
HOG_LUV_BINS
;
++
i
)
{
GpuMat
channel
(
shrunk
,
cv
::
Rect
(
0
,
fh
*
i
,
fw
,
fh
));
GpuMat
sum
(
hogluv
,
cv
::
Rect
(
0
,
(
fh
+
1
)
*
i
,
fw
+
1
,
fh
+
1
));
cv
::
gpu
::
integralBuffered
(
channel
,
sum
,
integralBuffer
);
}
}
private
:
void
calcLevels
(
const
std
::
vector
<
device
::
icf
::
Octave
>&
octs
,
int
frameW
,
int
frameH
,
int
nscales
);
...
...
@@ -479,64 +546,7 @@ void cv::gpu::SoftCascade::detectMultiScale(const GpuMat& colored, const GpuMat&
Filds
&
flds
=
*
filds
;
GpuMat
&
plane
=
flds
.
plane
;
GpuMat
&
shrunk
=
flds
.
shrunk
;
cudaMemset
(
plane
.
data
,
0
,
plane
.
step
*
plane
.
rows
);
int
fw
=
Filds
::
FRAME_WIDTH
;
int
fh
=
Filds
::
FRAME_HEIGHT
;
GpuMat
gray
(
plane
,
cv
::
Rect
(
0
,
fh
*
Filds
::
HOG_LUV_BINS
,
fw
,
fh
));
cv
::
gpu
::
cvtColor
(
colored
,
gray
,
CV_BGR2GRAY
);
//create hog
GpuMat
dfdx
(
flds
.
fplane
,
cv
::
Rect
(
0
,
0
,
fw
,
fh
));
GpuMat
dfdy
(
flds
.
fplane
,
cv
::
Rect
(
0
,
fh
,
fw
,
fh
));
cv
::
gpu
::
Sobel
(
gray
,
dfdx
,
CV_32F
,
1
,
0
,
3
,
0.125
f
);
cv
::
gpu
::
Sobel
(
gray
,
dfdy
,
CV_32F
,
0
,
1
,
3
,
0.125
f
);
GpuMat
mag
(
flds
.
fplane
,
cv
::
Rect
(
0
,
2
*
fh
,
fw
,
fh
));
GpuMat
ang
(
flds
.
fplane
,
cv
::
Rect
(
0
,
3
*
fh
,
fw
,
fh
));
cv
::
gpu
::
cartToPolar
(
dfdx
,
dfdy
,
mag
,
ang
,
true
);
// normolize magnitude to uchar interval and angles to 6 bins
GpuMat
nmag
(
flds
.
fplane
,
cv
::
Rect
(
0
,
4
*
fh
,
fw
,
fh
));
GpuMat
nang
(
flds
.
fplane
,
cv
::
Rect
(
0
,
5
*
fh
,
fw
,
fh
));
cv
::
gpu
::
multiply
(
mag
,
cv
::
Scalar
::
all
(
1.
f
/
::
log
(
2
)),
nmag
);
cv
::
gpu
::
multiply
(
ang
,
cv
::
Scalar
::
all
(
1.
f
/
60.
f
),
nang
);
//create uchar magnitude
GpuMat
cmag
(
plane
,
cv
::
Rect
(
0
,
fh
*
Filds
::
HOG_BINS
,
fw
,
fh
));
nmag
.
convertTo
(
cmag
,
CV_8UC1
);
// create luv
cv
::
gpu
::
cvtColor
(
colored
,
flds
.
luv
,
CV_BGR2Luv
);
std
::
vector
<
GpuMat
>
splited
;
for
(
int
i
=
0
;
i
<
Filds
::
LUV_BINS
;
++
i
)
{
splited
.
push_back
(
GpuMat
(
plane
,
cv
::
Rect
(
0
,
fh
*
(
7
+
i
),
fw
,
fh
)));
}
cv
::
gpu
::
split
(
flds
.
luv
,
splited
);
device
::
icf
::
fillBins
(
plane
,
nang
,
fw
,
fh
,
Filds
::
HOG_BINS
);
GpuMat
hogluv
(
plane
,
cv
::
Rect
(
0
,
0
,
fw
,
fh
*
Filds
::
HOG_LUV_BINS
));
cv
::
gpu
::
resize
(
hogluv
,
flds
.
shrunk
,
cv
::
Size
(),
0.25
,
0.25
,
CV_INTER_AREA
);
fw
/=
4
;
fh
/=
4
;
for
(
int
i
=
0
;
i
<
Filds
::
HOG_LUV_BINS
;
++
i
)
{
GpuMat
channel
(
shrunk
,
cv
::
Rect
(
0
,
fh
*
i
,
fw
,
fh
));
GpuMat
sum
(
flds
.
hogluv
,
cv
::
Rect
(
0
,
(
fh
+
1
)
*
i
,
fw
+
1
,
fh
+
1
));
cv
::
gpu
::
integralBuffered
(
channel
,
sum
,
flds
.
integralBuffer
);
}
flds
.
preprocess
(
colored
);
if
(
specificScale
==
-
1
)
flds
.
detect
(
rois
,
objects
,
0
);
...
...
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