标签:
多高斯背景差分,非常吃cpu,特别是多路视屏,所以想用gpu做检测 后面的跟踪一系列的规则判断用cpu
opencv+cuda+stl做了个测试
代码:
// MTTestCudaMog.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "opencv.hpp"
#include <thread>
#include <iostream>
#include <mutex>
#include "cudacodec.hpp"
#include "cudabgsegm.hpp"
#include "cudaobjdetect.hpp"
#include "Timer.h"
using namespace std;
std::mutex m;
void f1()
{	
	cv::VideoCapture cap("D:\\testvideo\\22.mp4");
	cv::Mat mat;
	cv::Ptr<cv::cuda::BackgroundSubtractorMOG2> mog = cv::cuda::createBackgroundSubtractorMOG2(0.0002, 16,false);
	cv::cuda::GpuMat gpuMat;
	cv::cuda::GpuMat gpuMsk;
	cv::Mat matMsk;
	CTimer timeTester;
	double t = 0.0;
	while (true)
	{     
		m.lock();
		cap>>mat;	
		timeTester.Start();
		gpuMat.upload(mat);
		mog->apply( gpuMat, gpuMsk );
		gpuMat.download( matMsk );
		t = timeTester.End();
		cout <<  "Intial ThreadID : " << std::this_thread::get_id() << ":" << t<< endl;
		m.unlock();
	} 
};
int _tmain(int argc, _TCHAR* argv[])
{
	int ichannel = 9;
	vector<thread> vThread;
	vThread.resize(ichannel);
	for( int i=0; i<ichannel; i++ )
	{
		vThread[i] = std::thread(f1);
	}
	for( int i=0; i<ichannel; i++ )
	{
		vThread[i].join();
	}
	cout<<"Main Thread"<<endl;
	return 0;
}
gpu负载率在36%左右 cpu使用25%左右包括读入视屏的占用
下面这幅图是每一帧gpu的多高斯检测时间包括数据上载gpu和下载到内存的时间

标签:
原文地址:http://www.cnblogs.com/Jnshushi99/p/4514991.html