高斯混合背景建模
2016-11-18 22:11
295 查看
#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
Mat frame;
Mat fgMaskMOG2;
Ptr<BackgroundSubtractor> pMOG2;
int keyboard;
void processVideo(string videoFilename)
{
// 视频获取
VideoCapture capture(videoFilename);
if(!capture.isOpened())
{
// 输出视频文件打开错误信息
cerr << "Unable to open video file: " << videoFilename << endl;
exit(EXIT_FAILURE);
}
// 按下q键和esc退出
while( (char)keyboard != 'q' && (char)keyboard != 27 )
{
// 读取当前帧
if(!capture.read(frame))
{
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
// 图像尺寸缩小
cv::resize(frame, frame,cv::Size(), 0.25,0.25);
// 背景模型生成
pMOG2->apply(frame, fgMaskMOG2);
// 输出当前帧号
stringstream ss;
rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
cv::Scalar(255,255,255), -1);
ss << capture.get(CAP_PROP_POS_FRAMES);
string frameNumberString = ss.str();
// 左上角显示帧号
putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
// 输出结果
imshow("Frame", frame);
imshow("FG Mask MOG 2", fgMaskMOG2);
keyboard = waitKey(30);
}
capture.release();
}
int main(int argc, char* argv[])
{
// 创建背景建模类
pMOG2 = createBackgroundSubtractorMOG2();
//string inputPath = "..\\images\\car.avi";
string inputPath = "MAH00054.MP4";
processVideo(inputPath);
return 0;
}
转载:http://blog.csdn.net/zhuwei1988
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/video.hpp>
#include <iostream>
#include <sstream>
using namespace cv;
using namespace std;
Mat frame;
Mat fgMaskMOG2;
Ptr<BackgroundSubtractor> pMOG2;
int keyboard;
void processVideo(string videoFilename)
{
// 视频获取
VideoCapture capture(videoFilename);
if(!capture.isOpened())
{
// 输出视频文件打开错误信息
cerr << "Unable to open video file: " << videoFilename << endl;
exit(EXIT_FAILURE);
}
// 按下q键和esc退出
while( (char)keyboard != 'q' && (char)keyboard != 27 )
{
// 读取当前帧
if(!capture.read(frame))
{
cerr << "Unable to read next frame." << endl;
cerr << "Exiting..." << endl;
exit(EXIT_FAILURE);
}
// 图像尺寸缩小
cv::resize(frame, frame,cv::Size(), 0.25,0.25);
// 背景模型生成
pMOG2->apply(frame, fgMaskMOG2);
// 输出当前帧号
stringstream ss;
rectangle(frame, cv::Point(10, 2), cv::Point(100,20),
cv::Scalar(255,255,255), -1);
ss << capture.get(CAP_PROP_POS_FRAMES);
string frameNumberString = ss.str();
// 左上角显示帧号
putText(frame, frameNumberString.c_str(), cv::Point(15, 15),
FONT_HERSHEY_SIMPLEX, 0.5 , cv::Scalar(0,0,0));
// 输出结果
imshow("Frame", frame);
imshow("FG Mask MOG 2", fgMaskMOG2);
keyboard = waitKey(30);
}
capture.release();
}
int main(int argc, char* argv[])
{
// 创建背景建模类
pMOG2 = createBackgroundSubtractorMOG2();
//string inputPath = "..\\images\\car.avi";
string inputPath = "MAH00054.MP4";
processVideo(inputPath);
return 0;
}
转载:http://blog.csdn.net/zhuwei1988
相关文章推荐
- 混合高斯背景建模
- 【OpenCV】高斯混合背景建模
- 高斯混合背景建模
- 混合高斯背景建模
- 混合高斯背景建模理解
- 混合高斯背景建模的示例程序(VC6.0 + OpenCv 1.0)
- 混合高斯背景建模(opecv)
- 高斯混合背景建模的改进方案
- OpenCV混合高斯背景建模
- 运动目标的背景建模-混合高斯背景建模和KNN模型建模的OpenCV代码实现
- 混合高斯背景建模原理及实现
- 混合高斯背景建模
- 混合高斯背景建模-视频的运动目标检测
- 背景建模与前景检测(一)——混合高斯GMM
- 混合高斯背景建模
- 改进的混合高斯背景建模
- 混合高斯背景建模原理及实现(C# )
- 混合高斯背景建模程序分析
- 【OpenCV】高斯混合背景建模
- 混合高斯背景建模