Dear All,
I tried to use FarnebackOpticalFlow (gpu version) to replace the calcOpticalFlowFarneback (cpu version),
but the result shows that the OpticalFlow runs slower on gpu than on cpu
I have tried to call the FarnebackOpticalFlow gpu function secondly, it still takes about 110 ms.
the result is unexpected, and is there anything I missed?
thanks in advance!
my environment:
I7/Invida Geforce G705 (48 core)/16G memory
opencv 2.3.14
for FarnebackOpticalFlow gpu version, it takes about 120 ms
for calcOpticalFlowFarneback cpu version, it takes about 80 ms
the following is code snippet:
void GetOptFlow_gpu(Mat framePre, Mat frameCur, Mat & flow, Mat & cflow)
{
GPU_PERFORMANCE_TRACE_BEGIN_GET_OPT_FLOW()
//calcOpticalFlowFarneback(framePre, frameCur, flow, 0.5, 3, 15, 3, 5, 1.2, 0);
Mat frame0 = framePre;
Mat frame1 = frameCur;
GpuMat d_frame0(frame0);
GpuMat d_frame1(frame1);
GpuMat d_flowx(frame0.size(), CV_32FC1);
GpuMat d_flowy(frame0.size(), CV_32FC1);
Mat flowx, flowy;
FarnebackOpticalFlow farn;
{
#if 1
farn.pyrScale = 0.5;
farn.winSize = 15;
farn.numIters = 3;
farn.polyN = 5;
farn.polySigma = 1.2;
farn.flags = 0;
#else
farn.pyrScale = 0.5;
farn.fastPyramids = false;
farn.winSize = 13;
farn.numIters = 10;
farn.polyN = 5;
farn.polySigma = 1.1;
farn.flags = 0;
#endif
{
const int64 start = getTickCount();
farn(d_frame0, d_frame1, d_flowx, d_flowy);
const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "Farn : " << timeSec << " sec" << endl;
}
{
const int64 start = getTickCount();
farn(d_frame0, d_frame1, d_flowx, d_flowy);
const double timeSec = (getTickCount() - start) / getTickFrequency();
cout << "Farn : " << timeSec << " sec" << endl;
}
}
d_flowx.download(flowx);
d_flowy.download(flowy);
vector<Mat> vecMat;
vecMat.push_back(flowx);
vecMat.push_back(flowy);
merge(vecMat,flow);
GPU_PERFORMANCE_TRACE_END_GET_OPT_FLOW()
cvtColor(framePre, cflow, CV_GRAY2BGR);
DrawOptFlowMap(flow, cflow, 8, 1.5, CV_RGB(0, 255, 0));
}