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
7860d52e
Commit
7860d52e
authored
Nov 29, 2010
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moved to cpp directory
parent
b46d23a2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
0 deletions
+63
-0
bgfg_segm.cpp
samples/cpp/bgfg_segm.cpp
+63
-0
No files found.
samples/cpp/bgfg_segm.cpp
0 → 100644
View file @
7860d52e
#include <opencv2/video/background_segm.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
//this is a sample for foreground detection functions
int
main
(
int
argc
,
char
**
argv
)
{
IplImage
*
tmp_frame
=
NULL
;
CvCapture
*
cap
=
NULL
;
bool
update_bg_model
=
true
;
if
(
argc
<
2
)
cap
=
cvCaptureFromCAM
(
0
);
else
cap
=
cvCaptureFromFile
(
argv
[
1
]);
if
(
!
cap
)
{
printf
(
"can not open camera or video file
\n
"
);
return
-
1
;
}
tmp_frame
=
cvQueryFrame
(
cap
);
if
(
!
tmp_frame
)
{
printf
(
"can not read data from the video source
\n
"
);
return
-
1
;
}
cvNamedWindow
(
"BG"
,
1
);
cvNamedWindow
(
"FG"
,
1
);
CvBGStatModel
*
bg_model
=
0
;
for
(
int
fr
=
1
;
tmp_frame
;
tmp_frame
=
cvQueryFrame
(
cap
),
fr
++
)
{
if
(
!
bg_model
)
{
//create BG model
bg_model
=
cvCreateGaussianBGModel
(
tmp_frame
);
//bg_model = cvCreateFGDStatModel( temp );
continue
;
}
double
t
=
(
double
)
cvGetTickCount
();
cvUpdateBGStatModel
(
tmp_frame
,
bg_model
,
update_bg_model
?
-
1
:
0
);
t
=
(
double
)
cvGetTickCount
()
-
t
;
printf
(
"%d. %.1f
\n
"
,
fr
,
t
/
(
cvGetTickFrequency
()
*
1000.
)
);
cvShowImage
(
"BG"
,
bg_model
->
background
);
cvShowImage
(
"FG"
,
bg_model
->
foreground
);
char
k
=
cvWaitKey
(
5
);
if
(
k
==
27
)
break
;
if
(
k
==
' '
)
update_bg_model
=
!
update_bg_model
;
}
cvReleaseBGStatModel
(
&
bg_model
);
cvReleaseCapture
(
&
cap
);
return
0
;
}
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