/////////////////////////////////////////////////////////////////////////// // Main entry point to a MEX function /////////////////////////////////////////////////////////////////////////// void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Ensure MATLAB's GPU support is available. mxInitGPU(); // Check inputs to mex function checkInputs(nrhs, prhs); // Convert mxArray inputs into OpenCV types cv::Ptr<cv::gpu::GpuMat> frame1 = ocvMxGpuArrayToGpuMat_uint8(prhs[0]); cv::Ptr<cv::gpu::GpuMat> frame2 = ocvMxGpuArrayToGpuMat_uint8(prhs[1]); // Allocate output matrix int outRows = frame1->rows ; int outCols = frame1->cols ; cv::gpu::GpuMat flowx((int)outRows, (int)outCols, CV_32FC1); cv::gpu::GpuMat flowy((int)outRows, (int)outCols, CV_32FC1); cv::gpu::FarnebackOpticalFlow d_calc; // Run the OpenCV template matching routine d_calc(*frame1, *frame2, flowx, flowy); // Put the data back into the output MATLAB gpuArray plhs[0] = ocvMxGpuArrayFromGpuMat_single(flowx); plhs[1] = ocvMxGpuArrayFromGpuMat_single(flowy); }
void _Flow::generateFlowMap(const GpuMat& d_flow) { GpuMat planes[2]; cuda::split(d_flow, planes); Mat flowx(planes[0]); Mat flowy(planes[1]); Mat out; drawOpticalFlow(flowx, flowy, out, 10); // out.copyTo(m_cMat); }