|
|
|
@ -55,178 +55,184 @@ using namespace cv::ocl; |
|
|
|
|
|
|
|
|
|
namespace cv |
|
|
|
|
{ |
|
|
|
|
namespace ocl |
|
|
|
|
{ |
|
|
|
|
///////////////////////////OpenCL kernel strings///////////////////////////
|
|
|
|
|
extern const char *optical_flow_farneback; |
|
|
|
|
} |
|
|
|
|
namespace ocl |
|
|
|
|
{ |
|
|
|
|
///////////////////////////OpenCL kernel strings///////////////////////////
|
|
|
|
|
extern const char *optical_flow_farneback; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
namespace cv { namespace ocl { namespace optflow_farneback |
|
|
|
|
namespace cv { |
|
|
|
|
namespace ocl { |
|
|
|
|
namespace optflow_farneback |
|
|
|
|
{ |
|
|
|
|
oclMat g; |
|
|
|
|
oclMat xg; |
|
|
|
|
oclMat xxg; |
|
|
|
|
oclMat gKer; |
|
|
|
|
oclMat g; |
|
|
|
|
oclMat xg; |
|
|
|
|
oclMat xxg; |
|
|
|
|
oclMat gKer; |
|
|
|
|
|
|
|
|
|
float ig[4]; |
|
|
|
|
float ig[4]; |
|
|
|
|
|
|
|
|
|
inline int divUp(int total, int grain) |
|
|
|
|
{ |
|
|
|
|
return (total + grain - 1) / grain; |
|
|
|
|
} |
|
|
|
|
inline int divUp(int total, int grain) |
|
|
|
|
{ |
|
|
|
|
return (total + grain - 1) / grain; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
inline void setGaussianBlurKernel(const float *c_gKer, int ksizeHalf) |
|
|
|
|
{ |
|
|
|
|
cv::Mat t_gKer(1, ksizeHalf + 1, CV_32FC1, const_cast<float *>(c_gKer)); |
|
|
|
|
gKer.upload(t_gKer); |
|
|
|
|
} |
|
|
|
|
inline void setGaussianBlurKernel(const float *c_gKer, int ksizeHalf) |
|
|
|
|
{ |
|
|
|
|
cv::Mat t_gKer(1, ksizeHalf + 1, CV_32FC1, const_cast<float *>(c_gKer)); |
|
|
|
|
gKer.upload(t_gKer); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void gaussianBlurOcl(const oclMat &src, int ksizeHalf, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("gaussianBlur"); |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(src.cols, localThreads[0]) * localThreads[0], src.rows, 1 }; |
|
|
|
|
int smem_size = (localThreads[0] + 2*ksizeHalf) * sizeof(float); |
|
|
|
|
|
|
|
|
|
CV_Assert(dst.size() == src.size()); |
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&gKer.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&ksizeHalf)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
static void gaussianBlurOcl(const oclMat &src, int ksizeHalf, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("gaussianBlur"); |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(src.cols, localThreads[0]) * localThreads[0], src.rows, 1 }; |
|
|
|
|
int smem_size = (localThreads[0] + 2*ksizeHalf) * sizeof(float); |
|
|
|
|
|
|
|
|
|
CV_Assert(dst.size() == src.size()); |
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&gKer.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&ksizeHalf)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void polynomialExpansionOcl(const oclMat &src, int polyN, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("polynomialExpansion"); |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(src.cols, localThreads[0] - 2*polyN) * localThreads[0], src.rows, 1 }; |
|
|
|
|
int smem_size = 3 * localThreads[0] * sizeof(float); |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&g.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&xg.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&xxg.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_float4), (void *)&ig)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
|
|
|
|
|
char opt [128]; |
|
|
|
|
sprintf(opt, "-D polyN=%d", polyN); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1, opt); |
|
|
|
|
} |
|
|
|
|
static void polynomialExpansionOcl(const oclMat &src, int polyN, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("polynomialExpansion"); |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(src.cols, localThreads[0] - 2*polyN) * localThreads[0], src.rows, 1 }; |
|
|
|
|
int smem_size = 3 * localThreads[0] * sizeof(float); |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&g.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&xg.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&xxg.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_float4), (void *)&ig)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
|
|
|
|
|
char opt [128]; |
|
|
|
|
sprintf(opt, "-D polyN=%d", polyN); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1, opt); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void updateMatricesOcl(const oclMat &flowx, const oclMat &flowy, const oclMat &R0, const oclMat &R1, oclMat &M) |
|
|
|
|
{ |
|
|
|
|
string kernelName("updateMatrices"); |
|
|
|
|
size_t localThreads[3] = { 32, 8, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(flowx.cols, localThreads[0]) * localThreads[0], |
|
|
|
|
divUp(flowx.rows, localThreads[1]) * localThreads[1], |
|
|
|
|
1 }; |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&M.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowx.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowy.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&R0.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&R1.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&M.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowy.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&R0.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&R1.step)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
static void updateMatricesOcl(const oclMat &flowx, const oclMat &flowy, const oclMat &R0, const oclMat &R1, oclMat &M) |
|
|
|
|
{ |
|
|
|
|
string kernelName("updateMatrices"); |
|
|
|
|
size_t localThreads[3] = { 32, 8, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(flowx.cols, localThreads[0]) * localThreads[0], |
|
|
|
|
divUp(flowx.rows, localThreads[1]) * localThreads[1], |
|
|
|
|
1 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&M.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowx.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowy.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&R0.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&R1.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&M.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowy.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&R0.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&R1.step)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void boxFilter5Ocl(const oclMat &src, int ksizeHalf, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("boxFilter5"); |
|
|
|
|
int height = src.rows / 5; |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(src.cols, localThreads[0]) * localThreads[0], height, 1 }; |
|
|
|
|
int smem_size = (localThreads[0] + 2*ksizeHalf) * 5 * sizeof(float); |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&height)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&ksizeHalf)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
static void boxFilter5Ocl(const oclMat &src, int ksizeHalf, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("boxFilter5"); |
|
|
|
|
int height = src.rows / 5; |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(src.cols, localThreads[0]) * localThreads[0], height, 1 }; |
|
|
|
|
int smem_size = (localThreads[0] + 2*ksizeHalf) * 5 * sizeof(float); |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&height)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&ksizeHalf)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void updateFlowOcl(const oclMat &M, oclMat &flowx, oclMat &flowy) |
|
|
|
|
{ |
|
|
|
|
string kernelName("updateFlow"); |
|
|
|
|
int cols = divUp(flowx.cols, 4); |
|
|
|
|
size_t localThreads[3] = { 32, 8, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(cols, localThreads[0]) * localThreads[0], |
|
|
|
|
divUp(flowx.rows, localThreads[1]) * localThreads[0], |
|
|
|
|
1 }; |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowx.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowy.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&M.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowy.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&M.step)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
static void updateFlowOcl(const oclMat &M, oclMat &flowx, oclMat &flowy) |
|
|
|
|
{ |
|
|
|
|
string kernelName("updateFlow"); |
|
|
|
|
int cols = divUp(flowx.cols, 4); |
|
|
|
|
size_t localThreads[3] = { 32, 8, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(cols, localThreads[0]) * localThreads[0], |
|
|
|
|
divUp(flowx.rows, localThreads[1]) * localThreads[0], |
|
|
|
|
1 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowx.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&flowy.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&M.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.rows)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&cols)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowx.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&flowy.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&M.step)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void gaussianBlur5Ocl(const oclMat &src, int ksizeHalf, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("gaussianBlur5"); |
|
|
|
|
int height = src.rows / 5; |
|
|
|
|
int width = src.cols; |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(width, localThreads[0]) * localThreads[0], height, 1 }; |
|
|
|
|
int smem_size = (localThreads[0] + 2*ksizeHalf) * 5 * sizeof(float); |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&gKer.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&height)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&width)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&ksizeHalf)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
}}} // namespace cv { namespace ocl { namespace optflow_farneback
|
|
|
|
|
static void gaussianBlur5Ocl(const oclMat &src, int ksizeHalf, oclMat &dst) |
|
|
|
|
{ |
|
|
|
|
string kernelName("gaussianBlur5"); |
|
|
|
|
int height = src.rows / 5; |
|
|
|
|
int width = src.cols; |
|
|
|
|
size_t localThreads[3] = { 256, 1, 1 }; |
|
|
|
|
size_t globalThreads[3] = { divUp(width, localThreads[0]) * localThreads[0], height, 1 }; |
|
|
|
|
int smem_size = (localThreads[0] + 2*ksizeHalf) * 5 * sizeof(float); |
|
|
|
|
|
|
|
|
|
std::vector< std::pair<size_t, const void *> > args; |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&dst.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&src.data)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_mem), (void *)&gKer.data)); |
|
|
|
|
args.push_back(std::make_pair(smem_size, (void *)NULL)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&height)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&width)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&dst.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&src.step)); |
|
|
|
|
args.push_back(std::make_pair(sizeof(cl_int), (void *)&ksizeHalf)); |
|
|
|
|
|
|
|
|
|
openCLExecuteKernel(Context::getContext(), &optical_flow_farneback, kernelName, |
|
|
|
|
globalThreads, localThreads, args, -1, -1); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} // namespace cv { namespace ocl { namespace optflow_farneback
|
|
|
|
|
|
|
|
|
|
static oclMat allocMatFromBuf(int rows, int cols, int type, oclMat &mat) |
|
|
|
|
{ |
|
|
|
@ -236,8 +242,8 @@ static oclMat allocMatFromBuf(int rows, int cols, int type, oclMat &mat) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cv::ocl::FarnebackOpticalFlow::prepareGaussian( |
|
|
|
|
int n, double sigma, float *g, float *xg, float *xxg, |
|
|
|
|
double &ig11, double &ig03, double &ig33, double &ig55) |
|
|
|
|
int n, double sigma, float *g, float *xg, float *xxg, |
|
|
|
|
double &ig11, double &ig03, double &ig33, double &ig55) |
|
|
|
|
{ |
|
|
|
|
double s = 0.; |
|
|
|
|
for (int x = -n; x <= n; x++) |
|
|
|
@ -316,8 +322,8 @@ void cv::ocl::FarnebackOpticalFlow::setPolynomialExpansionConsts(int n, double s |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void cv::ocl::FarnebackOpticalFlow::updateFlow_boxFilter( |
|
|
|
|
const oclMat& R0, const oclMat& R1, oclMat& flowx, oclMat &flowy, |
|
|
|
|
oclMat& M, oclMat &bufM, int blockSize, bool updateMatrices) |
|
|
|
|
const oclMat& R0, const oclMat& R1, oclMat& flowx, oclMat &flowy, |
|
|
|
|
oclMat& M, oclMat &bufM, int blockSize, bool updateMatrices) |
|
|
|
|
{ |
|
|
|
|
optflow_farneback::boxFilter5Ocl(M, blockSize/2, bufM); |
|
|
|
|
|
|
|
|
@ -333,8 +339,8 @@ void cv::ocl::FarnebackOpticalFlow::updateFlow_boxFilter( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cv::ocl::FarnebackOpticalFlow::updateFlow_gaussianBlur( |
|
|
|
|
const oclMat& R0, const oclMat& R1, oclMat& flowx, oclMat& flowy, |
|
|
|
|
oclMat& M, oclMat &bufM, int blockSize, bool updateMatrices) |
|
|
|
|
const oclMat& R0, const oclMat& R1, oclMat& flowx, oclMat& flowy, |
|
|
|
|
oclMat& M, oclMat &bufM, int blockSize, bool updateMatrices) |
|
|
|
|
{ |
|
|
|
|
optflow_farneback::gaussianBlur5Ocl(M, blockSize/2, bufM); |
|
|
|
|
|
|
|
|
@ -348,7 +354,7 @@ void cv::ocl::FarnebackOpticalFlow::updateFlow_gaussianBlur( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cv::ocl::FarnebackOpticalFlow::operator ()( |
|
|
|
|
const oclMat &frame0, const oclMat &frame1, oclMat &flowx, oclMat &flowy) |
|
|
|
|
const oclMat &frame0, const oclMat &frame1, oclMat &flowx, oclMat &flowy) |
|
|
|
|
{ |
|
|
|
|
CV_Assert(frame0.channels() == 1 && frame1.channels() == 1); |
|
|
|
|
CV_Assert(frame0.size() == frame1.size()); |
|
|
|
@ -504,4 +510,3 @@ void cv::ocl::FarnebackOpticalFlow::operator ()( |
|
|
|
|
flowx = curFlowX; |
|
|
|
|
flowy = curFlowY; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|