opencv 計算幀間差比率

#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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章