思想:
使用createBackgroundSubtractorMOG2()使用运动物体背景分割
使用findContours()查找轮廓并画出
实现一定感官上的跟踪功能
代码如下:
#include<opencv2\opencv.hpp>
#include<iostream>
#include<sstream>
using namespace cv;
using namespace std;
Mat frame;
Mat fgMaskMOG2;
Mat maskContour;
Ptr<BackgroundSubtractor> pMOG2;
char keyboard;
int FRAME = 0;
string b = ".jpg";
void processVideo(char* videoFilename);
void drawRect(Mat MOG2, Mat frame);
int main()
{
namedWindow("Frame");
namedWindow("移动目标跟踪");
namedWindow("FG Mask MOG 2");
pMOG2 = createBackgroundSubtractorMOG2();
char* videoFilename = "vtest.avi";
processVideo(videoFilename);
destroyAllWindows();
return 0;
}
void processVideo(char* videoFilename)
{
VideoCapture capture(videoFilename);
keyboard = 0;
while (keyboard != 'q' && keyboard != 27)
{
if (!cap