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
3562a05d
Commit
3562a05d
authored
Oct 10, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8940 from 678098:nonblocking_haar_detector_parallel_for
parents
b7ff9ddc
d0ab595f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
17 deletions
+80
-17
haar.cpp
modules/objdetect/src/haar.cpp
+80
-17
No files found.
modules/objdetect/src/haar.cpp
View file @
3562a05d
...
@@ -931,6 +931,8 @@ cvRunHaarClassifierCascade( const CvHaarClassifierCascade* _cascade,
...
@@ -931,6 +931,8 @@ cvRunHaarClassifierCascade( const CvHaarClassifierCascade* _cascade,
namespace
cv
namespace
cv
{
{
const
size_t
PARALLEL_LOOP_BATCH_SIZE
=
100
;
class
HaarDetectObjects_ScaleImage_Invoker
:
public
ParallelLoopBody
class
HaarDetectObjects_ScaleImage_Invoker
:
public
ParallelLoopBody
{
{
public
:
public
:
...
@@ -969,6 +971,10 @@ public:
...
@@ -969,6 +971,10 @@ public:
Size
ssz
(
sum1
.
cols
-
1
-
winSize0
.
width
,
y2
-
y1
);
Size
ssz
(
sum1
.
cols
-
1
-
winSize0
.
width
,
y2
-
y1
);
int
x
,
y
,
ystep
=
factor
>
2
?
1
:
2
;
int
x
,
y
,
ystep
=
factor
>
2
?
1
:
2
;
std
::
vector
<
Rect
>
vecLocal
;
std
::
vector
<
int
>
rejectLevelsLocal
;
std
::
vector
<
double
>
levelWeightsLocal
;
#ifdef HAVE_IPP
#ifdef HAVE_IPP
if
(
CV_IPP_CHECK_COND
&&
cascade
->
hid_cascade
->
ipp_stages
)
if
(
CV_IPP_CHECK_COND
&&
cascade
->
hid_cascade
->
ipp_stages
)
{
{
...
@@ -1015,10 +1021,17 @@ public:
...
@@ -1015,10 +1021,17 @@ public:
for
(
x
=
0
;
x
<
ssz
.
width
;
x
+=
ystep
)
for
(
x
=
0
;
x
<
ssz
.
width
;
x
+=
ystep
)
if
(
mask1row
[
x
]
!=
0
)
if
(
mask1row
[
x
]
!=
0
)
{
{
mtx
->
lock
();
vecLocal
.
push_back
(
Rect
(
cvRound
(
x
*
factor
),
cvRound
(
y
*
factor
),
vec
->
push_back
(
Rect
(
cvRound
(
x
*
factor
),
cvRound
(
y
*
factor
),
winSize
.
width
,
winSize
.
height
));
winSize
.
width
,
winSize
.
height
));
mtx
->
unlock
();
if
(
vecLocal
.
size
()
>=
PARALLEL_LOOP_BATCH_SIZE
)
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
mtx
->
unlock
();
vecLocal
.
clear
();
}
if
(
--
positive
==
0
)
if
(
--
positive
==
0
)
break
;
break
;
}
}
...
@@ -1039,25 +1052,59 @@ public:
...
@@ -1039,25 +1052,59 @@ public:
result
=
-
1
*
cascade
->
count
;
result
=
-
1
*
cascade
->
count
;
if
(
cascade
->
count
+
result
<
4
)
if
(
cascade
->
count
+
result
<
4
)
{
{
mtx
->
lock
();
vecLocal
.
push_back
(
Rect
(
cvRound
(
x
*
factor
),
cvRound
(
y
*
factor
),
vec
->
push_back
(
Rect
(
cvRound
(
x
*
factor
),
cvRound
(
y
*
factor
),
winSize
.
width
,
winSize
.
height
));
winSize
.
width
,
winSize
.
height
));
rejectLevelsLocal
.
push_back
(
-
result
);
rejectLevels
->
push_back
(
-
result
);
levelWeightsLocal
.
push_back
(
gypWeight
);
levelWeights
->
push_back
(
gypWeight
);
mtx
->
unlock
();
if
(
vecLocal
.
size
()
>=
PARALLEL_LOOP_BATCH_SIZE
)
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
rejectLevels
->
insert
(
rejectLevels
->
end
(),
rejectLevelsLocal
.
begin
(),
rejectLevelsLocal
.
end
());
levelWeights
->
insert
(
levelWeights
->
end
(),
levelWeightsLocal
.
begin
(),
levelWeightsLocal
.
end
());
mtx
->
unlock
();
vecLocal
.
clear
();
rejectLevelsLocal
.
clear
();
levelWeightsLocal
.
clear
();
}
}
}
}
}
else
else
{
{
if
(
result
>
0
)
if
(
result
>
0
)
{
{
mtx
->
lock
();
vecLocal
.
push_back
(
Rect
(
cvRound
(
x
*
factor
),
cvRound
(
y
*
factor
),
vec
->
push_back
(
Rect
(
cvRound
(
x
*
factor
),
cvRound
(
y
*
factor
),
winSize
.
width
,
winSize
.
height
));
winSize
.
width
,
winSize
.
height
));
mtx
->
unlock
();
if
(
vecLocal
.
size
()
>=
PARALLEL_LOOP_BATCH_SIZE
)
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
mtx
->
unlock
();
vecLocal
.
clear
();
}
}
}
}
}
}
}
if
(
rejectLevelsLocal
.
size
())
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
rejectLevels
->
insert
(
rejectLevels
->
end
(),
rejectLevelsLocal
.
begin
(),
rejectLevelsLocal
.
end
());
levelWeights
->
insert
(
levelWeights
->
end
(),
levelWeightsLocal
.
begin
(),
levelWeightsLocal
.
end
());
mtx
->
unlock
();
}
else
if
(
vecLocal
.
size
())
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
mtx
->
unlock
();
}
}
}
const
CvHaarClassifierCascade
*
cascade
;
const
CvHaarClassifierCascade
*
cascade
;
...
@@ -1100,6 +1147,8 @@ public:
...
@@ -1100,6 +1147,8 @@ public:
bool
doCannyPruning
=
p0
!=
0
;
bool
doCannyPruning
=
p0
!=
0
;
int
sstep
=
(
int
)(
sumstep
/
sizeof
(
p0
[
0
]));
int
sstep
=
(
int
)(
sumstep
/
sizeof
(
p0
[
0
]));
std
::
vector
<
Rect
>
vecLocal
;
for
(
iy
=
startY
;
iy
<
endY
;
iy
++
)
for
(
iy
=
startY
;
iy
<
endY
;
iy
++
)
{
{
int
ix
,
y
=
cvRound
(
iy
*
ystep
),
ixstep
=
1
;
int
ix
,
y
=
cvRound
(
iy
*
ystep
),
ixstep
=
1
;
...
@@ -1122,13 +1171,27 @@ public:
...
@@ -1122,13 +1171,27 @@ public:
int
result
=
cvRunHaarClassifierCascade
(
cascade
,
cvPoint
(
x
,
y
),
0
);
int
result
=
cvRunHaarClassifierCascade
(
cascade
,
cvPoint
(
x
,
y
),
0
);
if
(
result
>
0
)
if
(
result
>
0
)
{
{
mtx
->
lock
();
vecLocal
.
push_back
(
Rect
(
x
,
y
,
winsize
.
width
,
winsize
.
height
));
vec
->
push_back
(
Rect
(
x
,
y
,
winsize
.
width
,
winsize
.
height
));
mtx
->
unlock
();
if
(
vecLocal
.
size
()
>=
PARALLEL_LOOP_BATCH_SIZE
)
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
mtx
->
unlock
();
vecLocal
.
clear
();
}
}
}
ixstep
=
result
!=
0
?
1
:
2
;
ixstep
=
result
!=
0
?
1
:
2
;
}
}
}
}
if
(
vecLocal
.
size
())
{
mtx
->
lock
();
vec
->
insert
(
vec
->
end
(),
vecLocal
.
begin
(),
vecLocal
.
end
());
mtx
->
unlock
();
}
}
}
const
CvHaarClassifierCascade
*
cascade
;
const
CvHaarClassifierCascade
*
cascade
;
...
...
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