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
72b499df
Commit
72b499df
authored
Sep 27, 2012
by
marina.kolpakova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add detection storing
parent
8108bd30
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
47 deletions
+31
-47
perf_objdetect.cpp
modules/gpu/perf/perf_objdetect.cpp
+2
-2
isf-sc.cu
modules/gpu/src/cuda/isf-sc.cu
+19
-40
softcascade.cpp
modules/gpu/src/softcascade.cpp
+10
-5
No files found.
modules/gpu/perf/perf_objdetect.cpp
View file @
72b499df
...
...
@@ -104,7 +104,7 @@ PERF_TEST_P(SoftCascade, detect, Values<pair_string>(make_pair("cv/cascadeandhog
cv
::
gpu
::
SoftCascade
cascade
;
ASSERT_TRUE
(
cascade
.
load
(
perf
::
TestBase
::
getDataPath
(
GetParam
().
first
)));
cv
::
gpu
::
GpuMat
rois
,
objectBoxes
(
1
,
1000
,
CV_8UC
1
);
cv
::
gpu
::
GpuMat
rois
,
objectBoxes
(
1
,
1000
,
CV_8UC
4
);
cascade
.
detectMultiScale
(
colored
,
rois
,
objectBoxes
);
TEST_CYCLE
()
...
...
@@ -117,7 +117,7 @@ PERF_TEST_P(SoftCascade, detect, Values<pair_string>(make_pair("cv/cascadeandhog
ASSERT_FALSE
(
colored
.
empty
());
cv
::
SoftCascade
cascade
;
ASSERT_TRUE
(
cascade
.
load
(
GetParam
().
first
));
ASSERT_TRUE
(
cascade
.
load
(
getDataPath
(
GetParam
().
first
)
));
std
::
vector
<
cv
::
Rect
>
rois
,
objectBoxes
;
cascade
.
detectMultiScale
(
colored
,
rois
,
objectBoxes
);
...
...
modules/gpu/src/cuda/isf-sc.cu
View file @
72b499df
...
...
@@ -57,14 +57,6 @@
namespace cv { namespace gpu { namespace device {
namespace icf {
// enum {
// HOG_BINS = 6,
// HOG_LUV_BINS = 10,
// WIDTH = 640,
// HEIGHT = 480,
// GREY_OFFSET = HEIGHT * HOG_LUV_BINS
// };
// ToDo: use textures or ancached load instruction.
__global__ void magToHist(const uchar* __restrict__ mag,
const float* __restrict__ angle, const int angPitch,
...
...
@@ -94,13 +86,6 @@ namespace icf {
}
texture<int, cudaTextureType2D, cudaReadModeElementType> thogluv;
// ToDo: do it in load time
// __device__ __forceinline__ float rescale(const Level& level, uchar4& scaledRect, const Node& node)
// {
// scaledRect = node.rect;
// return (float)(node.threshold & 0x0FFFFFFFU);
// }
__device__ __forceinline__ float rescale(const Level& level, uchar4& scaledRect, const Node& node)
{
float relScale = level.relScale;
...
...
@@ -119,17 +104,12 @@ namespace icf {
float sarea = (scaledRect.z - scaledRect.x) * (scaledRect.w - scaledRect.y);
float approx = 1.f;
// if (fabs(farea - 0.f) > FLT_EPSILON && fabs(farea - 0.f) > FLT_EPSILON)
{
const float expected_new_area = farea * relScale * relScale;
approx = sarea / expected_new_area;
}
const float expected_new_area = farea * relScale * relScale;
float approx = sarea / expected_new_area;
dprintf("new rect: %d box %d %d %d %d rel areas %f %f\n", (node.threshold >> 28),
scaledRect.x, scaledRect.y, scaledRect.z, scaledRect.w, farea * relScale * relScale, sarea);
float rootThreshold = (node.threshold & 0x0FFFFFFFU) * approx;
rootThreshold *= level.scaling[(node.threshold >> 28) > 6];
...
...
@@ -139,7 +119,7 @@ namespace icf {
return rootThreshold;
}
__device__ __forceinline__ int get(const int x, int y,
int channel,
uchar4 area)
__device__ __forceinline__ int get(const int x, int y, uchar4 area)
{
dprintf("feature box %d %d %d %d ", area.x, area.y, area.z, area.w);
...
...
@@ -149,9 +129,6 @@ namespace icf {
x + area.x, y + area.w);
dprintf("at point %d %d with offset %d\n", x, y, 0);
int offset = channel * 121;
y += offset;
int a = tex2D(thogluv, x + area.x, y + area.y);
int b = tex2D(thogluv, x + area.z, y + area.y);
int c = tex2D(thogluv, x + area.z, y + area.w);
...
...
@@ -163,7 +140,7 @@ namespace icf {
}
__global__ void test_kernel(const Level* levels, const Octave* octaves, const float* stages,
const Node* nodes, const float* leaves, PtrStepSz<uchar4> objects)
const Node* nodes, const float* leaves, PtrStepSz<uchar4> objects
, uint* ctr
)
{
const int y = blockIdx.y * blockDim.y + threadIdx.y;
const int x = blockIdx.x * blockDim.x + threadIdx.x;
...
...
@@ -179,7 +156,7 @@ namespace icf {
float confidence = 0.f;
// #pragma unroll
8
// #pragma unroll
2
for(; st < stEnd; ++st)
{
dprintf("\n\nstage: %d\n", st);
...
...
@@ -190,7 +167,7 @@ namespace icf {
node.threshold >> 28, node.threshold & 0x0FFFFFFFU);
float threshold = rescale(level, node.rect, node);
int sum = get(x, y
, (node.threshold >> 28)
, node.rect);
int sum = get(x, y
+ (node.threshold >> 28) * 121
, node.rect);
dprintf("Node: [%d %d %d %d] %f\n", node.rect.x, node.rect.y, node.rect.z,
node.rect.w, threshold);
...
...
@@ -200,29 +177,30 @@ namespace icf {
node = nodes[nId + next];
threshold = rescale(level, node.rect, node);
sum = get(x, y
, (node.threshold >> 28)
, node.rect);
sum = get(x, y
+ (node.threshold >> 28) * 121
, node.rect);
const int lShift = (next - 1) * 2 + (int)(sum >= threshold);
float impact = leaves[st * 4 + lShift];
confidence += impact;
if (confidence <= stages[st]) st = stEnd + 1;
if (confidence <= stages[st]) st = stEnd + 1
0
;
dprintf("decided: %d (%d >= %f) %d %f\n\n" ,next, sum, threshold, lShift, impact);
dprintf("extracted stage: %f\n", stages[st]);
dprintf("computed score: %f\n\n", confidence);
}
// if
(st == stEnd)
// printf("%d %d %d\n", x, y, st);
uchar4 val;
val.x = (int)confidence
;
if (x == y) objects(0, threadIdx.
x) = val;
if
(st == stEnd)
{
int idx = atomicInc(ctr, objects.cols);
uchar4 val;
val.x = x * 4
;
objects(0, id
x) = val;
}
}
void detect(const PtrStepSzb& levels, const PtrStepSzb& octaves, const PtrStepSzf& stages,
const PtrStepSzb& nodes, const PtrStepSzf& leaves, const PtrStepSzi& hogluv, PtrStepSz<uchar4> objects)
const PtrStepSzb& nodes, const PtrStepSzf& leaves, const PtrStepSzi& hogluv,
PtrStepSz<uchar4> objects, PtrStepSzi counter)
{
int fw = 160;
int fh = 120;
...
...
@@ -235,11 +213,12 @@ namespace icf {
const float* st = (const float*)stages.ptr();
const Node* nd = (const Node*)nodes.ptr();
const float* lf = (const float*)leaves.ptr();
uint* ctr = (uint*)counter.ptr();
cudaChannelFormatDesc desc = cudaCreateChannelDesc<int>();
cudaSafeCall( cudaBindTexture2D(0, thogluv, hogluv.data, desc, hogluv.cols, hogluv.rows, hogluv.step));
test_kernel<<<grid, block>>>(l, oct, st, nd, lf, objects);
test_kernel<<<grid, block>>>(l, oct, st, nd, lf, objects
, ctr
);
cudaSafeCall( cudaGetLastError());
cudaSafeCall( cudaDeviceSynchronize());
...
...
modules/gpu/src/softcascade.cpp
View file @
72b499df
...
...
@@ -60,7 +60,8 @@ namespace icf {
void
fillBins
(
cv
::
gpu
::
PtrStepSzb
hogluv
,
const
cv
::
gpu
::
PtrStepSzf
&
nangle
,
const
int
fw
,
const
int
fh
,
const
int
bins
);
void
detect
(
const
PtrStepSzb
&
levels
,
const
PtrStepSzb
&
octaves
,
const
PtrStepSzf
&
stages
,
const
PtrStepSzb
&
nodes
,
const
PtrStepSzf
&
leaves
,
const
PtrStepSzi
&
hogluv
,
PtrStepSz
<
uchar4
>
objects
);
const
PtrStepSzb
&
nodes
,
const
PtrStepSzf
&
leaves
,
const
PtrStepSzi
&
hogluv
,
PtrStepSz
<
uchar4
>
objects
,
PtrStepSzi
counter
);
}
}}}
...
...
@@ -75,6 +76,7 @@ struct cv::gpu::SoftCascade::Filds
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
);
detCounter
.
create
(
1
,
1
,
CV_32SC1
);
}
// scales range
...
...
@@ -90,6 +92,8 @@ struct cv::gpu::SoftCascade::Filds
GpuMat
leaves
;
GpuMat
levels
;
GpuMat
detCounter
;
// preallocated buffer 640x480x10 for hogluv + 640x480 got gray
GpuMat
plane
;
...
...
@@ -127,7 +131,8 @@ struct cv::gpu::SoftCascade::Filds
bool
fill
(
const
FileNode
&
root
,
const
float
mins
,
const
float
maxs
);
void
detect
(
cv
::
gpu
::
GpuMat
objects
,
cudaStream_t
stream
)
const
{
device
::
icf
::
detect
(
levels
,
octaves
,
stages
,
nodes
,
leaves
,
hogluv
,
objects
);
cudaMemset
(
detCounter
.
data
,
0
,
detCounter
.
step
*
detCounter
.
rows
*
sizeof
(
int
));
device
::
icf
::
detect
(
levels
,
octaves
,
stages
,
nodes
,
leaves
,
hogluv
,
objects
,
detCounter
);
}
private
:
...
...
@@ -506,14 +511,13 @@ void cv::gpu::SoftCascade::detectMultiScale(const GpuMat& colored, const GpuMat&
GpuMat
sum
(
flds
.
hogluv
,
cv
::
Rect
(
0
,
(
fh
+
1
)
*
i
,
fw
+
1
,
fh
+
1
));
cv
::
gpu
::
integralBuffered
(
channel
,
sum
,
flds
.
integralBuffer
);
}
#endif
cudaStream_t
stream
=
StreamAccessor
::
getStream
(
s
);
// detection
flds
.
detect
(
objects
,
stream
);
// // flds.storage.frame(colored, stream);
// cv::Mat out(flds.detCounter);
// std::cout << out << std::endl;
}
#endif
\ 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