http://stackoverflow.com/questions/17842827/how-to-use-gpustream-in-opencv
opencv中流操作示例代码。将操作压入队列,然后使用stream.waitForCompletion()进行同步,达到GPU计算的同时进行GPU与CPU之间的数据交换,从而达到提升效率的目的。
示例代码
// allocate page-locked memory
CudaMem host_src_pl(768, 1024, CV_8UC1, CudaMem::ALLOC_PAGE_LOCKED);
CudaMem host_dst_pl;
// get Mat header for CudaMem (no data copy)
Mat host_src = host_src_pl;
// fill mat on CPUsomeCPUFunc(host_src);
GpuMat gpu_src, gpu_dst;
// create Stream objectStream stream;
// next calls are non-blocking
// first upload data from host
stream.enqueueUpload(host_src_pl, gpu_src);
// perform blurblur(gpu_src, gpu_dst, Size(5,5), Point(-1,-1), stream);
// download result back to host
stream.enqueueDownload(gpu_dst, host_dst_pl);
// call another CPU function in parallel with GPUanotherCPUFunc();
// wait GPU for finish
stream.waitForCompletion();
// now you can use GPU results
Mat host_dst = host_dst_pl;