Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
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_contrib
Commits
f1a198d1
Commit
f1a198d1
authored
Mar 15, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1064 from sovrasov:bgsegm_sample_update
parents
f4da1502
5acfbfad
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
26 deletions
+52
-26
bgfg.cpp
modules/bgsegm/samples/bgfg.cpp
+48
-25
bgfg_subcnt.cpp
modules/bgsegm/src/bgfg_subcnt.cpp
+4
-1
No files found.
modules/bgsegm/samples/bgfg
_gmg
.cpp
→
modules/bgsegm/samples/bgfg.cpp
View file @
f1a198d1
/*
* FGBGTest.cpp
*
* Created on: May 7, 2012
* Author: Andrew B. Godbehere
*/
#include "opencv2/bgsegm.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
...
...
@@ -14,37 +7,67 @@
using
namespace
cv
;
using
namespace
cv
::
bgsegm
;
static
void
help
()
const
String
about
=
"
\n
A program demonstrating the use and capabilities of different background subtraction algrorithms
\n
"
"Using OpenCV version "
+
String
(
CV_VERSION
)
+
"
\n
Press q or ESC to exit
\n
"
;
const
String
keys
=
"{help h usage ? | | print this message }"
"{vid | | path to a video file }"
"{algo | GMG | name of the algorithm (GMG, CNT, KNN, MOG, MOG2) }"
;
static
Ptr
<
BackgroundSubtractor
>
createBGSubtractorByName
(
const
String
&
algoName
)
{
std
::
cout
<<
"
\n
A program demonstrating the use and capabilities of a particular BackgroundSubtraction
\n
"
"algorithm described in A. Godbehere, A. Matsukawa, K. Goldberg,
\n
"
"
\"
Visual Tracking of Human Visitors under Variable-Lighting Conditions for a Responsive
\n
"
"Audio Art Installation
\"
, American Control Conference, 2012, used in an interactive
\n
"
"installation at the Contemporary Jewish Museum in San Francisco, CA from March 31 through
\n
"
"July 31, 2011.
\n
"
"Call:
\n
"
"./BackgroundSubtractorGMG_sample
\n
"
"Using OpenCV version "
<<
CV_VERSION
<<
"
\n
"
<<
std
::
endl
;
Ptr
<
BackgroundSubtractor
>
algo
;
if
(
algoName
==
String
(
"GMG"
))
algo
=
createBackgroundSubtractorGMG
(
20
,
0.7
);
else
if
(
algoName
==
String
(
"CNT"
))
algo
=
createBackgroundSubtractorCNT
();
else
if
(
algoName
==
String
(
"KNN"
))
algo
=
createBackgroundSubtractorKNN
();
else
if
(
algoName
==
String
(
"MOG"
))
algo
=
createBackgroundSubtractorMOG
();
else
if
(
algoName
==
String
(
"MOG2"
))
algo
=
createBackgroundSubtractorMOG2
();
return
algo
;
}
int
main
(
int
argc
,
char
**
argv
)
{
help
();
setUseOptimized
(
true
);
setNumThreads
(
8
);
Ptr
<
BackgroundSubtractor
>
fgbg
=
createBackgroundSubtractorGMG
(
20
,
0.7
);
if
(
!
fgbg
)
CommandLineParser
parser
(
argc
,
argv
,
keys
);
parser
.
about
(
about
);
parser
.
printMessage
();
if
(
parser
.
has
(
"help"
))
{
parser
.
printMessage
();
return
0
;
}
String
videoPath
=
parser
.
get
<
String
>
(
"vid"
);
String
algoName
=
parser
.
get
<
String
>
(
"algo"
);
if
(
!
parser
.
check
())
{
parser
.
printErrors
();
return
0
;
}
Ptr
<
BackgroundSubtractor
>
bgfs
=
createBGSubtractorByName
(
algoName
);
if
(
!
bgfs
)
{
std
::
cerr
<<
"Failed to create
BackgroundSubtractor.GMG Algorithm.
"
<<
std
::
endl
;
std
::
cerr
<<
"Failed to create
"
<<
algoName
<<
" background subtractor
"
<<
std
::
endl
;
return
-
1
;
}
VideoCapture
cap
;
if
(
argc
>
1
)
cap
.
open
(
argv
[
1
]
);
cap
.
open
(
videoPath
);
else
cap
.
open
(
0
);
...
...
@@ -65,7 +88,7 @@ int main(int argc, char** argv)
if
(
frame
.
empty
())
break
;
fgbg
->
apply
(
frame
,
fgmask
);
bgfs
->
apply
(
frame
,
fgmask
);
frame
.
convertTo
(
segm
,
CV_8U
,
0.5
);
add
(
frame
,
Scalar
(
100
,
100
,
0
),
segm
,
fgmask
);
...
...
modules/bgsegm/src/bgfg_subcnt.cpp
View file @
f1a198d1
...
...
@@ -341,9 +341,12 @@ private:
void
BackgroundSubtractorCNTImpl
::
apply
(
InputArray
image
,
OutputArray
_fgmask
,
double
learningRate
)
{
CV_Assert
(
image
.
type
()
==
CV_8UC1
);
CV_Assert
(
image
.
depth
()
==
CV_8U
);
Mat
frameIn
=
image
.
getMat
();
if
(
frameIn
.
channels
()
!=
1
)
cvtColor
(
frameIn
,
frameIn
,
COLOR_BGR2GRAY
);
_fgmask
.
create
(
image
.
size
(),
CV_8U
);
// OutputArray usage requires this step
Mat
fgMask
=
_fgmask
.
getMat
();
...
...
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