视频前景的提取Video
opencv实现运动追踪
OpenCV运动目标检测——帧间差,混合高斯模型方法
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/video/video.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char **argv){
Mat frame;
Mat foreground; // 前景图片
VideoCapture capture(argv[1]);
if (!capture.isOpened())
{
return 0;
}
namedWindow("Extracted Foreground");
namedWindow("Source Video");
// 混合高斯物体
BackgroundSubtractorMOG mog;
bool stop(false);
while (!stop)
{
if (!capture.read(frame))
{
break;
}
// 更新背景图片并且输出前景
mog(frame, foreground, 0.01);
// 输出的前景图片并不是2值图片,要处理一下显示
threshold(foreground, foreground, 128, 255, THRESH_BINARY_INV);
// show foreground
imshow("Extracted Foreground", foreground);
imshow("Source Video", frame);
if (waitKey(10) == 27)
{
stop = true;
}
}
}
本文详细介绍使用OpenCV实现视频中运动目标的检测过程。通过帧间差和混合高斯模型方法,有效提取并追踪视频前景,展示了如何利用C++编程实现背景减除和前景图像的二值化处理。
8万+

被折叠的 条评论
为什么被折叠?



