mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 15:53:03 +04:00
Merge remote-tracking branch 'origin/2.4'
Conflicts: 3rdparty/libjasper/CMakeLists.txt cmake/OpenCVDetectOpenCL.cmake modules/calib3d/doc/camera_calibration_and_3d_reconstruction.rst modules/imgproc/src/floodfill.cpp modules/ocl/include/opencv2/ocl/ocl.hpp modules/ocl/src/arithm.cpp modules/ocl/src/haar.cpp modules/ocl/src/imgproc.cpp modules/ocl/src/initialization.cpp modules/ocl/src/matrix_operations.cpp modules/ocl/src/mcwutil.cpp modules/ocl/src/opencl/arithm_bitwise_and_mask.cl modules/ocl/src/opencl/arithm_bitwise_and_scalar_mask.cl modules/ocl/src/opencl/arithm_bitwise_binary_mask.cl modules/ocl/src/opencl/arithm_bitwise_binary_scalar.cl modules/ocl/src/opencl/arithm_bitwise_binary_scalar_mask.cl modules/ocl/src/opencl/arithm_bitwise_or.cl modules/ocl/src/opencl/arithm_bitwise_or_scalar.cl modules/ocl/src/opencl/arithm_bitwise_or_scalar_mask.cl modules/ocl/src/opencl/arithm_bitwise_xor.cl modules/ocl/src/opencl/arithm_bitwise_xor_mask.cl modules/ocl/src/opencl/arithm_bitwise_xor_scalar.cl modules/ocl/src/stereobm.cpp modules/ocl/test/precomp.hpp modules/python/src2/api modules/ts/src/ts_func.cpp samples/gpu/bgfg_segm.cpp
This commit is contained in:
+59
-50
@@ -22,6 +22,7 @@
|
||||
// Jiang Liyuan, jlyuan001.good@163.com
|
||||
// Rock Li, Rock.Li@amd.com
|
||||
// Zailong Wu, bullet@yeah.net
|
||||
// Peng Xiao, pengxiao@outlook.com
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
@@ -61,8 +62,6 @@ namespace cv
|
||||
namespace ocl
|
||||
{
|
||||
////////////////////////////////OpenCL kernel strings/////////////////////
|
||||
extern const char *bitwise;
|
||||
extern const char *bitwiseM;
|
||||
extern const char *transpose_kernel;
|
||||
extern const char *arithm_nonzero;
|
||||
extern const char *arithm_sum;
|
||||
@@ -76,19 +75,11 @@ namespace cv
|
||||
extern const char *arithm_add;
|
||||
extern const char *arithm_add_scalar;
|
||||
extern const char *arithm_add_scalar_mask;
|
||||
extern const char *arithm_bitwise_binary;
|
||||
extern const char *arithm_bitwise_binary_mask;
|
||||
extern const char *arithm_bitwise_binary_scalar;
|
||||
extern const char *arithm_bitwise_binary_scalar_mask;
|
||||
extern const char *arithm_bitwise_not;
|
||||
extern const char *arithm_bitwise_and;
|
||||
extern const char *arithm_bitwise_and_mask;
|
||||
extern const char *arithm_bitwise_and_scalar;
|
||||
extern const char *arithm_bitwise_and_scalar_mask;
|
||||
extern const char *arithm_bitwise_or;
|
||||
extern const char *arithm_bitwise_or_mask;
|
||||
extern const char *arithm_bitwise_or_scalar;
|
||||
extern const char *arithm_bitwise_or_scalar_mask;
|
||||
extern const char *arithm_bitwise_xor;
|
||||
extern const char *arithm_bitwise_xor_mask;
|
||||
extern const char *arithm_bitwise_xor_scalar;
|
||||
extern const char *arithm_bitwise_xor_scalar_mask;
|
||||
extern const char *arithm_compare_eq;
|
||||
extern const char *arithm_compare_ne;
|
||||
extern const char *arithm_mul;
|
||||
@@ -126,7 +117,7 @@ inline int divUp(int total, int grain)
|
||||
/////////////////////// add subtract multiply divide /////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
template<typename T>
|
||||
void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
String kernelName, const char **kernelString, void *_scalar, int op_type = 0)
|
||||
{
|
||||
if(!src1.clCxt->supportsFeature(Context::CL_DOUBLE) && src1.type() == CV_64F)
|
||||
@@ -195,12 +186,12 @@ void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, -1, depth);
|
||||
}
|
||||
}
|
||||
static void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
static void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
String kernelName, const char **kernelString, int op_type = 0)
|
||||
{
|
||||
arithmetic_run<char>(src1, src2, dst, kernelName, kernelString, (void *)NULL, op_type);
|
||||
}
|
||||
static void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask,
|
||||
static void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask,
|
||||
String kernelName, const char **kernelString, int op_type = 0)
|
||||
{
|
||||
if(!src1.clCxt->supportsFeature(Context::CL_DOUBLE) && src1.type() == CV_64F)
|
||||
@@ -295,6 +286,7 @@ void cv::ocl::multiply(const oclMat &src1, const oclMat &src2, oclMat &dst, doub
|
||||
else
|
||||
arithmetic_run<float>(src1, src2, dst, "arithm_mul", &arithm_mul, (void *)(&scalar));
|
||||
}
|
||||
|
||||
void cv::ocl::divide(const oclMat &src1, const oclMat &src2, oclMat &dst, double scalar)
|
||||
{
|
||||
|
||||
@@ -479,6 +471,11 @@ void cv::ocl::subtract(const Scalar &src2, const oclMat &src1, oclMat &dst, cons
|
||||
|
||||
arithmetic_scalar( src1, src2, dst, mask, kernelName, kernelString, -1);
|
||||
}
|
||||
void cv::ocl::multiply(double scalar, const oclMat &src, oclMat &dst)
|
||||
{
|
||||
String kernelName = "arithm_muls";
|
||||
arithmetic_scalar_run( src, dst, kernelName, &arithm_mul, scalar);
|
||||
}
|
||||
void cv::ocl::divide(double scalar, const oclMat &src, oclMat &dst)
|
||||
{
|
||||
if(!src.clCxt->supportsFeature(Context::CL_DOUBLE))
|
||||
@@ -1647,7 +1644,8 @@ static void bitwise_run(const oclMat &src1, oclMat &dst, String kernelName, cons
|
||||
|
||||
|
||||
template<typename T>
|
||||
void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, String kernelName, const char **kernelString, void *_scalar)
|
||||
void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, String kernelName,
|
||||
const char **kernelString, void *_scalar, const char* _opt = NULL)
|
||||
{
|
||||
dst.create(src1.size(), src1.type());
|
||||
CV_Assert(src1.cols == src2.cols && src2.cols == dst.cols &&
|
||||
@@ -1697,13 +1695,15 @@ void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, String ker
|
||||
args.push_back( std::make_pair( sizeof(T), (void *)&scalar ));
|
||||
}
|
||||
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, -1, depth);
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, -1, depth, _opt);
|
||||
}
|
||||
static void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, String kernelName, const char **kernelString)
|
||||
static void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
String kernelName, const char **kernelString, const char* _opt = NULL)
|
||||
{
|
||||
bitwise_run<char>(src1, src2, dst, kernelName, kernelString, (void *)NULL);
|
||||
bitwise_run<char>(src1, src2, dst, kernelName, kernelString, (void *)NULL, _opt);
|
||||
}
|
||||
static void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask, String kernelName, const char **kernelString)
|
||||
static void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst,
|
||||
const oclMat &mask, String kernelName, const char **kernelString, const char* _opt = NULL)
|
||||
{
|
||||
dst.create(src1.size(), src1.type());
|
||||
CV_Assert(src1.cols == src2.cols && src2.cols == dst.cols &&
|
||||
@@ -1751,12 +1751,13 @@ static void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, con
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&cols ));
|
||||
args.push_back( std::make_pair( sizeof(cl_int), (void *)&dst_step1 ));
|
||||
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, channels, depth);
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, channels, depth, _opt);
|
||||
}
|
||||
|
||||
|
||||
template <typename WT , typename CL_WT>
|
||||
void bitwise_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, String kernelName, const char **kernelString, int isMatSubScalar)
|
||||
void bitwise_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst,
|
||||
const oclMat &mask, String kernelName, const char **kernelString, int isMatSubScalar, const char* opt = NULL)
|
||||
{
|
||||
dst.create(src1.size(), src1.type());
|
||||
|
||||
@@ -1818,14 +1819,16 @@ void bitwise_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst, con
|
||||
args.push_back( std::make_pair( sizeof(cl_int) , (void *)&isMatSubScalar));
|
||||
}
|
||||
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, channels, depth);
|
||||
openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, channels, depth, opt);
|
||||
}
|
||||
|
||||
|
||||
typedef void (*BitwiseFuncS)(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, String kernelName, const char **kernelString, int isMatSubScalar);
|
||||
typedef void (*BitwiseFuncS)(const oclMat &src1, const Scalar &src2, oclMat &dst,
|
||||
const oclMat &mask, String kernelName, const char **kernelString, int isMatSubScalar, const char* opt);
|
||||
|
||||
|
||||
static void bitwise_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, String kernelName, const char **kernelString, int isMatSubScalar)
|
||||
static void bitwise_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst,
|
||||
const oclMat &mask, String kernelName, const char **kernelString, int isMatSubScalar, const char* opt)
|
||||
{
|
||||
static BitwiseFuncS tab[8] =
|
||||
{
|
||||
@@ -1853,11 +1856,12 @@ static void bitwise_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst,
|
||||
BitwiseFuncS func = tab[src1.depth()];
|
||||
if(func == 0)
|
||||
cv::error(Error::StsBadArg, "Unsupported arithmetic operation", "", __FILE__, __LINE__);
|
||||
func(src1, src2, dst, mask, kernelName, kernelString, isMatSubScalar);
|
||||
func(src1, src2, dst, mask, kernelName, kernelString, isMatSubScalar, opt);
|
||||
}
|
||||
static void bitwise_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, String kernelName, const char **kernelString)
|
||||
static void bitwise_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst,
|
||||
const oclMat &mask, String kernelName, const char **kernelString, const char * opt = NULL)
|
||||
{
|
||||
bitwise_scalar(src1, src2, dst, mask, kernelName, kernelString, 0);
|
||||
bitwise_scalar(src1, src2, dst, mask, kernelName, kernelString, 0, opt);
|
||||
}
|
||||
|
||||
void cv::ocl::bitwise_not(const oclMat &src, oclMat &dst)
|
||||
@@ -1880,12 +1884,13 @@ void cv::ocl::bitwise_or(const oclMat &src1, const oclMat &src2, oclMat &dst, co
|
||||
std::cout << "Selected device do not support double" << std::endl;
|
||||
return;
|
||||
}
|
||||
oclMat emptyMat;
|
||||
String kernelName = mask.empty() ? "arithm_bitwise_or" : "arithm_bitwise_or_with_mask";
|
||||
|
||||
String kernelName = mask.empty() ? "arithm_bitwise_binary" : "arithm_bitwise_binary_with_mask";
|
||||
static const char opt [] = "-D OP_BINARY=|";
|
||||
if (mask.empty())
|
||||
bitwise_run(src1, src2, dst, kernelName, &arithm_bitwise_or);
|
||||
bitwise_run(src1, src2, dst, kernelName, &arithm_bitwise_binary, opt);
|
||||
else
|
||||
bitwise_run(src1, src2, dst, mask, kernelName, &arithm_bitwise_or_mask);
|
||||
bitwise_run(src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_mask, opt);
|
||||
}
|
||||
|
||||
|
||||
@@ -1896,11 +1901,12 @@ void cv::ocl::bitwise_or(const oclMat &src1, const Scalar &src2, oclMat &dst, co
|
||||
std::cout << "Selected device do not support double" << std::endl;
|
||||
return;
|
||||
}
|
||||
String kernelName = mask.data ? "arithm_s_bitwise_or_with_mask" : "arithm_s_bitwise_or";
|
||||
static const char opt [] = "-D OP_BINARY=|";
|
||||
String kernelName = mask.data ? "arithm_s_bitwise_binary_with_mask" : "arithm_s_bitwise_binary";
|
||||
if (mask.data)
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_or_scalar_mask);
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_scalar_mask, opt);
|
||||
else
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_or_scalar);
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_scalar, opt);
|
||||
}
|
||||
|
||||
void cv::ocl::bitwise_and(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask)
|
||||
@@ -1913,12 +1919,13 @@ void cv::ocl::bitwise_and(const oclMat &src1, const oclMat &src2, oclMat &dst, c
|
||||
}
|
||||
oclMat emptyMat;
|
||||
|
||||
String kernelName = mask.empty() ? "arithm_bitwise_and" : "arithm_bitwise_and_with_mask";
|
||||
String kernelName = mask.empty() ? "arithm_bitwise_binary" : "arithm_bitwise_binary_with_mask";
|
||||
|
||||
static const char opt [] = "-D OP_BINARY=&";
|
||||
if (mask.empty())
|
||||
bitwise_run(src1, src2, dst, kernelName, &arithm_bitwise_and);
|
||||
bitwise_run(src1, src2, dst, kernelName, &arithm_bitwise_binary, opt);
|
||||
else
|
||||
bitwise_run(src1, src2, dst, mask, kernelName, &arithm_bitwise_and_mask);
|
||||
bitwise_run(src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_mask, opt);
|
||||
}
|
||||
|
||||
void cv::ocl::bitwise_and(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask)
|
||||
@@ -1928,11 +1935,12 @@ void cv::ocl::bitwise_and(const oclMat &src1, const Scalar &src2, oclMat &dst, c
|
||||
std::cout << "Selected device do not support double" << std::endl;
|
||||
return;
|
||||
}
|
||||
String kernelName = mask.data ? "arithm_s_bitwise_and_with_mask" : "arithm_s_bitwise_and";
|
||||
static const char opt [] = "-D OP_BINARY=&";
|
||||
String kernelName = mask.data ? "arithm_s_bitwise_binary_with_mask" : "arithm_s_bitwise_binary";
|
||||
if (mask.data)
|
||||
bitwise_scalar(src1, src2, dst, mask, kernelName, &arithm_bitwise_and_scalar_mask);
|
||||
bitwise_scalar(src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_scalar_mask, opt);
|
||||
else
|
||||
bitwise_scalar(src1, src2, dst, mask, kernelName, &arithm_bitwise_and_scalar);
|
||||
bitwise_scalar(src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_scalar, opt);
|
||||
}
|
||||
|
||||
void cv::ocl::bitwise_xor(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask)
|
||||
@@ -1942,14 +1950,14 @@ void cv::ocl::bitwise_xor(const oclMat &src1, const oclMat &src2, oclMat &dst, c
|
||||
std::cout << "Selected device do not support double" << std::endl;
|
||||
return;
|
||||
}
|
||||
oclMat emptyMat;
|
||||
String kernelName = mask.empty() ? "arithm_bitwise_xor" : "arithm_bitwise_xor_with_mask";
|
||||
String kernelName = mask.empty() ? "arithm_bitwise_binary" : "arithm_bitwise_binary_with_mask";
|
||||
|
||||
static const char opt [] = "-D OP_BINARY=^";
|
||||
|
||||
if (mask.empty())
|
||||
bitwise_run(src1, src2, dst, kernelName, &arithm_bitwise_xor);
|
||||
bitwise_run(src1, src2, dst, kernelName, &arithm_bitwise_binary, opt);
|
||||
else
|
||||
bitwise_run(src1, src2, dst, mask, kernelName, &arithm_bitwise_xor_mask);
|
||||
bitwise_run(src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_mask, opt);
|
||||
}
|
||||
|
||||
|
||||
@@ -1961,11 +1969,12 @@ void cv::ocl::bitwise_xor(const oclMat &src1, const Scalar &src2, oclMat &dst, c
|
||||
std::cout << "Selected device do not support double" << std::endl;
|
||||
return;
|
||||
}
|
||||
String kernelName = mask.data ? "arithm_s_bitwise_xor_with_mask" : "arithm_s_bitwise_xor";
|
||||
String kernelName = mask.data ? "arithm_s_bitwise_binary_with_mask" : "arithm_s_bitwise_binary";
|
||||
static const char opt [] = "-D OP_BINARY=^";
|
||||
if (mask.data)
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_xor_scalar_mask);
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_scalar_mask, opt);
|
||||
else
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_xor_scalar);
|
||||
bitwise_scalar( src1, src2, dst, mask, kernelName, &arithm_bitwise_binary_scalar, opt);
|
||||
}
|
||||
|
||||
oclMat cv::ocl::operator ~ (const oclMat &src)
|
||||
|
||||
Reference in New Issue
Block a user