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
1e8194fd
Commit
1e8194fd
authored
Aug 22, 2013
by
Jin Ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized mog and mog2, which have much better performance.
parent
1bcd1fd3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
4 deletions
+13
-4
bgfg_mog.cpp
modules/ocl/src/bgfg_mog.cpp
+12
-3
bgfg_mog.cl
modules/ocl/src/opencl/bgfg_mog.cl
+0
-0
test_bgfg.cpp
modules/ocl/test/test_bgfg.cpp
+1
-1
No files found.
modules/ocl/src/bgfg_mog.cpp
View file @
1e8194fd
...
@@ -254,7 +254,7 @@ static void mog_withoutLearning(const oclMat& frame, int cn, oclMat& fgmask, ocl
...
@@ -254,7 +254,7 @@ static void mog_withoutLearning(const oclMat& frame, int cn, oclMat& fgmask, ocl
}
}
static
void
mog_withLearning
(
const
oclMat
&
frame
,
int
cn
,
oclMat
&
fgmask
,
oclMat
&
weight
,
oclMat
&
sortKey
,
oclMat
&
mean
,
oclMat
&
var
,
static
void
mog_withLearning
(
const
oclMat
&
frame
,
int
cn
,
oclMat
&
fgmask
_raw
,
oclMat
&
weight
,
oclMat
&
sortKey
,
oclMat
&
mean
,
oclMat
&
var
,
int
nmixtures
,
float
varThreshold
,
float
backgroundRatio
,
float
learningRate
,
float
minVar
)
int
nmixtures
,
float
varThreshold
,
float
backgroundRatio
,
float
learningRate
,
float
minVar
)
{
{
Context
*
clCxt
=
Context
::
getContext
();
Context
*
clCxt
=
Context
::
getContext
();
...
@@ -262,6 +262,8 @@ static void mog_withLearning(const oclMat& frame, int cn, oclMat& fgmask, oclMat
...
@@ -262,6 +262,8 @@ static void mog_withLearning(const oclMat& frame, int cn, oclMat& fgmask, oclMat
size_t
local_thread
[]
=
{
32
,
8
,
1
};
size_t
local_thread
[]
=
{
32
,
8
,
1
};
size_t
global_thread
[]
=
{
frame
.
cols
,
frame
.
rows
,
1
};
size_t
global_thread
[]
=
{
frame
.
cols
,
frame
.
rows
,
1
};
oclMat
fgmask
(
fgmask_raw
.
size
(),
CV_32SC1
);
int
frame_step
=
(
int
)(
frame
.
step
/
frame
.
elemSize
());
int
frame_step
=
(
int
)(
frame
.
step
/
frame
.
elemSize
());
int
fgmask_step
=
(
int
)(
fgmask
.
step
/
fgmask
.
elemSize
());
int
fgmask_step
=
(
int
)(
fgmask
.
step
/
fgmask
.
elemSize
());
int
weight_step
=
(
int
)(
weight
.
step
/
weight
.
elemSize
());
int
weight_step
=
(
int
)(
weight
.
step
/
weight
.
elemSize
());
...
@@ -318,6 +320,8 @@ static void mog_withLearning(const oclMat& frame, int cn, oclMat& fgmask, oclMat
...
@@ -318,6 +320,8 @@ static void mog_withLearning(const oclMat& frame, int cn, oclMat& fgmask, oclMat
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
frame_offset_y
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_int
),
(
void
*
)
&
frame_offset_y
));
openCLExecuteKernel
(
clCxt
,
&
bgfg_mog
,
kernel_name
,
global_thread
,
local_thread
,
args
,
-
1
,
-
1
,
build_option
);
openCLExecuteKernel
(
clCxt
,
&
bgfg_mog
,
kernel_name
,
global_thread
,
local_thread
,
args
,
-
1
,
-
1
,
build_option
);
fgmask
.
convertTo
(
fgmask
,
CV_8U
);
fgmask
.
copyTo
(
fgmask_raw
);
}
}
void
cv
::
ocl
::
device
::
mog
::
mog_ocl
(
const
oclMat
&
frame
,
int
cn
,
oclMat
&
fgmask
,
oclMat
&
weight
,
oclMat
&
sortKey
,
oclMat
&
mean
,
oclMat
&
var
,
void
cv
::
ocl
::
device
::
mog
::
mog_ocl
(
const
oclMat
&
frame
,
int
cn
,
oclMat
&
fgmask
,
oclMat
&
weight
,
oclMat
&
sortKey
,
oclMat
&
mean
,
oclMat
&
var
,
...
@@ -392,9 +396,11 @@ void cv::ocl::device::mog::loadConstants(float Tb, float TB, float Tg, float var
...
@@ -392,9 +396,11 @@ void cv::ocl::device::mog::loadConstants(float Tb, float TB, float Tg, float var
(
void
*
)
constants
,
sizeof
(
_contant_struct
));
(
void
*
)
constants
,
sizeof
(
_contant_struct
));
}
}
void
cv
::
ocl
::
device
::
mog
::
mog2_ocl
(
const
oclMat
&
frame
,
int
cn
,
oclMat
&
fgmask
,
oclMat
&
modesUsed
,
oclMat
&
weight
,
oclMat
&
variance
,
void
cv
::
ocl
::
device
::
mog
::
mog2_ocl
(
const
oclMat
&
frame
,
int
cn
,
oclMat
&
fgmask
Raw
,
oclMat
&
modesUsed
,
oclMat
&
weight
,
oclMat
&
variance
,
oclMat
&
mean
,
float
alphaT
,
float
prune
,
bool
detectShadows
,
int
nmixtures
)
oclMat
&
mean
,
float
alphaT
,
float
prune
,
bool
detectShadows
,
int
nmixtures
)
{
{
oclMat
fgmask
(
fgmaskRaw
.
size
(),
CV_32SC1
);
Context
*
clCxt
=
Context
::
getContext
();
Context
*
clCxt
=
Context
::
getContext
();
const
float
alpha1
=
1.0
f
-
alphaT
;
const
float
alpha1
=
1.0
f
-
alphaT
;
...
@@ -464,6 +470,9 @@ void cv::ocl::device::mog::mog2_ocl(const oclMat& frame, int cn, oclMat& fgmask,
...
@@ -464,6 +470,9 @@ void cv::ocl::device::mog::mog2_ocl(const oclMat& frame, int cn, oclMat& fgmask,
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
cl_constants
));
args
.
push_back
(
make_pair
(
sizeof
(
cl_mem
),
(
void
*
)
&
cl_constants
));
openCLExecuteKernel
(
clCxt
,
&
bgfg_mog
,
kernel_name
,
global_thread
,
local_thread
,
args
,
-
1
,
-
1
,
build_option
);
openCLExecuteKernel
(
clCxt
,
&
bgfg_mog
,
kernel_name
,
global_thread
,
local_thread
,
args
,
-
1
,
-
1
,
build_option
);
fgmask
.
convertTo
(
fgmask
,
CV_8U
);
fgmask
.
copyTo
(
fgmaskRaw
);
}
}
void
cv
::
ocl
::
device
::
mog
::
getBackgroundImage2_ocl
(
int
cn
,
const
oclMat
&
modesUsed
,
const
oclMat
&
weight
,
const
oclMat
&
mean
,
oclMat
&
dst
,
int
nmixtures
)
void
cv
::
ocl
::
device
::
mog
::
getBackgroundImage2_ocl
(
int
cn
,
const
oclMat
&
modesUsed
,
const
oclMat
&
weight
,
const
oclMat
&
mean
,
oclMat
&
dst
,
int
nmixtures
)
...
@@ -580,7 +589,7 @@ void cv::ocl::MOG2::initialize(cv::Size frameSize, int frameType)
...
@@ -580,7 +589,7 @@ void cv::ocl::MOG2::initialize(cv::Size frameSize, int frameType)
mean_
.
setTo
(
Scalar
::
all
(
0
));
mean_
.
setTo
(
Scalar
::
all
(
0
));
//make the array for keeping track of the used modes per pixel - all zeros at start
//make the array for keeping track of the used modes per pixel - all zeros at start
bgmodelUsedModes_
.
create
(
frameSize_
,
CV_
8U
C1
);
bgmodelUsedModes_
.
create
(
frameSize_
,
CV_
32F
C1
);
bgmodelUsedModes_
.
setTo
(
cv
::
Scalar
::
all
(
0
));
bgmodelUsedModes_
.
setTo
(
cv
::
Scalar
::
all
(
0
));
loadConstants
(
varThreshold
,
backgroundRatio
,
varThresholdGen
,
fVarInit
,
fVarMin
,
fVarMax
,
fTau
,
nShadowDetection
);
loadConstants
(
varThreshold
,
backgroundRatio
,
varThresholdGen
,
fVarInit
,
fVarMin
,
fVarMax
,
fTau
,
nShadowDetection
);
...
...
modules/ocl/src/opencl/bgfg_mog.cl
View file @
1e8194fd
This diff is collapsed.
Click to expand it.
modules/ocl/test/test_bgfg.cpp
View file @
1e8194fd
...
@@ -191,7 +191,7 @@ TEST_P(mog2, getBackgroundImage)
...
@@ -191,7 +191,7 @@ TEST_P(mog2, getBackgroundImage)
if
(
useGray
)
if
(
useGray
)
return
;
return
;
std
::
string
inputFile
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"
gpu
/768x576.avi"
;
std
::
string
inputFile
=
string
(
cvtest
::
TS
::
ptr
()
->
get_data_path
())
+
"
video
/768x576.avi"
;
cv
::
VideoCapture
cap
(
inputFile
);
cv
::
VideoCapture
cap
(
inputFile
);
ASSERT_TRUE
(
cap
.
isOpened
());
ASSERT_TRUE
(
cap
.
isOpened
());
...
...
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