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
5120322c
Commit
5120322c
authored
Mar 03, 2013
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move gpu version of soft cascade to dedicated module
parent
9b00c14f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
366 additions
and
106 deletions
+366
-106
CMakeLists.txt
apps/sft/CMakeLists.txt
+1
-1
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+1
-2
CMakeLists.txt
modules/softcascade/CMakeLists.txt
+49
-3
softcascade.hpp
modules/softcascade/include/opencv2/softcascade.hpp
+91
-0
perf_cuda_softcascade.cpp
modules/softcascade/perf/perf_cuda_softcascade.cpp
+21
-19
icf-sc.cu
modules/softcascade/src/cuda/icf-sc.cu
+6
-7
cuda_invoker.hpp
modules/softcascade/src/cuda_invoker.hpp
+14
-16
detector_cuda.cpp
modules/softcascade/src/detector_cuda.cpp
+0
-0
softcascade_init.cpp
modules/softcascade/src/softcascade_init.cpp
+7
-1
test_cuda_softcascade.cpp
modules/softcascade/test/test_cuda_softcascade.cpp
+33
-37
test_main.cpp
modules/softcascade/test/test_main.cpp
+0
-0
utility.cpp
modules/softcascade/test/utility.cpp
+109
-0
utility.hpp
modules/softcascade/test/utility.hpp
+30
-17
CMakeLists.txt
samples/gpu/CMakeLists.txt
+1
-1
softcascade.cpp
samples/gpu/softcascade.cpp
+3
-2
No files found.
apps/sft/CMakeLists.txt
View file @
5120322c
set
(
name sft
)
set
(
the_target opencv_
${
name
}
)
set
(
OPENCV_
${
the_target
}
_DEPS opencv_core opencv_softcascade opencv_highgui opencv_imgproc opencv_ml
)
set
(
OPENCV_
${
the_target
}
_DEPS opencv_core opencv_softcascade opencv_highgui opencv_imgproc opencv_ml
OPTIONAL opencv_gpu opencv_objdetect opencv_featurest2d
)
ocv_check_dependencies
(
${
OPENCV_
${
the_target
}
_DEPS
}
)
if
(
NOT OCV_DEPENDENCIES_FOUND
)
...
...
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
5120322c
...
...
@@ -12,7 +12,6 @@
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -23,7 +22,7 @@
//
// * 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
m
aterials provided with the distribution.
// and/or other
GpuM
aterials 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.
...
...
modules/softcascade/CMakeLists.txt
View file @
5120322c
macro
(
ocv_glob_cuda_powered_module_sources
)
file
(
GLOB_RECURSE lib_srcs
"src/*.cpp"
)
file
(
GLOB_RECURSE lib_int_hdrs
"src/*.hpp"
"src/*.h"
)
file
(
GLOB lib_hdrs
"include/opencv2/
${
name
}
/*.hpp"
"include/opencv2/
${
name
}
/*.h"
)
file
(
GLOB lib_hdrs_detail
"include/opencv2/
${
name
}
/detail/*.hpp"
"include/opencv2/
${
name
}
/detail/*.h"
)
file
(
GLOB_RECURSE lib_device_srcs
"src/*.cu"
)
set
(
device_objs
""
)
set
(
lib_device_hdrs
""
)
if
(
HAVE_CUDA AND lib_device_srcs
)
ocv_include_directories
(
${
CUDA_INCLUDE_DIRS
}
)
file
(
GLOB_RECURSE lib_device_hdrs
"src/cuda/*.hpp"
)
ocv_cuda_compile
(
device_objs
${
lib_device_srcs
}
)
source_group
(
"Src
\\
Cuda"
FILES
${
lib_device_srcs
}
${
lib_device_hdrs
}
)
if
(
lib_device_hdrs
)
list
(
REMOVE_ITEM lib_int_hdrs
${
lib_device_hdrs
}
)
endif
()
endif
()
ocv_set_module_sources
(
${
ARGN
}
HEADERS
${
lib_hdrs
}
${
lib_hdrs_detail
}
SOURCES
${
lib_srcs
}
${
lib_int_hdrs
}
${
device_objs
}
${
lib_device_srcs
}
${
lib_device_hdrs
}
)
source_group
(
"Src"
FILES
${
lib_srcs
}
${
lib_int_hdrs
}
)
source_group
(
"Include"
FILES
${
lib_hdrs
}
)
source_group
(
"Include
\\
detail"
FILES
${
lib_hdrs_detail
}
)
endmacro
()
set
(
the_description
"Soft Cascade detection and training"
)
ocv_define_module
(
softcascade opencv_core opencv_imgproc opencv_ml
)
ocv_warnings_disable
(
CMAKE_CXX_FLAGS /wd4310
)
\ No newline at end of file
ocv_warnings_disable
(
CMAKE_CXX_FLAGS /wd4310 -Wundef -Wmissing-declarations
)
set
(
cuda_deps
""
)
set
(
cuda_include
""
)
if
(
NAVE_CUDA
)
set
(
cuda_deps
${
CUDA_LIBRARIES
}
${
CUDA_npp_LIBRARY
}
)
endif
()
ocv_add_module
(
softcascade opencv_core opencv_imgproc opencv_ml OPTIONAL opencv_gpu
${
cuda_deps
}
)
if
(
HAVE_CUDA
)
ocv_module_include_directories
(
${
CUDA_INCLUDE_DIRS
}
)
ocv_warnings_disable
(
CMAKE_CXX_FLAGS -Wundef
)
endif
()
ocv_glob_cuda_powered_module_sources
()
ocv_create_module
()
ocv_add_precompiled_headers
(
${
the_module
}
)
ocv_add_accuracy_tests
()
ocv_add_perf_tests
()
modules/softcascade/include/opencv2/softcascade.hpp
View file @
5120322c
...
...
@@ -212,6 +212,96 @@ public:
CV_EXPORTS
bool
initModule_softcascade
(
void
);
// ======================== GPU version for soft cascade ===================== //
class
CV_EXPORTS
ChannelsProcessor
{
public
:
enum
{
GENERIC
=
1
<<
4
,
SEPARABLE
=
2
<<
4
};
// Appends specified number of HOG first-order features integrals into given vector.
// Param frame is an input 3-channel bgr image.
// Param channels is a GPU matrix of optionally shrinked channels
// Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution.
virtual
void
apply
(
InputArray
frame
,
OutputArray
channels
,
cv
::
gpu
::
Stream
&
stream
=
cv
::
gpu
::
Stream
::
Null
())
=
0
;
// Creates a specific preprocessor implementation.
// Param shrinkage is a resizing factor. Resize is applied before the computing integral sum
// Param bins is a number of HOG-like channels.
// Param flags is a channel computing extra flags.
static
cv
::
Ptr
<
ChannelsProcessor
>
create
(
const
int
shrinkage
,
const
int
bins
,
const
int
flags
=
GENERIC
);
virtual
~
ChannelsProcessor
();
protected
:
ChannelsProcessor
();
};
// Implementation of soft (stage-less) cascaded detector.
class
CV_EXPORTS
SCascade
:
public
cv
::
Algorithm
{
public
:
// Representation of detectors result.
struct
CV_EXPORTS
Detection
{
ushort
x
;
ushort
y
;
ushort
w
;
ushort
h
;
float
confidence
;
int
kind
;
enum
{
PEDESTRIAN
=
0
};
};
enum
{
NO_REJECT
=
1
,
DOLLAR
=
2
,
/*PASCAL = 4,*/
DEFAULT
=
NO_REJECT
,
NMS_MASK
=
0xF
};
// 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 applied.
// Param minScale is a maximum scale relative to the original size of the image on which cascade will be applied.
// Param scales is a number of scales from minScale to maxScale.
// Param flags is an extra tuning flags.
SCascade
(
const
double
minScale
=
0.4
,
const
double
maxScale
=
5.
,
const
int
scales
=
55
,
const
int
flags
=
NO_REJECT
||
ChannelsProcessor
::
GENERIC
);
virtual
~
SCascade
();
cv
::
AlgorithmInfo
*
info
()
const
;
// Load cascade from FileNode.
// Param fn is a root node for cascade. Should be <cascade>.
virtual
bool
load
(
const
FileNode
&
fn
);
// Load cascade config.
virtual
void
read
(
const
FileNode
&
fn
);
// Return the matrix of of detected objects.
// Param image is a frame on which detector will be applied.
// Param rois is a regions of interests mask generated by genRoi.
// Only the objects that fall into one of the regions will be returned.
// Param objects is an output array of Detections represented as GpuMat of detections (SCascade::Detection)
// The first element of the matrix is actually a count of detections.
// Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution
virtual
void
detect
(
InputArray
image
,
InputArray
rois
,
OutputArray
objects
,
cv
::
gpu
::
Stream
&
stream
=
cv
::
gpu
::
Stream
::
Null
())
const
;
private
:
struct
Fields
;
Fields
*
fields
;
double
minScale
;
double
maxScale
;
int
scales
;
int
flags
;
};
}}
// namespace cv { namespace softcascade {
#endif
\ No newline at end of file
modules/
gpu/perf/perf
_softcascade.cpp
→
modules/
softcascade/perf/perf_cuda
_softcascade.cpp
View file @
5120322c
#include "perf_precomp.hpp"
using
std
::
tr1
::
get
;
#define SC_PERF_TEST_P(fixture, name, params) \
class fixture##_##name : public fixture {\
public:\
...
...
@@ -25,8 +27,8 @@ void fixture##_##name::__cpu() { FAIL() << "No such CPU implementation analogy";
namespace
{
struct
DetectionLess
{
bool
operator
()(
const
cv
::
gpu
::
SCascade
::
Detection
&
a
,
const
cv
::
gpu
::
SCascade
::
Detection
&
b
)
const
bool
operator
()(
const
cv
::
softcascade
::
SCascade
::
Detection
&
a
,
const
cv
::
softcascade
::
SCascade
::
Detection
&
b
)
const
{
if
(
a
.
x
!=
b
.
x
)
return
a
.
x
<
b
.
x
;
else
if
(
a
.
y
!=
b
.
y
)
return
a
.
y
<
b
.
y
;
...
...
@@ -39,7 +41,7 @@ namespace {
{
cv
::
Mat
detections
(
objects
);
typedef
cv
::
gpu
::
SCascade
::
Detection
Detection
;
typedef
cv
::
softcascade
::
SCascade
::
Detection
Detection
;
Detection
*
begin
=
(
Detection
*
)(
detections
.
ptr
<
char
>
(
0
));
Detection
*
end
=
(
Detection
*
)(
detections
.
ptr
<
char
>
(
0
)
+
detections
.
cols
);
std
::
sort
(
begin
,
end
,
DetectionLess
());
...
...
@@ -60,18 +62,18 @@ SC_PERF_TEST_P(SCascadeTest, detect,
RUN_GPU
(
SCascadeTest
,
detect
)
{
cv
::
Mat
cpu
=
readImage
(
GET_PARAM
(
1
))
;
cv
::
Mat
cpu
=
cv
::
imread
(
getDataPath
(
get
<
1
>
(
GetParam
())));
;
ASSERT_FALSE
(
cpu
.
empty
());
cv
::
gpu
::
GpuMat
colored
(
cpu
);
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
perf
::
TestBase
::
getDataPath
(
GET_PARAM
(
0
)),
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
getDataPath
(
get
<
0
>
(
GetParam
()
)),
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
cv
::
gpu
::
GpuMat
objectBoxes
(
1
,
10000
*
sizeof
(
cv
::
gpu
::
SCascade
::
Detection
),
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
cv
::
gpu
::
GpuMat
objectBoxes
(
1
,
10000
*
sizeof
(
cv
::
softcascade
::
SCascade
::
Detection
),
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
1
);
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
...
...
@@ -118,13 +120,13 @@ SC_PERF_TEST_P(SCascadeTestRoi, detectInRoi,
RUN_GPU
(
SCascadeTestRoi
,
detectInRoi
)
{
cv
::
Mat
cpu
=
readImage
(
GET_PARAM
(
1
));
cv
::
Mat
cpu
=
cv
::
imread
(
getDataPath
(
get
<
1
>
(
GetParam
())
));
ASSERT_FALSE
(
cpu
.
empty
());
cv
::
gpu
::
GpuMat
colored
(
cpu
);
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
perf
::
TestBase
::
getDataPath
(
GET_PARAM
(
0
)),
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
getDataPath
(
get
<
0
>
(
GetParam
()
)),
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
...
...
@@ -132,7 +134,7 @@ RUN_GPU(SCascadeTestRoi, detectInRoi)
cv
::
gpu
::
GpuMat
objectBoxes
(
1
,
16384
*
20
,
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
0
);
int
nroi
=
GET_PARAM
(
2
);
int
nroi
=
get
<
2
>
(
GetParam
()
);
cv
::
RNG
rng
;
for
(
int
i
=
0
;
i
<
nroi
;
++
i
)
{
...
...
@@ -163,13 +165,13 @@ SC_PERF_TEST_P(SCascadeTestRoi, detectEachRoi,
RUN_GPU
(
SCascadeTestRoi
,
detectEachRoi
)
{
cv
::
Mat
cpu
=
readImage
(
GET_PARAM
(
1
));
cv
::
Mat
cpu
=
cv
::
imread
(
getDataPath
(
get
<
1
>
(
GetParam
())
));
ASSERT_FALSE
(
cpu
.
empty
());
cv
::
gpu
::
GpuMat
colored
(
cpu
);
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
perf
::
TestBase
::
getDataPath
(
GET_PARAM
(
0
)),
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
getDataPath
(
get
<
0
>
(
GetParam
()
)),
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
...
...
@@ -177,7 +179,7 @@ RUN_GPU(SCascadeTestRoi, detectEachRoi)
cv
::
gpu
::
GpuMat
objectBoxes
(
1
,
16384
*
20
,
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
0
);
int
idx
=
GET_PARAM
(
2
);
int
idx
=
get
<
2
>
(
GetParam
()
);
cv
::
Rect
r
=
getFromTable
(
idx
);
cv
::
gpu
::
GpuMat
sub
(
rois
,
r
);
sub
.
setTo
(
1
);
...
...
@@ -202,18 +204,18 @@ SC_PERF_TEST_P(SCascadeTest, detectStream,
RUN_GPU
(
SCascadeTest
,
detectStream
)
{
cv
::
Mat
cpu
=
readImage
(
GET_PARAM
(
1
));
cv
::
Mat
cpu
=
cv
::
imread
(
getDataPath
(
get
<
1
>
(
GetParam
())
));
ASSERT_FALSE
(
cpu
.
empty
());
cv
::
gpu
::
GpuMat
colored
(
cpu
);
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
perf
::
TestBase
::
getDataPath
(
GET_PARAM
(
0
)),
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
getDataPath
(
get
<
0
>
(
GetParam
()
)),
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
cv
::
gpu
::
GpuMat
objectBoxes
(
1
,
10000
*
sizeof
(
cv
::
gpu
::
SCascade
::
Detection
),
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
cv
::
gpu
::
GpuMat
objectBoxes
(
1
,
10000
*
sizeof
(
cv
::
softcascade
::
SCascade
::
Detection
),
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
1
);
cv
::
gpu
::
Stream
s
;
...
...
modules/
gpu
/src/cuda/icf-sc.cu
→
modules/
softcascade
/src/cuda/icf-sc.cu
View file @
5120322c
...
...
@@ -43,12 +43,11 @@
#include <opencv2/gpu/device/common.hpp>
#include <opencv2/gpu/device/saturate_cast.hpp>
#include <
icf
.hpp>
#include <
cuda_invoker
.hpp>
#include <float.h>
#include <stdio.h>
namespace cv { namespace gpu { namespace device {
namespace icf {
namespace cv { namespace softcascade { namespace device {
template <int FACTOR>
__device__ __forceinline__ uchar shrink(const uchar* ptr, const int pitch, const int y, const int x)
...
...
@@ -303,7 +302,7 @@ namespace icf {
excluded = excluded || (suppessed == i);
}
#if
__CUDA_ARCH__ >= 120
#if
defined __CUDA_ARCH__ && (__CUDA_ARCH__ >= 120)
if (__all(excluded)) break;
#endif
}
...
...
@@ -348,7 +347,7 @@ namespace icf {
template<typename Policy>
struct PrefixSum
{
__device static void apply(float& impact)
__device
_inline__
static void apply(float& impact)
{
#if defined __CUDA_ARCH__ && __CUDA_ARCH__ >= 300
#pragma unroll
...
...
@@ -442,6 +441,7 @@ namespace icf {
{
x += area.x;
y += area.y;
int a = tex2D(thogluv, x, y);
int b = tex2D(thogluv, x + area.z, y);
int c = tex2D(thogluv, x + area.z, y + area.w);
...
...
@@ -454,7 +454,7 @@ namespace icf {
template<typename Policy>
template<bool isUp>
__device void CascadeInvoker<Policy>::detect(Detection* objects, const uint ndetections, uint* ctr, const int downscales) const
__device
_inline__
void CascadeInvoker<Policy>::detect(Detection* objects, const uint ndetections, uint* ctr, const int downscales) const
{
const int y = blockIdx.y * blockDim.y + threadIdx.y;
const int x = blockIdx.x;
...
...
@@ -563,5 +563,4 @@ void CascadeInvoker<Policy>::operator()(const PtrStepSzb& roi, const PtrStepSzi&
template void CascadeInvoker<GK107PolicyX4>::operator()(const PtrStepSzb& roi, const PtrStepSzi& hogluv,
PtrStepSz<uchar4> objects, const int downscales, const cudaStream_t& stream) const;
}
}}}
modules/
gpu/src/icf
.hpp
→
modules/
softcascade/src/cuda_invoker
.hpp
View file @
5120322c
...
...
@@ -22,7 +22,7 @@
//
// * 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.
// 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.
...
...
@@ -46,15 +46,16 @@
#include <opencv2/gpu/device/common.hpp>
using
namespace
cv
::
gpu
::
device
;
#if defined __CUDACC__
# define __device __device__ __forceinline__
# define __device
_inline__
__device__ __forceinline__
#else
# define __device
# define __device
_inline__
#endif
namespace
cv
{
namespace
gpu
{
namespace
device
{
namespace
icf
{
namespace
cv
{
namespace
softcascade
{
namespace
device
{
struct
Octave
{
...
...
@@ -68,20 +69,19 @@ struct Octave
:
index
(
i
),
stages
(
s
),
shrinkage
(
sh
),
size
(
sz
),
scale
(
sc
)
{}
};
struct
Level
//is actually 24 bytes
struct
Level
{
int
octave
;
int
step
;
float
relScale
;
float
scaling
[
2
];
// calculated according to Dollal
paper
float
scaling
[
2
];
// calculated according to Dollar
paper
// for 640x480 we can not get overflow
uchar2
workRect
;
uchar2
objSize
;
Level
(
int
idx
,
const
Octave
&
oct
,
const
float
scale
,
const
int
w
,
const
int
h
);
__device
Level
(){}
__device
_inline__
Level
(){}
};
struct
Node
...
...
@@ -106,7 +106,7 @@ struct Detection
int
kind
;
Detection
(){}
__device
Detection
(
int
_x
,
int
_y
,
uchar
_w
,
uchar
_h
,
float
c
)
__device
_inline__
Detection
(
int
_x
,
int
_y
,
uchar
_w
,
uchar
_h
,
float
c
)
:
x
(
_x
),
y
(
_y
),
w
(
_w
),
h
(
_h
),
confidence
(
c
),
kind
(
0
)
{};
};
...
...
@@ -125,8 +125,8 @@ struct CascadeInvoker
{
CascadeInvoker
()
:
levels
(
0
),
stages
(
0
),
nodes
(
0
),
leaves
(
0
),
scales
(
0
)
{}
CascadeInvoker
(
const
PtrStepSzb
&
_levels
,
const
PtrStepSzf
&
_stages
,
const
PtrStepSzb
&
_nodes
,
const
PtrStepSzf
&
_leaves
)
CascadeInvoker
(
const
cv
::
gpu
::
PtrStepSzb
&
_levels
,
const
cv
::
gpu
::
PtrStepSzf
&
_stages
,
const
cv
::
gpu
::
PtrStepSzb
&
_nodes
,
const
cv
::
gpu
::
PtrStepSzf
&
_leaves
)
:
levels
((
const
Level
*
)
_levels
.
ptr
()),
stages
((
const
float
*
)
_stages
.
ptr
()),
nodes
((
const
Node
*
)
_nodes
.
ptr
()),
leaves
((
const
float
*
)
_leaves
.
ptr
()),
...
...
@@ -141,14 +141,13 @@ struct CascadeInvoker
int
scales
;
void
operator
()(
const
PtrStepSzb
&
roi
,
const
PtrStepSzi
&
hogluv
,
PtrStepSz
<
uchar4
>
objects
,
void
operator
()(
const
cv
::
gpu
::
PtrStepSzb
&
roi
,
const
cv
::
gpu
::
PtrStepSzi
&
hogluv
,
cv
::
gpu
::
PtrStepSz
<
uchar4
>
objects
,
const
int
downscales
,
const
cudaStream_t
&
stream
=
0
)
const
;
template
<
bool
isUp
>
__device
void
detect
(
Detection
*
objects
,
const
unsigned
int
ndetections
,
unsigned
int
*
ctr
,
const
int
downscales
)
const
;
__device
_inline__
void
detect
(
Detection
*
objects
,
const
unsigned
int
ndetections
,
unsigned
int
*
ctr
,
const
int
downscales
)
const
;
};
}
}}}
#endif
\ No newline at end of file
modules/
gpu/src/softcascade
.cpp
→
modules/
softcascade/src/detector_cuda
.cpp
View file @
5120322c
This diff is collapsed.
Click to expand it.
modules/softcascade/src/softcascade_init.cpp
View file @
5120322c
...
...
@@ -51,11 +51,16 @@ CV_INIT_ALGORITHM(Detector, "SoftCascade.Detector",
obj
.
info
()
->
addParam
(
obj
,
"scales"
,
obj
.
scales
);
obj
.
info
()
->
addParam
(
obj
,
"rejCriteria"
,
obj
.
rejCriteria
));
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
));
bool
initModule_softcascade
(
void
)
{
Ptr
<
Algorithm
>
sc
=
createSCascade
();
Ptr
<
Algorithm
>
sc1
=
createDetector
();
return
(
sc1
->
info
()
!=
0
);
return
(
sc1
->
info
()
!=
0
)
&&
(
sc
->
info
()
!=
0
)
;
}
}
}
\ No newline at end of file
modules/
gpu/test/test
_softcascade.cpp
→
modules/
softcascade/test/test_cuda
_softcascade.cpp
View file @
5120322c
...
...
@@ -41,10 +41,9 @@
//M*/
#include "test_precomp.hpp"
#include "opencv2/core/gpumat.hpp"
#ifdef HAVE_CUDA
using
cv
::
gpu
::
GpuMat
;
using
std
::
tr1
::
get
;
// show detection results on input image with cv::imshow
//#define SHOW_DETECTIONS
...
...
@@ -59,7 +58,7 @@ using cv::gpu::GpuMat;
static
std
::
string
path
(
std
::
string
relative
)
{
return
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"
../cv/
cascadeandhog/"
+
relative
;
return
cvtest
::
TS
::
ptr
()
->
get_data_path
()
+
"cascadeandhog/"
+
relative
;
}
TEST
(
SCascadeTest
,
readCascade
)
...
...
@@ -67,7 +66,7 @@ TEST(SCascadeTest, readCascade)
std
::
string
xml
=
path
(
"cascades/inria_caltech-17.01.2013.xml"
);
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
...
...
@@ -75,7 +74,7 @@ TEST(SCascadeTest, readCascade)
namespace
{
typedef
cv
::
gpu
::
SCascade
::
Detection
Detection
;
typedef
cv
::
softcascade
::
SCascade
::
Detection
Detection
;
cv
::
Rect
getFromTable
(
int
idx
)
{
...
...
@@ -97,7 +96,6 @@ namespace
return
rois
[
idx
];
}
void
print
(
std
::
ostream
&
out
,
const
Detection
&
d
)
{
#if defined SHOW_DETECTIONS
...
...
@@ -156,36 +154,36 @@ namespace
#endif
}
PARAM_TEST_CASE
(
SCascadeTestRoi
,
cv
::
gpu
::
DeviceInfo
,
std
::
string
,
std
::
string
,
int
)
class
SCascadeTestRoi
:
public
::
testing
::
TestWithParam
<
std
::
tr1
::
tuple
<
cv
::
gpu
::
DeviceInfo
,
std
::
string
,
std
::
string
,
int
>
>
{
virtual
void
SetUp
()
{
cv
::
gpu
::
setDevice
(
GET_PARAM
(
0
).
deviceID
());
cv
::
gpu
::
setDevice
(
get
<
0
>
(
GetParam
()
).
deviceID
());
}
};
GPU_
TEST_P
(
SCascadeTestRoi
,
Detect
)
TEST_P
(
SCascadeTestRoi
,
Detect
)
{
cv
::
Mat
coloredCpu
=
cv
::
imread
(
path
(
GET_PARAM
(
2
)));
cv
::
Mat
coloredCpu
=
cv
::
imread
(
path
(
get
<
2
>
(
GetParam
()
)));
ASSERT_FALSE
(
coloredCpu
.
empty
());
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
path
(
GET_PARAM
(
1
)),
cv
::
FileStorage
::
READ
);
cv
::
FileStorage
fs
(
path
(
get
<
1
>
(
GetParam
()
)),
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
ASSERT_TRUE
(
cascade
.
load
(
fs
.
getFirstTopLevelNode
()));
GpuMat
colored
(
coloredCpu
),
objectBoxes
(
1
,
16384
,
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
cv
::
gpu
::
GpuMat
colored
(
coloredCpu
),
objectBoxes
(
1
,
16384
,
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
0
);
int
nroi
=
GET_PARAM
(
3
);
int
nroi
=
get
<
3
>
(
GetParam
()
);
cv
::
Mat
result
(
coloredCpu
);
cv
::
RNG
rng
;
for
(
int
i
=
0
;
i
<
nroi
;
++
i
)
{
cv
::
Rect
r
=
getFromTable
(
rng
(
10
));
GpuMat
sub
(
rois
,
r
);
cv
::
gpu
::
GpuMat
sub
(
rois
,
r
);
sub
.
setTo
(
1
);
cv
::
rectangle
(
result
,
r
,
cv
::
Scalar
(
0
,
0
,
255
,
255
),
1
);
}
...
...
@@ -194,7 +192,7 @@ GPU_TEST_P(SCascadeTestRoi, Detect)
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
cv
::
Mat
dt
(
objectBoxes
);
typedef
cv
::
gpu
::
SCascade
::
Detection
Detection
;
typedef
cv
::
softcascade
::
SCascade
::
Detection
Detection
;
Detection
*
dts
=
((
Detection
*
)
dt
.
data
)
+
1
;
int
*
count
=
dt
.
ptr
<
int
>
(
0
);
...
...
@@ -211,15 +209,13 @@ GPU_TEST_P(SCascadeTestRoi, Detect)
SHOW
(
result
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_SoftCascade
,
SCascadeTestRoi
,
testing
::
Combine
(
ALL_DEVICES
,
INSTANTIATE_TEST_CASE_P
(
cuda_accelerated
,
SCascadeTestRoi
,
testing
::
Combine
(
testing
::
ValuesIn
(
DeviceManager
::
instance
().
values
())
,
testing
::
Values
(
std
::
string
(
"cascades/inria_caltech-17.01.2013.xml"
),
std
::
string
(
"cascades/sc_cvpr_2012_to_opencv_new_format.xml"
)),
testing
::
Values
(
std
::
string
(
"images/image_00000000_0.png"
)),
testing
::
Range
(
0
,
5
)));
////////////////////////////////////////
namespace
{
struct
Fixture
...
...
@@ -232,23 +228,24 @@ struct Fixture
};
}
PARAM_TEST_CASE
(
SCascadeTestAll
,
cv
::
gpu
::
DeviceInfo
,
Fixture
)
typedef
std
::
tr1
::
tuple
<
cv
::
gpu
::
DeviceInfo
,
Fixture
>
SCascadeTestAllFixture
;
class
SCascadeTestAll
:
public
::
testing
::
TestWithParam
<
SCascadeTestAllFixture
>
{
protected
:
std
::
string
xml
;
int
expected
;
virtual
void
SetUp
()
{
cv
::
gpu
::
setDevice
(
GET_PARAM
(
0
).
deviceID
());
xml
=
path
(
GET_PARAM
(
1
).
path
);
expected
=
GET_PARAM
(
1
).
expected
;
cv
::
gpu
::
setDevice
(
get
<
0
>
(
GetParam
()
).
deviceID
());
xml
=
path
(
get
<
1
>
(
GetParam
()
).
path
);
expected
=
get
<
1
>
(
GetParam
()
).
expected
;
}
};
GPU_
TEST_P
(
SCascadeTestAll
,
detect
)
TEST_P
(
SCascadeTestAll
,
detect
)
{
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
...
...
@@ -258,12 +255,12 @@ GPU_TEST_P(SCascadeTestAll, detect)
cv
::
Mat
coloredCpu
=
cv
::
imread
(
path
(
"images/image_00000000_0.png"
));
ASSERT_FALSE
(
coloredCpu
.
empty
());
GpuMat
colored
(
coloredCpu
),
objectBoxes
,
rois
(
colored
.
size
(),
CV_8UC1
);
cv
::
gpu
::
GpuMat
colored
(
coloredCpu
),
objectBoxes
,
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
1
);
cascade
.
detect
(
colored
,
rois
,
objectBoxes
);
typedef
cv
::
gpu
::
SCascade
::
Detection
Detection
;
typedef
cv
::
softcascade
::
SCascade
::
Detection
Detection
;
cv
::
Mat
dt
(
objectBoxes
);
...
...
@@ -283,9 +280,9 @@ GPU_TEST_P(SCascadeTestAll, detect)
ASSERT_EQ
(
*
count
,
expected
);
}
GPU_
TEST_P
(
SCascadeTestAll
,
detectStream
)
TEST_P
(
SCascadeTestAll
,
detectStream
)
{
cv
::
gpu
::
SCascade
cascade
;
cv
::
softcascade
::
SCascade
cascade
;
cv
::
FileStorage
fs
(
xml
,
cv
::
FileStorage
::
READ
);
ASSERT_TRUE
(
fs
.
isOpened
());
...
...
@@ -295,7 +292,7 @@ GPU_TEST_P(SCascadeTestAll, detectStream)
cv
::
Mat
coloredCpu
=
cv
::
imread
(
path
(
"images/image_00000000_0.png"
));
ASSERT_FALSE
(
coloredCpu
.
empty
());
GpuMat
colored
(
coloredCpu
),
objectBoxes
(
1
,
100000
,
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
cv
::
gpu
::
GpuMat
colored
(
coloredCpu
),
objectBoxes
(
1
,
100000
,
CV_8UC1
),
rois
(
colored
.
size
(),
CV_8UC1
);
rois
.
setTo
(
cv
::
Scalar
::
all
(
1
));
cv
::
gpu
::
Stream
s
;
...
...
@@ -304,14 +301,12 @@ GPU_TEST_P(SCascadeTestAll, detectStream)
cascade
.
detect
(
colored
,
rois
,
objectBoxes
,
s
);
s
.
waitForCompletion
();
typedef
cv
::
gpu
::
SCascade
::
Detection
Detection
;
typedef
cv
::
softcascade
::
SCascade
::
Detection
Detection
;
cv
::
Mat
detections
(
objectBoxes
);
int
a
=
*
(
detections
.
ptr
<
int
>
(
0
));
ASSERT_EQ
(
a
,
expected
);
}
INSTANTIATE_TEST_CASE_P
(
GPU_SoftCascade
,
SCascadeTestAll
,
testing
::
Combine
(
ALL_DEVICES
,
INSTANTIATE_TEST_CASE_P
(
cuda_accelerated
,
SCascadeTestAll
,
testing
::
Combine
(
ALL_DEVICES
,
testing
::
Values
(
Fixture
(
"cascades/inria_caltech-17.01.2013.xml"
,
7
),
Fixture
(
"cascades/sc_cvpr_2012_to_opencv_new_format.xml"
,
1291
))));
\ No newline at end of file
#endif
modules/softcascade/test/test_main.cpp
View file @
5120322c
modules/softcascade/test/utility.cpp
0 → 100644
View file @
5120322c
/*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.
//
//
// Intel License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000, Intel Corporation, 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 Intel Corporation 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 Intel Corporation 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 "test_precomp.hpp"
#ifdef HAVE_CUDA
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
::
gpu
;
using
namespace
cvtest
;
using
namespace
testing
;
using
namespace
testing
::
internal
;
//////////////////////////////////////////////////////////////////////
// Gpu devices
bool
supportFeature
(
const
DeviceInfo
&
info
,
FeatureSet
feature
)
{
return
TargetArchs
::
builtWith
(
feature
)
&&
info
.
supports
(
feature
);
}
DeviceManager
&
DeviceManager
::
instance
()
{
static
DeviceManager
obj
;
return
obj
;
}
void
DeviceManager
::
load
(
int
i
)
{
devices_
.
clear
();
devices_
.
reserve
(
1
);
std
::
ostringstream
msg
;
if
(
i
<
0
||
i
>=
getCudaEnabledDeviceCount
())
{
msg
<<
"Incorrect device number - "
<<
i
;
CV_Error
(
CV_StsBadArg
,
msg
.
str
());
}
DeviceInfo
info
(
i
);
if
(
!
info
.
isCompatible
())
{
msg
<<
"Device "
<<
i
<<
" ["
<<
info
.
name
()
<<
"] is NOT compatible with current GPU module build"
;
CV_Error
(
CV_StsBadArg
,
msg
.
str
());
}
devices_
.
push_back
(
info
);
}
void
DeviceManager
::
loadAll
()
{
int
deviceCount
=
getCudaEnabledDeviceCount
();
devices_
.
clear
();
devices_
.
reserve
(
deviceCount
);
for
(
int
i
=
0
;
i
<
deviceCount
;
++
i
)
{
DeviceInfo
info
(
i
);
if
(
info
.
isCompatible
())
{
devices_
.
push_back
(
info
);
}
}
}
#endif // HAVE_CUDA
modules/
gpu/src/gpu_init.c
pp
→
modules/
softcascade/test/utility.h
pp
View file @
5120322c
...
...
@@ -7,11 +7,10 @@
// copy or use the software.
//
//
// License Agreement
//
Intel
License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2008-2012, Willow Garage Inc., all rights reserved.
// Copyright (C) 2000, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
//
// Redistribution and use in source and binary forms, with or without modification,
...
...
@@ -24,7 +23,7 @@
// 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
//
* The name of Intel Corporation
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
...
...
@@ -40,20 +39,35 @@
//
//M*/
#include "precomp.hpp"
#ifndef __OPENCV_SOFTCASCADE_TEST_UTILITY_HPP__
#define __OPENCV_SOFTCASCADE_TEST_UTILITY_HPP__
namespace
cv
{
namespace
gpu
{
#include "opencv2/core/core.hpp"
#include "opencv2/core/gpumat.hpp"
#include "opencv2/ts/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
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
)
);
//////////////////////////////////////////////////////////////////////
// Gpu devices
//! return true if device supports specified feature and gpu module was built with support the feature.
bool
supportFeature
(
const
cv
::
gpu
::
DeviceInfo
&
info
,
cv
::
gpu
::
FeatureSet
feature
);
bool
initModule_gpu
(
void
)
class
DeviceManager
{
Ptr
<
Algorithm
>
sc
=
createSCascade
();
return
sc
->
info
()
!=
0
;
}
public
:
static
DeviceManager
&
instance
();
void
load
(
int
i
);
void
loadAll
();
const
std
::
vector
<
cv
::
gpu
::
DeviceInfo
>&
values
()
const
{
return
devices_
;
}
private
:
std
::
vector
<
cv
::
gpu
::
DeviceInfo
>
devices_
;
DeviceManager
()
{
loadAll
();}
};
#define ALL_DEVICES testing::ValuesIn(DeviceManager::instance().values())
}
}
\ No newline at end of file
#endif // __OPENCV_GPU_TEST_UTILITY_HPP__
samples/gpu/CMakeLists.txt
View file @
5120322c
SET
(
OPENCV_GPU_SAMPLES_REQUIRED_DEPS opencv_core opencv_flann opencv_imgproc opencv_highgui
opencv_ml opencv_video opencv_objdetect opencv_features2d
opencv_calib3d opencv_legacy opencv_contrib opencv_gpu
opencv_nonfree
)
opencv_nonfree
opencv_softcascade
)
ocv_check_dependencies
(
${
OPENCV_GPU_SAMPLES_REQUIRED_DEPS
}
)
...
...
samples/gpu/softcascade.cpp
View file @
5120322c
#include <opencv2/gpu/gpu.hpp>
#include <opencv2/softcascade/softcascade.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
...
...
@@ -46,7 +47,7 @@ int main(int argc, char** argv)
float
maxScale
=
parser
.
get
<
float
>
(
"max_scale"
);
int
scales
=
parser
.
get
<
int
>
(
"total_scales"
);
using
cv
::
gpu
::
SCascade
;
using
cv
::
softcascade
::
SCascade
;
SCascade
cascade
(
minScale
,
maxScale
,
scales
);
if
(
!
cascade
.
load
(
fs
.
getFirstTopLevelNode
()))
...
...
@@ -79,7 +80,7 @@ int main(int argc, char** argv)
cascade
.
detect
(
dframe
,
roi
,
objects
);
cv
::
Mat
dt
(
objects
);
typedef
cv
::
gpu
::
SCascade
::
Detection
Detection
;
typedef
cv
::
softcascade
::
SCascade
::
Detection
Detection
;
Detection
*
dts
=
((
Detection
*
)
dt
.
data
)
+
1
;
int
*
count
=
dt
.
ptr
<
int
>
(
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