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
449b4d8a
Commit
449b4d8a
authored
Aug 21, 2013
by
zio dodo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the tutorial on background subtraction, in the video section
parent
7992402e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
205 additions
and
5 deletions
+205
-5
conf.py
doc/conf.py
+4
-2
tocDefinitions.rst
doc/tutorials/definitions/tocDefinitions.rst
+1
-0
background_subtraction.rst
...s/video/background_subtraction/background_subtraction.rst
+0
-0
Background_Subtraction_Tutorial_Result_1.png
...ction/images/Background_Subtraction_Tutorial_Result_1.png
+0
-0
Background_Subtraction_Tutorial_Result_2.png
...ction/images/Background_Subtraction_Tutorial_Result_2.png
+0
-0
Background_Subtraction_Tutorial_Scheme.png
...raction/images/Background_Subtraction_Tutorial_Scheme.png
+0
-0
Background_Subtraction_Tutorial_Cover.jpg
...nt_video/images/Background_Subtraction_Tutorial_Cover.jpg
+0
-0
table_of_content_video.rst
...s/video/table_of_content_video/table_of_content_video.rst
+27
-2
motion_estimators.cpp
modules/stitching/src/motion_estimators.cpp
+1
-1
bg_sub.cpp
samples/cpp/tutorial_code/video/bg_sub.cpp
+172
-0
No files found.
doc/conf.py
View file @
449b4d8a
...
...
@@ -401,5 +401,7 @@ extlinks = {
'brute_force_matcher'
:
(
'http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=bruteforcematcher#bruteforcematcher
%
s'
,
None
),
'cascade_classifier'
:
(
'http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=cascadeclassifier#cascadeclassifier
%
s'
,
None
),
'cascade_classifier_load'
:
(
'http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=load#cascadeclassifier-load
%
s'
,
None
),
'cascade_classifier_detect_multiscale'
:
(
'http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale
%
s'
,
None
)
}
'cascade_classifier_detect_multiscale'
:
(
'http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale
%
s'
,
None
),
'background_subtractor'
:
(
'http://opencv.itseez.com/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractor#backgroundsubtractor
%
s'
,
None
),
'video_capture'
:
(
'http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture
%
s'
,
None
)
}
doc/tutorials/definitions/tocDefinitions.rst
View file @
449b4d8a
...
...
@@ -11,3 +11,4 @@
.. |Author_EricCh| unicode:: Eric U+0020 Christiansen
.. |Author_AndreyP| unicode:: Andrey U+0020 Pavlenko
.. |Author_AlexS| unicode:: Alexander U+0020 Smorkalov
.. |Author_DomenicoB| unicode:: Domenico U+0020 Daniele U+0020 Bloisi
doc/tutorials/video/background_subtraction/background_subtraction.rst
0 → 100644
View file @
449b4d8a
This diff is collapsed.
Click to expand it.
doc/tutorials/video/background_subtraction/images/Background_Subtraction_Tutorial_Result_1.png
0 → 100644
View file @
449b4d8a
141 KB
doc/tutorials/video/background_subtraction/images/Background_Subtraction_Tutorial_Result_2.png
0 → 100644
View file @
449b4d8a
159 KB
doc/tutorials/video/background_subtraction/images/Background_Subtraction_Tutorial_Scheme.png
0 → 100644
View file @
449b4d8a
77.7 KB
doc/tutorials/video/table_of_content_video/images/Background_Subtraction_Tutorial_Cover.jpg
0 → 100644
View file @
449b4d8a
2.66 KB
doc/tutorials/video/table_of_content_video/table_of_content_video.rst
View file @
449b4d8a
...
...
@@ -3,10 +3,35 @@
*video* module. Video analysis
-----------------------------------------------------------
Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions.
Look here in order to find use on your video stream algoritms like: motion extraction, feature tracking and foreground extractions.
.. include:: ../../definitions/noContent.rst
.. include:: ../../definitions/tocDefinitions.rst
+
.. tabularcolumns:: m{100pt} m{300pt}
.. cssclass:: toctableopencv
=============== ======================================================
|BgSub| **Title:** :ref:`Background_Subtraction`
*Compatibility:* > OpenCV 2.4.5
*Author:* |Author_DomenicoB|
We will learn how to extract foreground masks from both videos and sequences of images and to show them.
=============== ======================================================
.. |BgSub| image:: images/Background_Subtraction_Tutorial_Cover.jpg
:height: 90pt
:width: 90pt
.. raw:: latex
\pagebreak
.. toctree::
:hidden:
../background_subtraction/background_subtraction
modules/stitching/src/motion_estimators.cpp
View file @
449b4d8a
...
...
@@ -259,7 +259,7 @@ bool BundleAdjusterBase::estimate(const std::vector<ImageFeatures> &features,
bool
ok
=
true
;
for
(
int
i
=
0
;
i
<
cam_params_
.
rows
;
++
i
)
{
if
(
isnan
(
cam_params_
.
at
<
double
>
(
i
,
0
)))
if
(
std
::
isnan
(
cam_params_
.
at
<
double
>
(
i
,
0
)))
{
ok
=
false
;
break
;
...
...
samples/cpp/tutorial_code/video/bg_sub.cpp
0 → 100644
View file @
449b4d8a
//opencv
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/video/background_segm.hpp>
//C
#include <stdio.h>
//C++
#include <iostream>
#include <sstream>
using
namespace
cv
;
using
namespace
std
;
//global variables
Mat
frame
;
//current frame
Mat
fgMaskMOG
;
//fg mask generated by MOG method
Mat
fgMaskMOG2
;
//fg mask fg mask generated by MOG2 method
Ptr
<
BackgroundSubtractor
>
pMOG
;
//MOG Background subtractor
Ptr
<
BackgroundSubtractor
>
pMOG2
;
//MOG2 Background subtractor
int
keyboard
;
//input from keyboard
//function declarations
void
help
();
void
processVideo
(
char
*
videoFilename
);
void
processImages
(
char
*
firstFrameFilename
);
void
help
()
{
cout
<<
"--------------------------------------------------------------------------"
<<
endl
<<
"This program shows how to use background subtraction methods provided by "
<<
endl
<<
" OpenCV. You can process both videos (-vid) and images (-img)."
<<
endl
<<
endl
<<
"Usage:"
<<
endl
<<
"./bs {-vid <video filename>|-img <image filename>}"
<<
endl
<<
"for example: ./bs -vid video.avi"
<<
endl
<<
"or: ./bs -img /data/images/1.png"
<<
endl
<<
"--------------------------------------------------------------------------"
<<
endl
<<
endl
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
//print help information
help
();
//check for the input parameter correctness
if
(
argc
!=
3
)
{
cerr
<<
"Incorret input list"
<<
endl
;
cerr
<<
"exiting..."
<<
endl
;
return
EXIT_FAILURE
;
}
//create GUI windows
namedWindow
(
"Frame"
);
namedWindow
(
"FG Mask MOG"
);
namedWindow
(
"FG Mask MOG 2"
);
//create Background Subtractor objects
pMOG
=
createBackgroundSubtractorMOG
();
//MOG approach
pMOG2
=
createBackgroundSubtractorMOG2
();
//MOG2 approach
if
(
strcmp
(
argv
[
1
],
"-vid"
)
==
0
)
{
//input data coming from a video
processVideo
(
argv
[
2
]);
}
else
if
(
strcmp
(
argv
[
1
],
"-img"
)
==
0
)
{
//input data coming from a sequence of images
processImages
(
argv
[
2
]);
}
else
{
//error in reading input parameters
cerr
<<
"Please, check the input parameters."
<<
endl
;
cerr
<<
"Exiting..."
<<
endl
;
return
EXIT_FAILURE
;
}
//destroy GUI windows
destroyAllWindows
();
return
EXIT_SUCCESS
;
}
void
processVideo
(
char
*
videoFilename
)
{
//create the capture object
VideoCapture
capture
(
videoFilename
);
if
(
!
capture
.
isOpened
()){
//error in opening the video input
cerr
<<
"Unable to open video file: "
<<
videoFilename
<<
endl
;
exit
(
EXIT_FAILURE
);
}
//read input data. ESC or 'q' for quitting
while
(
(
char
)
keyboard
!=
'q'
&&
(
char
)
keyboard
!=
27
){
//read the current frame
if
(
!
capture
.
read
(
frame
))
{
cerr
<<
"Unable to read next frame."
<<
endl
;
cerr
<<
"Exiting..."
<<
endl
;
exit
(
EXIT_FAILURE
);
}
//update the background model
pMOG
->
apply
(
frame
,
fgMaskMOG
);
pMOG2
->
apply
(
frame
,
fgMaskMOG2
);
//get the frame number and write it on the current frame
stringstream
ss
;
rectangle
(
frame
,
cv
::
Point
(
10
,
2
),
cv
::
Point
(
100
,
20
),
cv
::
Scalar
(
255
,
255
,
255
),
-
1
);
ss
<<
capture
.
get
(
CV_CAP_PROP_POS_FRAMES
);
string
frameNumberString
=
ss
.
str
();
putText
(
frame
,
frameNumberString
.
c_str
(),
cv
::
Point
(
15
,
15
),
CV_FONT_NORMAL
,
0.5
,
cv
::
Scalar
(
0
,
0
,
0
));
//show the current frame and the fg masks
imshow
(
"Frame"
,
frame
);
imshow
(
"FG Mask MOG"
,
fgMaskMOG
);
imshow
(
"FG Mask MOG 2"
,
fgMaskMOG2
);
//get the input from the keyboard
keyboard
=
waitKey
(
30
);
}
//delete capture object
capture
.
release
();
}
void
processImages
(
char
*
fistFrameFilename
)
{
//read the first file of the sequence
frame
=
imread
(
fistFrameFilename
);
if
(
!
frame
.
data
){
//error in opening the first image
cerr
<<
"Unable to open first image frame: "
<<
fistFrameFilename
<<
endl
;
exit
(
EXIT_FAILURE
);
}
//current image filename
string
fn
(
fistFrameFilename
);
//read input data. ESC or 'q' for quitting
while
(
(
char
)
keyboard
!=
'q'
&&
(
char
)
keyboard
!=
27
){
//update the background model
pMOG
->
apply
(
frame
,
fgMaskMOG
);
pMOG2
->
apply
(
frame
,
fgMaskMOG2
);
//get the frame number and write it on the current frame
size_t
index
=
fn
.
find_last_of
(
"/"
);
if
(
index
==
string
::
npos
)
{
index
=
fn
.
find_last_of
(
"
\\
"
);
}
size_t
index2
=
fn
.
find_last_of
(
"."
);
string
prefix
=
fn
.
substr
(
0
,
index
+
1
);
string
suffix
=
fn
.
substr
(
index2
);
string
frameNumberString
=
fn
.
substr
(
index
+
1
,
index2
-
index
-
1
);
istringstream
iss
(
frameNumberString
);
int
frameNumber
;
iss
>>
frameNumber
;
rectangle
(
frame
,
cv
::
Point
(
10
,
2
),
cv
::
Point
(
100
,
20
),
cv
::
Scalar
(
255
,
255
,
255
),
-
1
);
putText
(
frame
,
frameNumberString
.
c_str
(),
cv
::
Point
(
15
,
15
),
CV_FONT_NORMAL
,
0.5
,
cv
::
Scalar
(
0
,
0
,
0
));
//show the current frame and the fg masks
imshow
(
"Frame"
,
frame
);
imshow
(
"FG Mask MOG"
,
fgMaskMOG
);
imshow
(
"FG Mask MOG 2"
,
fgMaskMOG2
);
//get the input from the keyboard
keyboard
=
waitKey
(
30
);
//search for the next image in the sequence
ostringstream
oss
;
oss
<<
(
frameNumber
+
1
);
string
nextFrameNumberString
=
oss
.
str
();
string
nextFrameFilename
=
prefix
+
nextFrameNumberString
+
suffix
;
//read the next frame
frame
=
imread
(
nextFrameFilename
);
if
(
!
frame
.
data
){
//error in opening the next image in the sequence
cerr
<<
"Unable to open image frame: "
<<
nextFrameFilename
<<
endl
;
exit
(
EXIT_FAILURE
);
}
//update the path of the current frame
fn
.
assign
(
nextFrameFilename
);
}
}
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