...
#include < time.h>
#include < opencv2\opencv.hpp>
#include < opencv2\gpu\gpu.hpp>
#include < string>
#include < stdio.h>
#ifdef _DEBUG
#pragma comment(lib, "opencv_core249d.lib")
#pragma comment(lib, "opencv_imgproc249d.lib") //MAT processing
#pragma comment(lib, "opencv_gpu249d.lib")
#pragma comment(lib, "opencv_highgui249d.lib")
#else
#pragma comment(lib, "opencv_core249.lib")
#pragma comment(lib, "opencv_imgproc249.lib")
#pragma comment(lib, "opencv_gpu249.lib")
#pragma comment(lib, "opencv_highgui249.lib")
#endif
#define RWIDTH 800
#define RHEIGHT 600
using namespace std;
using namespace cv;
int main()
{
/////////////////////////////////////////////////////////////////////////
gpu::MOG2_GPU pMOG2_g(30);
pMOG2_g.history = 3000; //300;
pMOG2_g.varThreshold =64; //128; //64; //32;//;
pMOG2_g.bShadowDetection = true;
Mat Mog_Mask;
gpu::GpuMat Mog_Mask_g;
/////////////////////////////////////////////////////////////////////////
VideoCapture cap("M:\\____videoSample____\\blog\\video20.wmv");//0);
/////////////////////////////////////////////////////////////////////////
Mat o_frame;
gpu::GpuMat o_frame_gpu;
/////////////////////////////////////////////////////////////////////////
cap >> o_frame;
if( o_frame.empty() )
return 0;
/////////////////////////////////////////////////////////////////////////
unsigned long AAtime=0, BBtime=0;
//Mat rFrame;
Mat showMat_r_blur;
Mat showMat_r;
namedWindow("origin");
namedWindow("mog_mask");
while(1)
{
/////////////////////////////////////////////////////////////////////////
cap >> o_frame;
if( o_frame.empty() )
return 0;
o_frame_gpu.upload(o_frame);
AAtime = getTickCount();
//
pMOG2_g.operator()(o_frame_gpu, Mog_Mask_g,-1);
//
Mog_Mask_g.download(Mog_Mask);
BBtime = getTickCount();
float pt = (BBtime - AAtime)/getTickFrequency();
float fpt = 1/pt;
printf("gpu %.4lf / %.4lf \n", pt, fpt );
o_frame_gpu.download(showMat_r);
imshow("origin", showMat_r);
imshow("mog_mask", Mog_Mask);
/////////////////////////////////////////////////////////////////////////
if( waitKey(10) > 0)
break;
}
return 0;
}
No comments:
Post a Comment