#include
#include “core/core.hpp”
#include “highgui/highgui.hpp”
#include “imgproc/imgproc.hpp”
using namespace cv;
using namespace std;
int main(void)
{
Mat framePre; //上一帧
Mat frameNow; //当前帧
Mat frameDet; //运动物体
framePre=imread(“G:\C++workspace\firefilter\1.jpg”);
frameNow=imread(“G:\C++workspace\firefilter\2.jpg”);
framePre.resize(300, 300);
frameNow.resize(300, 300);
cvtColor(framePre, framePre, CV_RGB2GRAY);
cvtColor(frameNow, frameNow, CV_RGB2GRAY);
absdiff(frameNow, framePre, frameDet);
imshow(“Detection”, frameDet);
printf("%d\n", frameDet.channels());
int height = frameDet.rows;
int width = frameDet.cols;
int num = 0;
for (int i = 0; i < height; i++) {
for (int j = 0; j < width; j++) {
if (frameDet.at(i,j)!=0){
num++;
}
}
}
printf("%d\n", num);
printf("%lf\n", double(num) / double(height * width));
waitKey(0);
//char response; std::cin >> response;
return 0;
}