From: Andrey Kamaev Date: Fri, 25 Jan 2013 10:31:34 +0000 (+0400) Subject: Fix OpenCL build warnings X-Git-Tag: accepted/2.0/20130307.220821~196^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9509dfd1de012ab2d01ea43806d581818c0a5479;p=profile%2Fivi%2Fopencv.git Fix OpenCL build warnings --- diff --git a/modules/ocl/CMakeLists.txt b/modules/ocl/CMakeLists.txt index 5cbf57c..d0e254d 100644 --- a/modules/ocl/CMakeLists.txt +++ b/modules/ocl/CMakeLists.txt @@ -39,6 +39,8 @@ if (HAVE_OPENCL) endif() endif() +ocv_warnings_disable(CMAKE_CXX_FLAGS -Wshadow) + ocv_set_module_sources(HEADERS ${lib_hdrs} SOURCES ${lib_int_hdrs} ${lib_srcs} ${kernels_cpp}) ocv_create_module(${ocl_link_libs}) diff --git a/modules/ocl/include/opencv2/ocl/ocl.hpp b/modules/ocl/include/opencv2/ocl/ocl.hpp index 5e12889..5e4b143 100644 --- a/modules/ocl/include/opencv2/ocl/ocl.hpp +++ b/modules/ocl/include/opencv2/ocl/ocl.hpp @@ -1738,12 +1738,13 @@ namespace cv } } -#if _MSC_VER >= 1200 -#pragma warning( push) -#pragma warning( disable: 4267) +#if defined _MSC_VER && _MSC_VER >= 1200 +# pragma warning( push) +# pragma warning( disable: 4267) #endif #include "opencv2/ocl/matrix_operations.hpp" -#if _MSC_VER >= 1200 -#pragma warning( pop) +#if defined _MSC_VER && _MSC_VER >= 1200 +# pragma warning( pop) #endif + #endif /* __OPENCV_GPU_HPP__ */ diff --git a/modules/ocl/perf/main.cpp b/modules/ocl/perf/main.cpp index fb80136..e517a37 100644 --- a/modules/ocl/perf/main.cpp +++ b/modules/ocl/perf/main.cpp @@ -113,15 +113,15 @@ int main(int argc, char **argv) print_info(); - int flag = CVCL_DEVICE_TYPE_GPU; + // int flag = CVCL_DEVICE_TYPE_GPU; - if(type == "cpu") + // if(type == "cpu") - { + // { - flag = CVCL_DEVICE_TYPE_CPU; + // flag = CVCL_DEVICE_TYPE_CPU; - } + // } std::vector oclinfo; int devnums = getDevice(oclinfo); if(devnums <= device || device < 0) diff --git a/modules/ocl/perf/perf_arithm.cpp b/modules/ocl/perf/perf_arithm.cpp index 197e8d6..9f1dfa3 100644 --- a/modules/ocl/perf/perf_arithm.cpp +++ b/modules/ocl/perf/perf_arithm.cpp @@ -2597,13 +2597,13 @@ TEST_P(Sum, MAT) Has_roi(k); t0 = (double)cvGetTickCount();//cpu start - Scalar cpures = cv::sum(mat1_roi); + cv::sum(mat1_roi); t0 = (double)cvGetTickCount() - t0;//cpu end t1 = (double)cvGetTickCount();//gpu start1 gmat1 = mat1_roi; t2 = (double)cvGetTickCount(); //kernel - Scalar gpures = cv::ocl::sum(gmat1); + cv::ocl::sum(gmat1); t2 = (double)cvGetTickCount() - t2;//kernel t1 = (double)cvGetTickCount() - t1;//gpu end1 if(j == 0) diff --git a/modules/ocl/perf/perf_haar.cpp b/modules/ocl/perf/perf_haar.cpp index a271f44..525b8fb 100644 --- a/modules/ocl/perf/perf_haar.cpp +++ b/modules/ocl/perf/perf_haar.cpp @@ -109,15 +109,15 @@ TEST_F(Haar, FaceDetect) double t = 0; vector faces, oclfaces; - const static Scalar colors[] = { CV_RGB(0, 0, 255), - CV_RGB(0, 128, 255), - CV_RGB(0, 255, 255), - CV_RGB(0, 255, 0), - CV_RGB(255, 128, 0), - CV_RGB(255, 255, 0), - CV_RGB(255, 0, 0), - CV_RGB(255, 0, 255) - } ; + // const static Scalar colors[] = { CV_RGB(0, 0, 255), + // CV_RGB(0, 128, 255), + // CV_RGB(0, 255, 255), + // CV_RGB(0, 255, 0), + // CV_RGB(255, 128, 0), + // CV_RGB(255, 255, 0), + // CV_RGB(255, 0, 0), + // CV_RGB(255, 0, 255) + // } ; Mat gray, smallImg(cvRound (img.rows / scale), cvRound(img.cols / scale), CV_8UC1 ); MemStorage storage(cvCreateMemStorage(0)); diff --git a/modules/ocl/perf/perf_imgproc.cpp b/modules/ocl/perf/perf_imgproc.cpp index 7d544b0..bc54cb2 100644 --- a/modules/ocl/perf/perf_imgproc.cpp +++ b/modules/ocl/perf/perf_imgproc.cpp @@ -379,7 +379,7 @@ TEST_P(bilateralFilter, Mat) } else { - for(int i = 0; i < sizeof(bordertype) / sizeof(int); i++) + for(size_t i = 0; i < sizeof(bordertype) / sizeof(int); i++) { cout << borderstr[i] << endl; #ifndef PRINT_KERNEL_RUN_TIME @@ -397,7 +397,7 @@ TEST_P(bilateralFilter, Mat) for(int j = 0; j < LOOP_TIMES + 1; j ++) { Has_roi(k); - if(((bordertype[i] != cv::BORDER_CONSTANT) && (bordertype[i] != cv::BORDER_REPLICATE)) && (mat1_roi.cols <= radius) || (mat1_roi.cols <= radius) || (mat1_roi.rows <= radius) || (mat1_roi.rows <= radius)) + if(((bordertype[i] != cv::BORDER_CONSTANT) && (bordertype[i] != cv::BORDER_REPLICATE) && (mat1_roi.cols <= radius)) || (mat1_roi.cols <= radius) || (mat1_roi.rows <= radius) || (mat1_roi.rows <= radius)) { continue; } @@ -482,7 +482,7 @@ TEST_P(CopyMakeBorder, Mat) } else { - for(int i = 0; i < sizeof(bordertype) / sizeof(int); i++) + for(size_t i = 0; i < sizeof(bordertype) / sizeof(int); i++) { #ifndef PRINT_KERNEL_RUN_TIME double totalcputick = 0; @@ -1133,7 +1133,6 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int) cv::RNG &rng = TS::ptr()->get_rng(); cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT); - cv::Size dstSize = cv::Size(MWIDTH, MHEIGHT); cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT); double min = 5, max = 16; diff --git a/modules/ocl/perf/precomp.hpp b/modules/ocl/perf/precomp.hpp index b3c540d..34eea55 100644 --- a/modules/ocl/perf/precomp.hpp +++ b/modules/ocl/perf/precomp.hpp @@ -38,6 +38,15 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ + +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-declarations" +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic ignored "-Wmissing-prototypes" +# pragma GCC diagnostic ignored "-Wextra" +# endif +#endif + #ifndef __OPENCV_TEST_PRECOMP_HPP__ #define __OPENCV_TEST_PRECOMP_HPP__ diff --git a/modules/ocl/perf/utility.hpp b/modules/ocl/perf/utility.hpp index 79f0f10..7d34b67 100644 --- a/modules/ocl/perf/utility.hpp +++ b/modules/ocl/perf/utility.hpp @@ -84,12 +84,12 @@ double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2); EXPECT_LE(checkNorm(cv::Mat(mat)), eps) \ } -//#define EXPECT_MAT_NEAR(mat1, mat2, eps) \ -//{ \ -// ASSERT_EQ(mat1.type(), mat2.type()); \ -// ASSERT_EQ(mat1.size(), mat2.size()); \ -// EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps); \ -//} +/*#define EXPECT_MAT_NEAR(mat1, mat2, eps) \ +{ \ + ASSERT_EQ(mat1.type(), mat2.type()); \ + ASSERT_EQ(mat1.size(), mat2.size()); \ + EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps); \ +}*/ #define EXPECT_MAT_NEAR(mat1, mat2, eps,s) \ { \ diff --git a/modules/ocl/src/arithm.cpp b/modules/ocl/src/arithm.cpp index 584ca93..de8f434 100644 --- a/modules/ocl/src/arithm.cpp +++ b/modules/ocl/src/arithm.cpp @@ -362,11 +362,11 @@ void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, -1, depth); } -void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const char **kernelString) +static void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const char **kernelString) { arithmetic_run(src1, src2, dst, kernelName, kernelString, (void *)NULL); } -void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString) +static void arithmetic_run(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString) { if(src1.clCxt -> impl -> double_support == 0 && src1.type() == CV_64F) { @@ -476,7 +476,9 @@ void arithmetic_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst, //CV_Assert(src1.depth() != CV_8S); if(mask.data) + { CV_Assert(mask.type() == CV_8U && src1.rows == mask.rows && src1.cols == mask.cols); + } Context *clCxt = src1.clCxt; int channels = dst.oclchannels(); @@ -530,7 +532,7 @@ void arithmetic_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst, openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, channels, depth); } -void arithmetic_scalar_run(const oclMat &src, oclMat &dst, string kernelName, const char **kernelString, double scalar) +static void arithmetic_scalar_run(const oclMat &src, oclMat &dst, string kernelName, const char **kernelString, double scalar) { if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F) { @@ -590,7 +592,7 @@ void arithmetic_scalar_run(const oclMat &src, oclMat &dst, string kernelName, co typedef void (*ArithmeticFuncS)(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString, int isMatSubScalar); -void arithmetic_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString, int isMatSubScalar) +static void arithmetic_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString, int isMatSubScalar) { static ArithmeticFuncS tab[8] = { @@ -608,7 +610,7 @@ void arithmetic_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, cons cv::ocl::error("Unsupported arithmetic operation", __FILE__, __LINE__); func(src1, src2, dst, mask, kernelName, kernelString, isMatSubScalar); } -void arithmetic_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString) +static void arithmetic_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString) { arithmetic_scalar(src1, src2, dst, mask, kernelName, kernelString, 0); } @@ -660,7 +662,7 @@ void cv::ocl::absdiff(const oclMat &src1, const Scalar &src2, oclMat &dst) ////////////////////////////////////////////////////////////////////////////// ///////////////////////////////// compare /////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void compare_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const char **kernelString) +static void compare_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const char **kernelString) { dst.create(src1.size(), CV_8UC1); CV_Assert(src1.oclchannels() == 1); @@ -739,7 +741,7 @@ void cv::ocl::compare(const oclMat &src1, const oclMat &src2, oclMat &dst , int ////////////////////////////////////////////////////////////////////////////// //type = 0 sum,type = 1 absSum,type = 2 sqrSum -void arithmetic_sum_buffer_run(const oclMat &src, cl_mem &dst, int vlen , int groupnum, int type = 0) +static void arithmetic_sum_buffer_run(const oclMat &src, cl_mem &dst, int vlen , int groupnum, int type = 0) { vector > args; int all_cols = src.step / (vlen * src.elemSize1()); @@ -872,7 +874,7 @@ void cv::ocl::meanStdDev(const oclMat &src, Scalar &mean, Scalar &stddev) ////////////////////////////////////////////////////////////////////////////// //////////////////////////////////// minMax ///////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_minMax_run(const oclMat &src, const oclMat &mask, cl_mem &dst, int vlen , int groupnum, string kernelName) +static void arithmetic_minMax_run(const oclMat &src, const oclMat &mask, cl_mem &dst, int vlen , int groupnum, string kernelName) { vector > args; int all_cols = src.step / (vlen * src.elemSize1()); @@ -909,7 +911,7 @@ void arithmetic_minMax_run(const oclMat &src, const oclMat &mask, cl_mem &dst, i } -void arithmetic_minMax_mask_run(const oclMat &src, const oclMat &mask, cl_mem &dst, int vlen, int groupnum, string kernelName) +static void arithmetic_minMax_mask_run(const oclMat &src, const oclMat &mask, cl_mem &dst, int vlen, int groupnum, string kernelName) { vector > args; size_t gt[3] = {groupnum * 256, 1, 1}, lt[3] = {256, 1, 1}; @@ -1063,7 +1065,7 @@ double cv::ocl::norm(const oclMat &src1, const oclMat &src2, int normType) ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// flip ////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_flip_rows_run(const oclMat &src, oclMat &dst, string kernelName) +static void arithmetic_flip_rows_run(const oclMat &src, oclMat &dst, string kernelName) { if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F) { @@ -1112,7 +1114,7 @@ void arithmetic_flip_rows_run(const oclMat &src, oclMat &dst, string kernelName) openCLExecuteKernel(clCxt, &arithm_flip, kernelName, globalThreads, localThreads, args, -1, depth); } -void arithmetic_flip_cols_run(const oclMat &src, oclMat &dst, string kernelName, bool isVertical) +static void arithmetic_flip_cols_run(const oclMat &src, oclMat &dst, string kernelName, bool isVertical) { if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F) { @@ -1183,7 +1185,7 @@ void cv::ocl::flip(const oclMat &src, oclMat &dst, int flipCode) ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// LUT ////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_lut_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName) +static void arithmetic_lut_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName) { Context *clCxt = src1.clCxt; int channels = src1.oclchannels(); @@ -1284,7 +1286,7 @@ void cv::ocl::LUT(const oclMat &src, const oclMat &lut, oclMat &dst) ////////////////////////////////////////////////////////////////////////////// //////////////////////////////// exp log ///////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_exp_log_run(const oclMat &src, oclMat &dst, string kernelName, const char **kernelString) +static void arithmetic_exp_log_run(const oclMat &src, oclMat &dst, string kernelName, const char **kernelString) { dst.create(src.size(), src.type()); CV_Assert(src.cols == dst.cols && @@ -1333,7 +1335,7 @@ void cv::ocl::log(const oclMat &src, oclMat &dst) ////////////////////////////////////////////////////////////////////////////// ////////////////////////////// magnitude phase /////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_magnitude_phase_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName) +static void arithmetic_magnitude_phase_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName) { if(src1.clCxt -> impl -> double_support == 0 && src1.type() == CV_64F) { @@ -1381,7 +1383,7 @@ void cv::ocl::magnitude(const oclMat &src1, const oclMat &src2, oclMat &dst) arithmetic_magnitude_phase_run(src1, src2, dst, "arithm_magnitude"); } -void arithmetic_phase_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const char **kernelString) +static void arithmetic_phase_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string kernelName, const char **kernelString) { if(src1.clCxt -> impl -> double_support == 0 && src1.type() == CV_64F) { @@ -1444,7 +1446,7 @@ void cv::ocl::phase(const oclMat &x, const oclMat &y, oclMat &Angle , bool angle ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// cartToPolar /////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_cartToPolar_run(const oclMat &src1, const oclMat &src2, oclMat &dst_mag, oclMat &dst_cart, +static void arithmetic_cartToPolar_run(const oclMat &src1, const oclMat &src2, oclMat &dst_mag, oclMat &dst_cart, string kernelName, bool angleInDegrees) { if(src1.clCxt -> impl -> double_support == 0 && src1.type() == CV_64F) @@ -1499,7 +1501,7 @@ void cv::ocl::cartToPolar(const oclMat &x, const oclMat &y, oclMat &mag, oclMat ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////// polarToCart /////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_ptc_run(const oclMat &src1, const oclMat &src2, oclMat &dst1, oclMat &dst2, bool angleInDegrees, +static void arithmetic_ptc_run(const oclMat &src1, const oclMat &src2, oclMat &dst1, oclMat &dst2, bool angleInDegrees, string kernelName) { if(src1.clCxt -> impl -> double_support == 0 && src1.type() == CV_64F) @@ -1564,7 +1566,7 @@ void cv::ocl::polarToCart(const oclMat &magnitude, const oclMat &angle, oclMat & ////////////////////////////////////////////////////////////////////////////// /////////////////////////////////// minMaxLoc //////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_minMaxLoc_run(const oclMat &src, cl_mem &dst, int vlen , int groupnum) +static void arithmetic_minMaxLoc_run(const oclMat &src, cl_mem &dst, int vlen , int groupnum) { vector > args; int all_cols = src.step / (vlen * src.elemSize1()); @@ -1588,7 +1590,7 @@ void arithmetic_minMaxLoc_run(const oclMat &src, cl_mem &dst, int vlen , int gro openCLExecuteKernel(src.clCxt, &arithm_minMaxLoc, "arithm_op_minMaxLoc", gt, lt, args, -1, -1, build_options); } -void arithmetic_minMaxLoc_mask_run(const oclMat &src, const oclMat &mask, cl_mem &dst, int vlen, int groupnum) +static void arithmetic_minMaxLoc_mask_run(const oclMat &src, const oclMat &mask, cl_mem &dst, int vlen, int groupnum) { vector > args; size_t gt[3] = {groupnum * 256, 1, 1}, lt[3] = {256, 1, 1}; @@ -1702,7 +1704,7 @@ void cv::ocl::minMaxLoc(const oclMat &src, double *minVal, double *maxVal, ////////////////////////////////////////////////////////////////////////////// ///////////////////////////// countNonZero /////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void arithmetic_countNonZero_run(const oclMat &src, cl_mem &dst, int vlen , int groupnum, string kernelName) +static void arithmetic_countNonZero_run(const oclMat &src, cl_mem &dst, int vlen , int groupnum, string kernelName) { vector > args; int all_cols = src.step / (vlen * src.elemSize1()); @@ -1759,7 +1761,7 @@ int cv::ocl::countNonZero(const oclMat &src) ////////////////////////////////////////////////////////////////////////////// ////////////////////////////////bitwise_op//////////////////////////////////// ////////////////////////////////////////////////////////////////////////////// -void bitwise_run(const oclMat &src1, oclMat &dst, string kernelName, const char **kernelString) +static void bitwise_run(const oclMat &src1, oclMat &dst, string kernelName, const char **kernelString) { dst.create(src1.size(), src1.type()); @@ -1853,11 +1855,11 @@ void bitwise_run(const oclMat &src1, const oclMat &src2, oclMat &dst, string ker openCLExecuteKernel(clCxt, kernelString, kernelName, globalThreads, localThreads, args, -1, depth); } -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) { bitwise_run(src1, src2, dst, kernelName, kernelString, (void *)NULL); } -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) { dst.create(src1.size(), src1.type()); CV_Assert(src1.cols == src2.cols && src2.cols == dst.cols && @@ -1919,7 +1921,9 @@ void bitwise_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst, con if(mask.data) + { CV_Assert(mask.type() == CV_8U && src1.rows == mask.rows && src1.cols == mask.cols); + } Context *clCxt = src1.clCxt; int channels = dst.oclchannels(); @@ -1977,7 +1981,7 @@ void bitwise_scalar_run(const oclMat &src1, const Scalar &src2, oclMat &dst, con typedef void (*BitwiseFuncS)(const oclMat &src1, const Scalar &src2, oclMat &dst, const oclMat &mask, string kernelName, const char **kernelString, int isMatSubScalar); -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) { static BitwiseFuncS tab[8] = { @@ -2007,7 +2011,7 @@ void bitwise_scalar(const oclMat &src1, const Scalar &src2, oclMat &dst, const o cv::ocl::error("Unsupported arithmetic operation", __FILE__, __LINE__); func(src1, src2, dst, mask, kernelName, kernelString, isMatSubScalar); } -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) { bitwise_scalar(src1, src2, dst, mask, kernelName, kernelString, 0); } @@ -2153,7 +2157,7 @@ cv::ocl::oclMat cv::ocl::operator ^ (const oclMat &src1, const oclMat &src2) ////////////////////////////////////////////////////////////////////////////// #define TILE_DIM (32) #define BLOCK_ROWS (256/TILE_DIM) -void transpose_run(const oclMat &src, oclMat &dst, string kernelName) +static void transpose_run(const oclMat &src, oclMat &dst, string kernelName) { if(src.clCxt -> impl -> double_support == 0 && src.type() == CV_64F) { @@ -2368,7 +2372,7 @@ void cv::ocl::magnitudeSqr(const oclMat &src1, oclMat &dst) openCLExecuteKernel(clCxt, &arithm_magnitudeSqr, "magnitudeSqr", globalThreads, localThreads, args, 2, depth); } -void arithmetic_pow_run(const oclMat &src1, double p, oclMat &dst, string kernelName, const char **kernelString) +static void arithmetic_pow_run(const oclMat &src1, double p, oclMat &dst, string kernelName, const char **kernelString) { CV_Assert(src1.cols == dst.cols && src1.rows == dst.rows); CV_Assert(src1.type() == dst.type()); @@ -2417,7 +2421,7 @@ void cv::ocl::pow(const oclMat &x, double p, oclMat &y) return; } - CV_Assert(x.type() == y.type() && x.size() == y.size() && x.depth() == CV_32F || x.depth() == CV_64F); + CV_Assert((x.type() == y.type() && x.size() == y.size() && x.depth() == CV_32F) || x.depth() == CV_64F); y.create(x.size(), x.type()); string kernelName = "arithm_pow"; diff --git a/modules/ocl/src/brute_force_matcher.cpp b/modules/ocl/src/brute_force_matcher.cpp index 440a310..9fe14d2 100644 --- a/modules/ocl/src/brute_force_matcher.cpp +++ b/modules/ocl/src/brute_force_matcher.cpp @@ -821,7 +821,7 @@ void findKnnMatch(int k, const oclMat &trainIdx, const oclMat &distance, const o } } -void findKnnMatchDispatcher(int k, const oclMat &trainIdx, const oclMat &distance, const oclMat &allDist, int distType) +static void findKnnMatchDispatcher(int k, const oclMat &trainIdx, const oclMat &distance, const oclMat &allDist, int distType) { findKnnMatch<256>(k, trainIdx, distance, allDist, distType); } diff --git a/modules/ocl/src/filtering.cpp b/modules/ocl/src/filtering.cpp index 18fed6e..0eca510 100644 --- a/modules/ocl/src/filtering.cpp +++ b/modules/ocl/src/filtering.cpp @@ -332,7 +332,7 @@ public: **Extend this if necessary later. **Note that the kernel need to be further refined. */ -void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, const Point anchor) +static void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, const Point anchor) { //Normalize the result by default //float alpha = ksize.height * ksize.width; @@ -388,7 +388,7 @@ void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, c } char compile_option[128]; - sprintf(compile_option, "-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D ERODE %s", anchor.x, anchor.y, localThreads[0], localThreads[1], s); + sprintf(compile_option, "-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D ERODE %s", anchor.x, anchor.y, (int)localThreads[0], (int)localThreads[1], s); vector< pair > args; args.push_back(make_pair(sizeof(cl_mem), (void *)&src.data)); args.push_back(make_pair(sizeof(cl_mem), (void *)&dst.data)); @@ -407,7 +407,7 @@ void GPUErode(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, c //! data type supported: CV_8UC1, CV_8UC4, CV_32FC1, CV_32FC4 -void GPUDilate(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, const Point anchor) +static void GPUDilate(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, const Point anchor) { //Normalize the result by default //float alpha = ksize.height * ksize.width; @@ -463,7 +463,7 @@ void GPUDilate(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, } char compile_option[128]; - sprintf(compile_option, "-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D DILATE %s", anchor.x, anchor.y, localThreads[0], localThreads[1], s); + sprintf(compile_option, "-D RADIUSX=%d -D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D DILATE %s", anchor.x, anchor.y, (int)localThreads[0], (int)localThreads[1], s); vector< pair > args; args.push_back(make_pair(sizeof(cl_mem), (void *)&src.data)); args.push_back(make_pair(sizeof(cl_mem), (void *)&dst.data)); @@ -691,7 +691,7 @@ public: }; } -void GPUFilter2D(const oclMat &src, oclMat &dst, oclMat &mat_kernel, +static void GPUFilter2D(const oclMat &src, oclMat &dst, oclMat &mat_kernel, Size &ksize, const Point anchor, const int borderType) { CV_Assert(src.clCxt == dst.clCxt); @@ -850,7 +850,7 @@ Ptr cv::ocl::createSeparableFilter_GPU(const Ptr> 1; vector > args; args.push_back(make_pair(sizeof(cl_mem), &src.data)); @@ -1363,18 +1363,18 @@ void linearColumnFilter_gpu(const oclMat &src, const oclMat &dst, oclMat mat_ker case 1: globalThreads[0] = (dst.cols + localThreads[0] - 1) / localThreads[0] * localThreads[0]; sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float", "uchar", "convert_uchar_sat"); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float", "uchar", "convert_uchar_sat"); break; case 2: globalThreads[0] = ((dst.cols + 1) / 2 + localThreads[0] - 1) / localThreads[0] * localThreads[0]; sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float2", "uchar2", "convert_uchar2_sat"); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float2", "uchar2", "convert_uchar2_sat"); break; case 3: case 4: globalThreads[0] = (dst.cols + localThreads[0] - 1) / localThreads[0] * localThreads[0]; sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float4", "uchar4", "convert_uchar4_sat"); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float4", "uchar4", "convert_uchar4_sat"); break; } } @@ -1386,21 +1386,21 @@ void linearColumnFilter_gpu(const oclMat &src, const oclMat &dst, oclMat mat_ker { case CV_32SC1: sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float", "int", "convert_int_sat"); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float", "int", "convert_int_sat"); break; case CV_32SC3: case CV_32SC4: sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float4", "int4", "convert_int4_sat"); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float4", "int4", "convert_int4_sat"); break; case CV_32FC1: sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float", "float", ""); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float", "float", ""); break; case CV_32FC3: case CV_32FC4: sprintf(compile_option, "-D RADIUSY=%d -D LSIZE0=%d -D LSIZE1=%d -D CN=%d -D %s -D GENTYPE_SRC=%s -D GENTYPE_DST=%s -D convert_to_DST=%s", - anchor, localThreads[0], localThreads[1], channels, btype, "float4", "float4", ""); + anchor, (int)localThreads[0], (int)localThreads[1], channels, btype, "float4", "float4", ""); break; } } @@ -1411,10 +1411,11 @@ void linearColumnFilter_gpu(const oclMat &src, const oclMat &dst, oclMat mat_ker CV_Assert(src.oclchannels() == dst.oclchannels()); CV_Assert(ksize == (anchor << 1) + 1); int src_pix_per_row, dst_pix_per_row; - int src_offset_x, src_offset_y, dst_offset_in_pixel; + //int src_offset_x, src_offset_y; + int dst_offset_in_pixel; src_pix_per_row = src.step / src.elemSize(); - src_offset_x = (src.offset % src.step) / src.elemSize(); - src_offset_y = src.offset / src.step; + //src_offset_x = (src.offset % src.step) / src.elemSize(); + //src_offset_y = src.offset / src.step; dst_pix_per_row = dst.step / dst.elemSize(); dst_offset_in_pixel = dst.offset / dst.elemSize(); diff --git a/modules/ocl/src/haar.cpp b/modules/ocl/src/haar.cpp index 492cd91..5c9b75b 100644 --- a/modules/ocl/src/haar.cpp +++ b/modules/ocl/src/haar.cpp @@ -150,7 +150,7 @@ typedef struct int imgoff; float factor; } detect_piramid_info; -#if WIN32 +#ifdef WIN32 #define _ALIGNED_ON(_ALIGNMENT) __declspec(align(_ALIGNMENT)) typedef _ALIGNED_ON(128) struct GpuHidHaarFeature { @@ -300,40 +300,37 @@ const float icv_stage_threshold_bias = 0.0001f; double globaltime = 0; -CvHaarClassifierCascade * -gpuCreateHaarClassifierCascade( int stage_count ) -{ - CvHaarClassifierCascade *cascade = 0; +// static CvHaarClassifierCascade * gpuCreateHaarClassifierCascade( int stage_count ) +// { +// CvHaarClassifierCascade *cascade = 0; - int block_size = sizeof(*cascade) + stage_count * sizeof(*cascade->stage_classifier); +// int block_size = sizeof(*cascade) + stage_count * sizeof(*cascade->stage_classifier); - if( stage_count <= 0 ) - CV_Error( CV_StsOutOfRange, "Number of stages should be positive" ); +// if( stage_count <= 0 ) +// CV_Error( CV_StsOutOfRange, "Number of stages should be positive" ); - cascade = (CvHaarClassifierCascade *)cvAlloc( block_size ); - memset( cascade, 0, block_size ); +// cascade = (CvHaarClassifierCascade *)cvAlloc( block_size ); +// memset( cascade, 0, block_size ); - cascade->stage_classifier = (CvHaarStageClassifier *)(cascade + 1); - cascade->flags = CV_HAAR_MAGIC_VAL; - cascade->count = stage_count; +// cascade->stage_classifier = (CvHaarStageClassifier *)(cascade + 1); +// cascade->flags = CV_HAAR_MAGIC_VAL; +// cascade->count = stage_count; - return cascade; -} +// return cascade; +// } //static int globalcounter = 0; -void -gpuReleaseHidHaarClassifierCascade( GpuHidHaarClassifierCascade **_cascade ) -{ - if( _cascade && *_cascade ) - { - cvFree( _cascade ); - } -} +// static void gpuReleaseHidHaarClassifierCascade( GpuHidHaarClassifierCascade **_cascade ) +// { +// if( _cascade && *_cascade ) +// { +// cvFree( _cascade ); +// } +// } /* create more efficient internal representation of haar classifier cascade */ -GpuHidHaarClassifierCascade * -gpuCreateHidHaarClassifierCascade( CvHaarClassifierCascade *cascade, int *size, int *totalclassifier) +static GpuHidHaarClassifierCascade * gpuCreateHidHaarClassifierCascade( CvHaarClassifierCascade *cascade, int *size, int *totalclassifier) { GpuHidHaarClassifierCascade *out = 0; @@ -522,8 +519,7 @@ gpuCreateHidHaarClassifierCascade( CvHaarClassifierCascade *cascade, int *size, ((rect).p0[offset] - (rect).p1[offset] - (rect).p2[offset] + (rect).p3[offset]) -CV_IMPL void -gpuSetImagesForHaarClassifierCascade( CvHaarClassifierCascade *_cascade, +static void gpuSetImagesForHaarClassifierCascade( CvHaarClassifierCascade *_cascade, /* const CvArr* _sum, const CvArr* _sqsum, const CvArr* _tilted_sum,*/ @@ -767,8 +763,8 @@ gpuSetImagesForHaarClassifierCascade( CvHaarClassifierCascade *_cascade, } /* j */ } } -CV_IMPL void -gpuSetHaarClassifierCascade( CvHaarClassifierCascade *_cascade + +static void gpuSetHaarClassifierCascade( CvHaarClassifierCascade *_cascade /*double scale=0.0,*/ /*int step*/) { @@ -870,7 +866,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS int datasize=0; int totalclassifier=0; - void *out; + //void *out; GpuHidHaarClassifierCascade *gcascade; GpuHidHaarStageClassifier *stage; GpuHidHaarClassifier *classifier; @@ -910,7 +906,7 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS //gsqsum1 = oclMat( gimg.rows + 1, gimg.cols + 1, CV_32FC1 ); if( !cascade->hid_cascade ) - out = (void *)gpuCreateHidHaarClassifierCascade(cascade, &datasize, &totalclassifier); + /*out = (void *)*/gpuCreateHidHaarClassifierCascade(cascade, &datasize, &totalclassifier); if( cascade->hid_cascade->has_tilted_features ) gtilted1 = oclMat( gimg.rows + 1, gimg.cols + 1, CV_32SC1 ); @@ -1411,206 +1407,203 @@ CvSeq *cv::ocl::OclCascadeClassifier::oclHaarDetectObjects( oclMat &gimg, CvMemS } -CvHaarClassifierCascade * -gpuLoadCascadeCART( const char **input_cascade, int n, CvSize orig_window_size ) -{ - int i; - CvHaarClassifierCascade *cascade = gpuCreateHaarClassifierCascade(n); - cascade->orig_window_size = orig_window_size; - - for( i = 0; i < n; i++ ) - { - int j, count, l; - float threshold = 0; - const char *stage = input_cascade[i]; - int dl = 0; - - /* tree links */ - int parent = -1; - int next = -1; - - sscanf( stage, "%d%n", &count, &dl ); - stage += dl; - - assert( count > 0 ); - cascade->stage_classifier[i].count = count; - cascade->stage_classifier[i].classifier = - (CvHaarClassifier *)cvAlloc( count * sizeof(cascade->stage_classifier[i].classifier[0])); - - for( j = 0; j < count; j++ ) - { - CvHaarClassifier *classifier = cascade->stage_classifier[i].classifier + j; - int k, rects = 0; - char str[100]; - - sscanf( stage, "%d%n", &classifier->count, &dl ); - stage += dl; - - classifier->haar_feature = (CvHaarFeature *) cvAlloc( - classifier->count * ( sizeof( *classifier->haar_feature ) + - sizeof( *classifier->threshold ) + - sizeof( *classifier->left ) + - sizeof( *classifier->right ) ) + - (classifier->count + 1) * sizeof( *classifier->alpha ) ); - classifier->threshold = (float *) (classifier->haar_feature + classifier->count); - classifier->left = (int *) (classifier->threshold + classifier->count); - classifier->right = (int *) (classifier->left + classifier->count); - classifier->alpha = (float *) (classifier->right + classifier->count); - - for( l = 0; l < classifier->count; l++ ) - { - sscanf( stage, "%d%n", &rects, &dl ); - stage += dl; - - assert( rects >= 2 && rects <= CV_HAAR_FEATURE_MAX ); - - for( k = 0; k < rects; k++ ) - { - CvRect r; - int band = 0; - sscanf( stage, "%d%d%d%d%d%f%n", - &r.x, &r.y, &r.width, &r.height, &band, - &(classifier->haar_feature[l].rect[k].weight), &dl ); - stage += dl; - classifier->haar_feature[l].rect[k].r = r; - } - sscanf( stage, "%s%n", str, &dl ); - stage += dl; - - classifier->haar_feature[l].tilted = strncmp( str, "tilted", 6 ) == 0; - - for( k = rects; k < CV_HAAR_FEATURE_MAX; k++ ) - { - memset( classifier->haar_feature[l].rect + k, 0, - sizeof(classifier->haar_feature[l].rect[k]) ); - } - - sscanf( stage, "%f%d%d%n", &(classifier->threshold[l]), - &(classifier->left[l]), - &(classifier->right[l]), &dl ); - stage += dl; - } - for( l = 0; l <= classifier->count; l++ ) - { - sscanf( stage, "%f%n", &(classifier->alpha[l]), &dl ); - stage += dl; - } - } - - sscanf( stage, "%f%n", &threshold, &dl ); - stage += dl; - - cascade->stage_classifier[i].threshold = threshold; - - /* load tree links */ - if( sscanf( stage, "%d%d%n", &parent, &next, &dl ) != 2 ) - { - parent = i - 1; - next = -1; - } - stage += dl; - - cascade->stage_classifier[i].parent = parent; - cascade->stage_classifier[i].next = next; - cascade->stage_classifier[i].child = -1; - - if( parent != -1 && cascade->stage_classifier[parent].child == -1 ) - { - cascade->stage_classifier[parent].child = i; - } - } - - return cascade; -} +// static CvHaarClassifierCascade * gpuLoadCascadeCART( const char **input_cascade, int n, CvSize orig_window_size ) +// { +// int i; +// CvHaarClassifierCascade *cascade = gpuCreateHaarClassifierCascade(n); +// cascade->orig_window_size = orig_window_size; + +// for( i = 0; i < n; i++ ) +// { +// int j, count, l; +// float threshold = 0; +// const char *stage = input_cascade[i]; +// int dl = 0; + +// /* tree links */ +// int parent = -1; +// int next = -1; + +// sscanf( stage, "%d%n", &count, &dl ); +// stage += dl; + +// assert( count > 0 ); +// cascade->stage_classifier[i].count = count; +// cascade->stage_classifier[i].classifier = +// (CvHaarClassifier *)cvAlloc( count * sizeof(cascade->stage_classifier[i].classifier[0])); + +// for( j = 0; j < count; j++ ) +// { +// CvHaarClassifier *classifier = cascade->stage_classifier[i].classifier + j; +// int k, rects = 0; +// char str[100]; + +// sscanf( stage, "%d%n", &classifier->count, &dl ); +// stage += dl; + +// classifier->haar_feature = (CvHaarFeature *) cvAlloc( +// classifier->count * ( sizeof( *classifier->haar_feature ) + +// sizeof( *classifier->threshold ) + +// sizeof( *classifier->left ) + +// sizeof( *classifier->right ) ) + +// (classifier->count + 1) * sizeof( *classifier->alpha ) ); +// classifier->threshold = (float *) (classifier->haar_feature + classifier->count); +// classifier->left = (int *) (classifier->threshold + classifier->count); +// classifier->right = (int *) (classifier->left + classifier->count); +// classifier->alpha = (float *) (classifier->right + classifier->count); + +// for( l = 0; l < classifier->count; l++ ) +// { +// sscanf( stage, "%d%n", &rects, &dl ); +// stage += dl; + +// assert( rects >= 2 && rects <= CV_HAAR_FEATURE_MAX ); + +// for( k = 0; k < rects; k++ ) +// { +// CvRect r; +// int band = 0; +// sscanf( stage, "%d%d%d%d%d%f%n", +// &r.x, &r.y, &r.width, &r.height, &band, +// &(classifier->haar_feature[l].rect[k].weight), &dl ); +// stage += dl; +// classifier->haar_feature[l].rect[k].r = r; +// } +// sscanf( stage, "%s%n", str, &dl ); +// stage += dl; + +// classifier->haar_feature[l].tilted = strncmp( str, "tilted", 6 ) == 0; + +// for( k = rects; k < CV_HAAR_FEATURE_MAX; k++ ) +// { +// memset( classifier->haar_feature[l].rect + k, 0, +// sizeof(classifier->haar_feature[l].rect[k]) ); +// } + +// sscanf( stage, "%f%d%d%n", &(classifier->threshold[l]), +// &(classifier->left[l]), +// &(classifier->right[l]), &dl ); +// stage += dl; +// } +// for( l = 0; l <= classifier->count; l++ ) +// { +// sscanf( stage, "%f%n", &(classifier->alpha[l]), &dl ); +// stage += dl; +// } +// } + +// sscanf( stage, "%f%n", &threshold, &dl ); +// stage += dl; + +// cascade->stage_classifier[i].threshold = threshold; + +// /* load tree links */ +// if( sscanf( stage, "%d%d%n", &parent, &next, &dl ) != 2 ) +// { +// parent = i - 1; +// next = -1; +// } +// stage += dl; + +// cascade->stage_classifier[i].parent = parent; +// cascade->stage_classifier[i].next = next; +// cascade->stage_classifier[i].child = -1; + +// if( parent != -1 && cascade->stage_classifier[parent].child == -1 ) +// { +// cascade->stage_classifier[parent].child = i; +// } +// } + +// return cascade; +// } #ifndef _MAX_PATH #define _MAX_PATH 1024 #endif -CV_IMPL CvHaarClassifierCascade * -gpuLoadHaarClassifierCascade( const char *directory, CvSize orig_window_size ) -{ - const char **input_cascade = 0; - CvHaarClassifierCascade *cascade = 0; - - int i, n; - const char *slash; - char name[_MAX_PATH]; - int size = 0; - char *ptr = 0; - - if( !directory ) - CV_Error( CV_StsNullPtr, "Null path is passed" ); - - n = (int)strlen(directory) - 1; - slash = directory[n] == '\\' || directory[n] == '/' ? "" : "/"; - - /* try to read the classifier from directory */ - for( n = 0; ; n++ ) - { - sprintf( name, "%s%s%d/AdaBoostCARTHaarClassifier.txt", directory, slash, n ); - FILE *f = fopen( name, "rb" ); - if( !f ) - break; - fseek( f, 0, SEEK_END ); - size += ftell( f ) + 1; - fclose(f); - } - - if( n == 0 && slash[0] ) - return (CvHaarClassifierCascade *)cvLoad( directory ); - - if( n == 0 ) - CV_Error( CV_StsBadArg, "Invalid path" ); - - size += (n + 1) * sizeof(char *); - input_cascade = (const char **)cvAlloc( size ); - ptr = (char *)(input_cascade + n + 1); - - for( i = 0; i < n; i++ ) - { - sprintf( name, "%s/%d/AdaBoostCARTHaarClassifier.txt", directory, i ); - FILE *f = fopen( name, "rb" ); - if( !f ) - CV_Error( CV_StsError, "" ); - fseek( f, 0, SEEK_END ); - size = ftell( f ); - fseek( f, 0, SEEK_SET ); - fread( ptr, 1, size, f ); - fclose(f); - input_cascade[i] = ptr; - ptr += size; - *ptr++ = '\0'; - } - - input_cascade[n] = 0; - cascade = gpuLoadCascadeCART( input_cascade, n, orig_window_size ); - - if( input_cascade ) - cvFree( &input_cascade ); - - return cascade; -} - - -CV_IMPL void -gpuReleaseHaarClassifierCascade( CvHaarClassifierCascade **_cascade ) -{ - if( _cascade && *_cascade ) - { - int i, j; - CvHaarClassifierCascade *cascade = *_cascade; - - for( i = 0; i < cascade->count; i++ ) - { - for( j = 0; j < cascade->stage_classifier[i].count; j++ ) - cvFree( &cascade->stage_classifier[i].classifier[j].haar_feature ); - cvFree( &cascade->stage_classifier[i].classifier ); - } - gpuReleaseHidHaarClassifierCascade( (GpuHidHaarClassifierCascade **)&cascade->hid_cascade ); - cvFree( _cascade ); - } -} +// static CvHaarClassifierCascade * gpuLoadHaarClassifierCascade( const char *directory, CvSize orig_window_size ) +// { +// const char **input_cascade = 0; +// CvHaarClassifierCascade *cascade = 0; + +// int i, n; +// const char *slash; +// char name[_MAX_PATH]; +// int size = 0; +// char *ptr = 0; + +// if( !directory ) +// CV_Error( CV_StsNullPtr, "Null path is passed" ); + +// n = (int)strlen(directory) - 1; +// slash = directory[n] == '\\' || directory[n] == '/' ? "" : "/"; + +// /* try to read the classifier from directory */ +// for( n = 0; ; n++ ) +// { +// sprintf( name, "%s%s%d/AdaBoostCARTHaarClassifier.txt", directory, slash, n ); +// FILE *f = fopen( name, "rb" ); +// if( !f ) +// break; +// fseek( f, 0, SEEK_END ); +// size += ftell( f ) + 1; +// fclose(f); +// } + +// if( n == 0 && slash[0] ) +// return (CvHaarClassifierCascade *)cvLoad( directory ); + +// if( n == 0 ) +// CV_Error( CV_StsBadArg, "Invalid path" ); + +// size += (n + 1) * sizeof(char *); +// input_cascade = (const char **)cvAlloc( size ); +// ptr = (char *)(input_cascade + n + 1); + +// for( i = 0; i < n; i++ ) +// { +// sprintf( name, "%s/%d/AdaBoostCARTHaarClassifier.txt", directory, i ); +// FILE *f = fopen( name, "rb" ); +// if( !f ) +// CV_Error( CV_StsError, "" ); +// fseek( f, 0, SEEK_END ); +// size = ftell( f ); +// fseek( f, 0, SEEK_SET ); +// CV_Assert((size_t)size == fread( ptr, 1, size, f )); +// fclose(f); +// input_cascade[i] = ptr; +// ptr += size; +// *ptr++ = '\0'; +// } + +// input_cascade[n] = 0; +// cascade = gpuLoadCascadeCART( input_cascade, n, orig_window_size ); + +// if( input_cascade ) +// cvFree( &input_cascade ); + +// return cascade; +// } + + +// static void gpuReleaseHaarClassifierCascade( CvHaarClassifierCascade **_cascade ) +// { +// if( _cascade && *_cascade ) +// { +// int i, j; +// CvHaarClassifierCascade *cascade = *_cascade; + +// for( i = 0; i < cascade->count; i++ ) +// { +// for( j = 0; j < cascade->stage_classifier[i].count; j++ ) +// cvFree( &cascade->stage_classifier[i].classifier[j].haar_feature ); +// cvFree( &cascade->stage_classifier[i].classifier ); +// } +// gpuReleaseHidHaarClassifierCascade( (GpuHidHaarClassifierCascade **)&cascade->hid_cascade ); +// cvFree( _cascade ); +// } +// } /****************************************************************************************\ @@ -1634,524 +1627,520 @@ gpuReleaseHaarClassifierCascade( CvHaarClassifierCascade **_cascade ) #define ICV_HAAR_PARENT_NAME "parent" #define ICV_HAAR_NEXT_NAME "next" -int -gpuIsHaarClassifier( const void *struct_ptr ) -{ - return CV_IS_HAAR_CLASSIFIER( struct_ptr ); -} - -void * -gpuReadHaarClassifier( CvFileStorage *fs, CvFileNode *node ) -{ - CvHaarClassifierCascade *cascade = NULL; - - char buf[256]; - CvFileNode *seq_fn = NULL; /* sequence */ - CvFileNode *fn = NULL; - CvFileNode *stages_fn = NULL; - CvSeqReader stages_reader; - int n; - int i, j, k, l; - int parent, next; - - stages_fn = cvGetFileNodeByName( fs, node, ICV_HAAR_STAGES_NAME ); - if( !stages_fn || !CV_NODE_IS_SEQ( stages_fn->tag) ) - CV_Error( CV_StsError, "Invalid stages node" ); - - n = stages_fn->data.seq->total; - cascade = gpuCreateHaarClassifierCascade(n); - - /* read size */ - seq_fn = cvGetFileNodeByName( fs, node, ICV_HAAR_SIZE_NAME ); - if( !seq_fn || !CV_NODE_IS_SEQ( seq_fn->tag ) || seq_fn->data.seq->total != 2 ) - CV_Error( CV_StsError, "size node is not a valid sequence." ); - fn = (CvFileNode *) cvGetSeqElem( seq_fn->data.seq, 0 ); - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 ) - CV_Error( CV_StsError, "Invalid size node: width must be positive integer" ); - cascade->orig_window_size.width = fn->data.i; - fn = (CvFileNode *) cvGetSeqElem( seq_fn->data.seq, 1 ); - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 ) - CV_Error( CV_StsError, "Invalid size node: height must be positive integer" ); - cascade->orig_window_size.height = fn->data.i; - - cvStartReadSeq( stages_fn->data.seq, &stages_reader ); - for( i = 0; i < n; ++i ) - { - CvFileNode *stage_fn; - CvFileNode *trees_fn; - CvSeqReader trees_reader; - - stage_fn = (CvFileNode *) stages_reader.ptr; - if( !CV_NODE_IS_MAP( stage_fn->tag ) ) - { - sprintf( buf, "Invalid stage %d", i ); - CV_Error( CV_StsError, buf ); - } - - trees_fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_TREES_NAME ); - if( !trees_fn || !CV_NODE_IS_SEQ( trees_fn->tag ) - || trees_fn->data.seq->total <= 0 ) - { - sprintf( buf, "Trees node is not a valid sequence. (stage %d)", i ); - CV_Error( CV_StsError, buf ); - } - - cascade->stage_classifier[i].classifier = - (CvHaarClassifier *) cvAlloc( trees_fn->data.seq->total - * sizeof( cascade->stage_classifier[i].classifier[0] ) ); - for( j = 0; j < trees_fn->data.seq->total; ++j ) - { - cascade->stage_classifier[i].classifier[j].haar_feature = NULL; - } - cascade->stage_classifier[i].count = trees_fn->data.seq->total; - - cvStartReadSeq( trees_fn->data.seq, &trees_reader ); - for( j = 0; j < trees_fn->data.seq->total; ++j ) - { - CvFileNode *tree_fn; - CvSeqReader tree_reader; - CvHaarClassifier *classifier; - int last_idx; - - classifier = &cascade->stage_classifier[i].classifier[j]; - tree_fn = (CvFileNode *) trees_reader.ptr; - if( !CV_NODE_IS_SEQ( tree_fn->tag ) || tree_fn->data.seq->total <= 0 ) - { - sprintf( buf, "Tree node is not a valid sequence." - " (stage %d, tree %d)", i, j ); - CV_Error( CV_StsError, buf ); - } - - classifier->count = tree_fn->data.seq->total; - classifier->haar_feature = (CvHaarFeature *) cvAlloc( - classifier->count * ( sizeof( *classifier->haar_feature ) + - sizeof( *classifier->threshold ) + - sizeof( *classifier->left ) + - sizeof( *classifier->right ) ) + - (classifier->count + 1) * sizeof( *classifier->alpha ) ); - classifier->threshold = (float *) (classifier->haar_feature + classifier->count); - classifier->left = (int *) (classifier->threshold + classifier->count); - classifier->right = (int *) (classifier->left + classifier->count); - classifier->alpha = (float *) (classifier->right + classifier->count); - - cvStartReadSeq( tree_fn->data.seq, &tree_reader ); - for( k = 0, last_idx = 0; k < tree_fn->data.seq->total; ++k ) - { - CvFileNode *node_fn; - CvFileNode *feature_fn; - CvFileNode *rects_fn; - CvSeqReader rects_reader; - - node_fn = (CvFileNode *) tree_reader.ptr; - if( !CV_NODE_IS_MAP( node_fn->tag ) ) - { - sprintf( buf, "Tree node %d is not a valid map. (stage %d, tree %d)", - k, i, j ); - CV_Error( CV_StsError, buf ); - } - feature_fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_FEATURE_NAME ); - if( !feature_fn || !CV_NODE_IS_MAP( feature_fn->tag ) ) - { - sprintf( buf, "Feature node is not a valid map. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - rects_fn = cvGetFileNodeByName( fs, feature_fn, ICV_HAAR_RECTS_NAME ); - if( !rects_fn || !CV_NODE_IS_SEQ( rects_fn->tag ) - || rects_fn->data.seq->total < 1 - || rects_fn->data.seq->total > CV_HAAR_FEATURE_MAX ) - { - sprintf( buf, "Rects node is not a valid sequence. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - cvStartReadSeq( rects_fn->data.seq, &rects_reader ); - for( l = 0; l < rects_fn->data.seq->total; ++l ) - { - CvFileNode *rect_fn; - CvRect r; - - rect_fn = (CvFileNode *) rects_reader.ptr; - if( !CV_NODE_IS_SEQ( rect_fn->tag ) || rect_fn->data.seq->total != 5 ) - { - sprintf( buf, "Rect %d is not a valid sequence. " - "(stage %d, tree %d, node %d)", l, i, j, k ); - CV_Error( CV_StsError, buf ); - } - - fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 0 ); - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i < 0 ) - { - sprintf( buf, "x coordinate must be non-negative integer. " - "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); - CV_Error( CV_StsError, buf ); - } - r.x = fn->data.i; - fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 1 ); - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i < 0 ) - { - sprintf( buf, "y coordinate must be non-negative integer. " - "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); - CV_Error( CV_StsError, buf ); - } - r.y = fn->data.i; - fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 2 ); - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 - || r.x + fn->data.i > cascade->orig_window_size.width ) - { - sprintf( buf, "width must be positive integer and " - "(x + width) must not exceed window width. " - "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); - CV_Error( CV_StsError, buf ); - } - r.width = fn->data.i; - fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 3 ); - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 - || r.y + fn->data.i > cascade->orig_window_size.height ) - { - sprintf( buf, "height must be positive integer and " - "(y + height) must not exceed window height. " - "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); - CV_Error( CV_StsError, buf ); - } - r.height = fn->data.i; - fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 4 ); - if( !CV_NODE_IS_REAL( fn->tag ) ) - { - sprintf( buf, "weight must be real number. " - "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); - CV_Error( CV_StsError, buf ); - } - - classifier->haar_feature[k].rect[l].weight = (float) fn->data.f; - classifier->haar_feature[k].rect[l].r = r; - - CV_NEXT_SEQ_ELEM( sizeof( *rect_fn ), rects_reader ); - } /* for each rect */ - for( l = rects_fn->data.seq->total; l < CV_HAAR_FEATURE_MAX; ++l ) - { - classifier->haar_feature[k].rect[l].weight = 0; - classifier->haar_feature[k].rect[l].r = cvRect( 0, 0, 0, 0 ); - } - - fn = cvGetFileNodeByName( fs, feature_fn, ICV_HAAR_TILTED_NAME); - if( !fn || !CV_NODE_IS_INT( fn->tag ) ) - { - sprintf( buf, "tilted must be 0 or 1. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - classifier->haar_feature[k].tilted = ( fn->data.i != 0 ); - fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_THRESHOLD_NAME); - if( !fn || !CV_NODE_IS_REAL( fn->tag ) ) - { - sprintf( buf, "threshold must be real number. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - classifier->threshold[k] = (float) fn->data.f; - fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_LEFT_NODE_NAME); - if( fn ) - { - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= k - || fn->data.i >= tree_fn->data.seq->total ) - { - sprintf( buf, "left node must be valid node number. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - /* left node */ - classifier->left[k] = fn->data.i; - } - else - { - fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_LEFT_VAL_NAME ); - if( !fn ) - { - sprintf( buf, "left node or left value must be specified. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - if( !CV_NODE_IS_REAL( fn->tag ) ) - { - sprintf( buf, "left value must be real number. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - /* left value */ - if( last_idx >= classifier->count + 1 ) - { - sprintf( buf, "Tree structure is broken: too many values. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - classifier->left[k] = -last_idx; - classifier->alpha[last_idx++] = (float) fn->data.f; - } - fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_RIGHT_NODE_NAME); - if( fn ) - { - if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= k - || fn->data.i >= tree_fn->data.seq->total ) - { - sprintf( buf, "right node must be valid node number. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - /* right node */ - classifier->right[k] = fn->data.i; - } - else - { - fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_RIGHT_VAL_NAME ); - if( !fn ) - { - sprintf( buf, "right node or right value must be specified. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - if( !CV_NODE_IS_REAL( fn->tag ) ) - { - sprintf( buf, "right value must be real number. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - /* right value */ - if( last_idx >= classifier->count + 1 ) - { - sprintf( buf, "Tree structure is broken: too many values. " - "(stage %d, tree %d, node %d)", i, j, k ); - CV_Error( CV_StsError, buf ); - } - classifier->right[k] = -last_idx; - classifier->alpha[last_idx++] = (float) fn->data.f; - } - - CV_NEXT_SEQ_ELEM( sizeof( *node_fn ), tree_reader ); - } /* for each node */ - if( last_idx != classifier->count + 1 ) - { - sprintf( buf, "Tree structure is broken: too few values. " - "(stage %d, tree %d)", i, j ); - CV_Error( CV_StsError, buf ); - } - - CV_NEXT_SEQ_ELEM( sizeof( *tree_fn ), trees_reader ); - } /* for each tree */ - - fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_STAGE_THRESHOLD_NAME); - if( !fn || !CV_NODE_IS_REAL( fn->tag ) ) - { - sprintf( buf, "stage threshold must be real number. (stage %d)", i ); - CV_Error( CV_StsError, buf ); - } - cascade->stage_classifier[i].threshold = (float) fn->data.f; - - parent = i - 1; - next = -1; - - fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_PARENT_NAME ); - if( !fn || !CV_NODE_IS_INT( fn->tag ) - || fn->data.i < -1 || fn->data.i >= cascade->count ) - { - sprintf( buf, "parent must be integer number. (stage %d)", i ); - CV_Error( CV_StsError, buf ); - } - parent = fn->data.i; - fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_NEXT_NAME ); - if( !fn || !CV_NODE_IS_INT( fn->tag ) - || fn->data.i < -1 || fn->data.i >= cascade->count ) - { - sprintf( buf, "next must be integer number. (stage %d)", i ); - CV_Error( CV_StsError, buf ); - } - next = fn->data.i; - - cascade->stage_classifier[i].parent = parent; - cascade->stage_classifier[i].next = next; - cascade->stage_classifier[i].child = -1; - - if( parent != -1 && cascade->stage_classifier[parent].child == -1 ) - { - cascade->stage_classifier[parent].child = i; - } - - CV_NEXT_SEQ_ELEM( sizeof( *stage_fn ), stages_reader ); - } /* for each stage */ - - return cascade; -} - -void -gpuWriteHaarClassifier( CvFileStorage *fs, const char *name, const void *struct_ptr, - CvAttrList attributes ) -{ - int i, j, k, l; - char buf[256]; - const CvHaarClassifierCascade *cascade = (const CvHaarClassifierCascade *) struct_ptr; - - /* TODO: parameters check */ - - cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_HAAR, attributes ); - - cvStartWriteStruct( fs, ICV_HAAR_SIZE_NAME, CV_NODE_SEQ | CV_NODE_FLOW ); - cvWriteInt( fs, NULL, cascade->orig_window_size.width ); - cvWriteInt( fs, NULL, cascade->orig_window_size.height ); - cvEndWriteStruct( fs ); /* size */ - - cvStartWriteStruct( fs, ICV_HAAR_STAGES_NAME, CV_NODE_SEQ ); - for( i = 0; i < cascade->count; ++i ) - { - cvStartWriteStruct( fs, NULL, CV_NODE_MAP ); - sprintf( buf, "stage %d", i ); - cvWriteComment( fs, buf, 1 ); - - cvStartWriteStruct( fs, ICV_HAAR_TREES_NAME, CV_NODE_SEQ ); - - for( j = 0; j < cascade->stage_classifier[i].count; ++j ) - { - CvHaarClassifier *tree = &cascade->stage_classifier[i].classifier[j]; - - cvStartWriteStruct( fs, NULL, CV_NODE_SEQ ); - sprintf( buf, "tree %d", j ); - cvWriteComment( fs, buf, 1 ); - - for( k = 0; k < tree->count; ++k ) - { - CvHaarFeature *feature = &tree->haar_feature[k]; - - cvStartWriteStruct( fs, NULL, CV_NODE_MAP ); - if( k ) - { - sprintf( buf, "node %d", k ); - } - else - { - sprintf( buf, "root node" ); - } - cvWriteComment( fs, buf, 1 ); - - cvStartWriteStruct( fs, ICV_HAAR_FEATURE_NAME, CV_NODE_MAP ); - - cvStartWriteStruct( fs, ICV_HAAR_RECTS_NAME, CV_NODE_SEQ ); - for( l = 0; l < CV_HAAR_FEATURE_MAX && feature->rect[l].r.width != 0; ++l ) - { - cvStartWriteStruct( fs, NULL, CV_NODE_SEQ | CV_NODE_FLOW ); - cvWriteInt( fs, NULL, feature->rect[l].r.x ); - cvWriteInt( fs, NULL, feature->rect[l].r.y ); - cvWriteInt( fs, NULL, feature->rect[l].r.width ); - cvWriteInt( fs, NULL, feature->rect[l].r.height ); - cvWriteReal( fs, NULL, feature->rect[l].weight ); - cvEndWriteStruct( fs ); /* rect */ - } - cvEndWriteStruct( fs ); /* rects */ - cvWriteInt( fs, ICV_HAAR_TILTED_NAME, feature->tilted ); - cvEndWriteStruct( fs ); /* feature */ - - cvWriteReal( fs, ICV_HAAR_THRESHOLD_NAME, tree->threshold[k]); - - if( tree->left[k] > 0 ) - { - cvWriteInt( fs, ICV_HAAR_LEFT_NODE_NAME, tree->left[k] ); - } - else - { - cvWriteReal( fs, ICV_HAAR_LEFT_VAL_NAME, - tree->alpha[-tree->left[k]] ); - } - - if( tree->right[k] > 0 ) - { - cvWriteInt( fs, ICV_HAAR_RIGHT_NODE_NAME, tree->right[k] ); - } - else - { - cvWriteReal( fs, ICV_HAAR_RIGHT_VAL_NAME, - tree->alpha[-tree->right[k]] ); - } - - cvEndWriteStruct( fs ); /* split */ - } - - cvEndWriteStruct( fs ); /* tree */ - } - - cvEndWriteStruct( fs ); /* trees */ - - cvWriteReal( fs, ICV_HAAR_STAGE_THRESHOLD_NAME, cascade->stage_classifier[i].threshold); - cvWriteInt( fs, ICV_HAAR_PARENT_NAME, cascade->stage_classifier[i].parent ); - cvWriteInt( fs, ICV_HAAR_NEXT_NAME, cascade->stage_classifier[i].next ); - - cvEndWriteStruct( fs ); /* stage */ - } /* for each stage */ - - cvEndWriteStruct( fs ); /* stages */ - cvEndWriteStruct( fs ); /* root */ -} - -void * -gpuCloneHaarClassifier( const void *struct_ptr ) -{ - CvHaarClassifierCascade *cascade = NULL; - - int i, j, k, n; - const CvHaarClassifierCascade *cascade_src = - (const CvHaarClassifierCascade *) struct_ptr; - - n = cascade_src->count; - cascade = gpuCreateHaarClassifierCascade(n); - cascade->orig_window_size = cascade_src->orig_window_size; - - for( i = 0; i < n; ++i ) - { - cascade->stage_classifier[i].parent = cascade_src->stage_classifier[i].parent; - cascade->stage_classifier[i].next = cascade_src->stage_classifier[i].next; - cascade->stage_classifier[i].child = cascade_src->stage_classifier[i].child; - cascade->stage_classifier[i].threshold = cascade_src->stage_classifier[i].threshold; - - cascade->stage_classifier[i].count = 0; - cascade->stage_classifier[i].classifier = - (CvHaarClassifier *) cvAlloc( cascade_src->stage_classifier[i].count - * sizeof( cascade->stage_classifier[i].classifier[0] ) ); - - cascade->stage_classifier[i].count = cascade_src->stage_classifier[i].count; - - for( j = 0; j < cascade->stage_classifier[i].count; ++j ) - cascade->stage_classifier[i].classifier[j].haar_feature = NULL; - - for( j = 0; j < cascade->stage_classifier[i].count; ++j ) - { - const CvHaarClassifier *classifier_src = - &cascade_src->stage_classifier[i].classifier[j]; - CvHaarClassifier *classifier = - &cascade->stage_classifier[i].classifier[j]; - - classifier->count = classifier_src->count; - classifier->haar_feature = (CvHaarFeature *) cvAlloc( - classifier->count * ( sizeof( *classifier->haar_feature ) + - sizeof( *classifier->threshold ) + - sizeof( *classifier->left ) + - sizeof( *classifier->right ) ) + - (classifier->count + 1) * sizeof( *classifier->alpha ) ); - classifier->threshold = (float *) (classifier->haar_feature + classifier->count); - classifier->left = (int *) (classifier->threshold + classifier->count); - classifier->right = (int *) (classifier->left + classifier->count); - classifier->alpha = (float *) (classifier->right + classifier->count); - for( k = 0; k < classifier->count; ++k ) - { - classifier->haar_feature[k] = classifier_src->haar_feature[k]; - classifier->threshold[k] = classifier_src->threshold[k]; - classifier->left[k] = classifier_src->left[k]; - classifier->right[k] = classifier_src->right[k]; - classifier->alpha[k] = classifier_src->alpha[k]; - } - classifier->alpha[classifier->count] = - classifier_src->alpha[classifier->count]; - } - } - - return cascade; -} +// static int gpuIsHaarClassifier( const void *struct_ptr ) +// { +// return CV_IS_HAAR_CLASSIFIER( struct_ptr ); +// } + +// static void * gpuReadHaarClassifier( CvFileStorage *fs, CvFileNode *node ) +// { +// CvHaarClassifierCascade *cascade = NULL; + +// char buf[256]; +// CvFileNode *seq_fn = NULL; /* sequence */ +// CvFileNode *fn = NULL; +// CvFileNode *stages_fn = NULL; +// CvSeqReader stages_reader; +// int n; +// int i, j, k, l; +// int parent, next; + +// stages_fn = cvGetFileNodeByName( fs, node, ICV_HAAR_STAGES_NAME ); +// if( !stages_fn || !CV_NODE_IS_SEQ( stages_fn->tag) ) +// CV_Error( CV_StsError, "Invalid stages node" ); + +// n = stages_fn->data.seq->total; +// cascade = gpuCreateHaarClassifierCascade(n); + +// /* read size */ +// seq_fn = cvGetFileNodeByName( fs, node, ICV_HAAR_SIZE_NAME ); +// if( !seq_fn || !CV_NODE_IS_SEQ( seq_fn->tag ) || seq_fn->data.seq->total != 2 ) +// CV_Error( CV_StsError, "size node is not a valid sequence." ); +// fn = (CvFileNode *) cvGetSeqElem( seq_fn->data.seq, 0 ); +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 ) +// CV_Error( CV_StsError, "Invalid size node: width must be positive integer" ); +// cascade->orig_window_size.width = fn->data.i; +// fn = (CvFileNode *) cvGetSeqElem( seq_fn->data.seq, 1 ); +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 ) +// CV_Error( CV_StsError, "Invalid size node: height must be positive integer" ); +// cascade->orig_window_size.height = fn->data.i; + +// cvStartReadSeq( stages_fn->data.seq, &stages_reader ); +// for( i = 0; i < n; ++i ) +// { +// CvFileNode *stage_fn; +// CvFileNode *trees_fn; +// CvSeqReader trees_reader; + +// stage_fn = (CvFileNode *) stages_reader.ptr; +// if( !CV_NODE_IS_MAP( stage_fn->tag ) ) +// { +// sprintf( buf, "Invalid stage %d", i ); +// CV_Error( CV_StsError, buf ); +// } + +// trees_fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_TREES_NAME ); +// if( !trees_fn || !CV_NODE_IS_SEQ( trees_fn->tag ) +// || trees_fn->data.seq->total <= 0 ) +// { +// sprintf( buf, "Trees node is not a valid sequence. (stage %d)", i ); +// CV_Error( CV_StsError, buf ); +// } + +// cascade->stage_classifier[i].classifier = +// (CvHaarClassifier *) cvAlloc( trees_fn->data.seq->total +// * sizeof( cascade->stage_classifier[i].classifier[0] ) ); +// for( j = 0; j < trees_fn->data.seq->total; ++j ) +// { +// cascade->stage_classifier[i].classifier[j].haar_feature = NULL; +// } +// cascade->stage_classifier[i].count = trees_fn->data.seq->total; + +// cvStartReadSeq( trees_fn->data.seq, &trees_reader ); +// for( j = 0; j < trees_fn->data.seq->total; ++j ) +// { +// CvFileNode *tree_fn; +// CvSeqReader tree_reader; +// CvHaarClassifier *classifier; +// int last_idx; + +// classifier = &cascade->stage_classifier[i].classifier[j]; +// tree_fn = (CvFileNode *) trees_reader.ptr; +// if( !CV_NODE_IS_SEQ( tree_fn->tag ) || tree_fn->data.seq->total <= 0 ) +// { +// sprintf( buf, "Tree node is not a valid sequence." +// " (stage %d, tree %d)", i, j ); +// CV_Error( CV_StsError, buf ); +// } + +// classifier->count = tree_fn->data.seq->total; +// classifier->haar_feature = (CvHaarFeature *) cvAlloc( +// classifier->count * ( sizeof( *classifier->haar_feature ) + +// sizeof( *classifier->threshold ) + +// sizeof( *classifier->left ) + +// sizeof( *classifier->right ) ) + +// (classifier->count + 1) * sizeof( *classifier->alpha ) ); +// classifier->threshold = (float *) (classifier->haar_feature + classifier->count); +// classifier->left = (int *) (classifier->threshold + classifier->count); +// classifier->right = (int *) (classifier->left + classifier->count); +// classifier->alpha = (float *) (classifier->right + classifier->count); + +// cvStartReadSeq( tree_fn->data.seq, &tree_reader ); +// for( k = 0, last_idx = 0; k < tree_fn->data.seq->total; ++k ) +// { +// CvFileNode *node_fn; +// CvFileNode *feature_fn; +// CvFileNode *rects_fn; +// CvSeqReader rects_reader; + +// node_fn = (CvFileNode *) tree_reader.ptr; +// if( !CV_NODE_IS_MAP( node_fn->tag ) ) +// { +// sprintf( buf, "Tree node %d is not a valid map. (stage %d, tree %d)", +// k, i, j ); +// CV_Error( CV_StsError, buf ); +// } +// feature_fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_FEATURE_NAME ); +// if( !feature_fn || !CV_NODE_IS_MAP( feature_fn->tag ) ) +// { +// sprintf( buf, "Feature node is not a valid map. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// rects_fn = cvGetFileNodeByName( fs, feature_fn, ICV_HAAR_RECTS_NAME ); +// if( !rects_fn || !CV_NODE_IS_SEQ( rects_fn->tag ) +// || rects_fn->data.seq->total < 1 +// || rects_fn->data.seq->total > CV_HAAR_FEATURE_MAX ) +// { +// sprintf( buf, "Rects node is not a valid sequence. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// cvStartReadSeq( rects_fn->data.seq, &rects_reader ); +// for( l = 0; l < rects_fn->data.seq->total; ++l ) +// { +// CvFileNode *rect_fn; +// CvRect r; + +// rect_fn = (CvFileNode *) rects_reader.ptr; +// if( !CV_NODE_IS_SEQ( rect_fn->tag ) || rect_fn->data.seq->total != 5 ) +// { +// sprintf( buf, "Rect %d is not a valid sequence. " +// "(stage %d, tree %d, node %d)", l, i, j, k ); +// CV_Error( CV_StsError, buf ); +// } + +// fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 0 ); +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i < 0 ) +// { +// sprintf( buf, "x coordinate must be non-negative integer. " +// "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); +// CV_Error( CV_StsError, buf ); +// } +// r.x = fn->data.i; +// fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 1 ); +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i < 0 ) +// { +// sprintf( buf, "y coordinate must be non-negative integer. " +// "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); +// CV_Error( CV_StsError, buf ); +// } +// r.y = fn->data.i; +// fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 2 ); +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 +// || r.x + fn->data.i > cascade->orig_window_size.width ) +// { +// sprintf( buf, "width must be positive integer and " +// "(x + width) must not exceed window width. " +// "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); +// CV_Error( CV_StsError, buf ); +// } +// r.width = fn->data.i; +// fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 3 ); +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= 0 +// || r.y + fn->data.i > cascade->orig_window_size.height ) +// { +// sprintf( buf, "height must be positive integer and " +// "(y + height) must not exceed window height. " +// "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); +// CV_Error( CV_StsError, buf ); +// } +// r.height = fn->data.i; +// fn = CV_SEQ_ELEM( rect_fn->data.seq, CvFileNode, 4 ); +// if( !CV_NODE_IS_REAL( fn->tag ) ) +// { +// sprintf( buf, "weight must be real number. " +// "(stage %d, tree %d, node %d, rect %d)", i, j, k, l ); +// CV_Error( CV_StsError, buf ); +// } + +// classifier->haar_feature[k].rect[l].weight = (float) fn->data.f; +// classifier->haar_feature[k].rect[l].r = r; + +// CV_NEXT_SEQ_ELEM( sizeof( *rect_fn ), rects_reader ); +// } /* for each rect */ +// for( l = rects_fn->data.seq->total; l < CV_HAAR_FEATURE_MAX; ++l ) +// { +// classifier->haar_feature[k].rect[l].weight = 0; +// classifier->haar_feature[k].rect[l].r = cvRect( 0, 0, 0, 0 ); +// } + +// fn = cvGetFileNodeByName( fs, feature_fn, ICV_HAAR_TILTED_NAME); +// if( !fn || !CV_NODE_IS_INT( fn->tag ) ) +// { +// sprintf( buf, "tilted must be 0 or 1. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// classifier->haar_feature[k].tilted = ( fn->data.i != 0 ); +// fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_THRESHOLD_NAME); +// if( !fn || !CV_NODE_IS_REAL( fn->tag ) ) +// { +// sprintf( buf, "threshold must be real number. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// classifier->threshold[k] = (float) fn->data.f; +// fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_LEFT_NODE_NAME); +// if( fn ) +// { +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= k +// || fn->data.i >= tree_fn->data.seq->total ) +// { +// sprintf( buf, "left node must be valid node number. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// /* left node */ +// classifier->left[k] = fn->data.i; +// } +// else +// { +// fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_LEFT_VAL_NAME ); +// if( !fn ) +// { +// sprintf( buf, "left node or left value must be specified. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// if( !CV_NODE_IS_REAL( fn->tag ) ) +// { +// sprintf( buf, "left value must be real number. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// /* left value */ +// if( last_idx >= classifier->count + 1 ) +// { +// sprintf( buf, "Tree structure is broken: too many values. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// classifier->left[k] = -last_idx; +// classifier->alpha[last_idx++] = (float) fn->data.f; +// } +// fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_RIGHT_NODE_NAME); +// if( fn ) +// { +// if( !CV_NODE_IS_INT( fn->tag ) || fn->data.i <= k +// || fn->data.i >= tree_fn->data.seq->total ) +// { +// sprintf( buf, "right node must be valid node number. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// /* right node */ +// classifier->right[k] = fn->data.i; +// } +// else +// { +// fn = cvGetFileNodeByName( fs, node_fn, ICV_HAAR_RIGHT_VAL_NAME ); +// if( !fn ) +// { +// sprintf( buf, "right node or right value must be specified. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// if( !CV_NODE_IS_REAL( fn->tag ) ) +// { +// sprintf( buf, "right value must be real number. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// /* right value */ +// if( last_idx >= classifier->count + 1 ) +// { +// sprintf( buf, "Tree structure is broken: too many values. " +// "(stage %d, tree %d, node %d)", i, j, k ); +// CV_Error( CV_StsError, buf ); +// } +// classifier->right[k] = -last_idx; +// classifier->alpha[last_idx++] = (float) fn->data.f; +// } + +// CV_NEXT_SEQ_ELEM( sizeof( *node_fn ), tree_reader ); +// } /* for each node */ +// if( last_idx != classifier->count + 1 ) +// { +// sprintf( buf, "Tree structure is broken: too few values. " +// "(stage %d, tree %d)", i, j ); +// CV_Error( CV_StsError, buf ); +// } + +// CV_NEXT_SEQ_ELEM( sizeof( *tree_fn ), trees_reader ); +// } /* for each tree */ + +// fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_STAGE_THRESHOLD_NAME); +// if( !fn || !CV_NODE_IS_REAL( fn->tag ) ) +// { +// sprintf( buf, "stage threshold must be real number. (stage %d)", i ); +// CV_Error( CV_StsError, buf ); +// } +// cascade->stage_classifier[i].threshold = (float) fn->data.f; + +// parent = i - 1; +// next = -1; + +// fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_PARENT_NAME ); +// if( !fn || !CV_NODE_IS_INT( fn->tag ) +// || fn->data.i < -1 || fn->data.i >= cascade->count ) +// { +// sprintf( buf, "parent must be integer number. (stage %d)", i ); +// CV_Error( CV_StsError, buf ); +// } +// parent = fn->data.i; +// fn = cvGetFileNodeByName( fs, stage_fn, ICV_HAAR_NEXT_NAME ); +// if( !fn || !CV_NODE_IS_INT( fn->tag ) +// || fn->data.i < -1 || fn->data.i >= cascade->count ) +// { +// sprintf( buf, "next must be integer number. (stage %d)", i ); +// CV_Error( CV_StsError, buf ); +// } +// next = fn->data.i; + +// cascade->stage_classifier[i].parent = parent; +// cascade->stage_classifier[i].next = next; +// cascade->stage_classifier[i].child = -1; + +// if( parent != -1 && cascade->stage_classifier[parent].child == -1 ) +// { +// cascade->stage_classifier[parent].child = i; +// } + +// CV_NEXT_SEQ_ELEM( sizeof( *stage_fn ), stages_reader ); +// } /* for each stage */ + +// return cascade; +// } + +// static void gpuWriteHaarClassifier( CvFileStorage *fs, const char *name, const void *struct_ptr, +// CvAttrList attributes ) +// { +// int i, j, k, l; +// char buf[256]; +// const CvHaarClassifierCascade *cascade = (const CvHaarClassifierCascade *) struct_ptr; + +// /* TODO: parameters check */ + +// cvStartWriteStruct( fs, name, CV_NODE_MAP, CV_TYPE_NAME_HAAR, attributes ); + +// cvStartWriteStruct( fs, ICV_HAAR_SIZE_NAME, CV_NODE_SEQ | CV_NODE_FLOW ); +// cvWriteInt( fs, NULL, cascade->orig_window_size.width ); +// cvWriteInt( fs, NULL, cascade->orig_window_size.height ); +// cvEndWriteStruct( fs ); /* size */ + +// cvStartWriteStruct( fs, ICV_HAAR_STAGES_NAME, CV_NODE_SEQ ); +// for( i = 0; i < cascade->count; ++i ) +// { +// cvStartWriteStruct( fs, NULL, CV_NODE_MAP ); +// sprintf( buf, "stage %d", i ); +// cvWriteComment( fs, buf, 1 ); + +// cvStartWriteStruct( fs, ICV_HAAR_TREES_NAME, CV_NODE_SEQ ); + +// for( j = 0; j < cascade->stage_classifier[i].count; ++j ) +// { +// CvHaarClassifier *tree = &cascade->stage_classifier[i].classifier[j]; + +// cvStartWriteStruct( fs, NULL, CV_NODE_SEQ ); +// sprintf( buf, "tree %d", j ); +// cvWriteComment( fs, buf, 1 ); + +// for( k = 0; k < tree->count; ++k ) +// { +// CvHaarFeature *feature = &tree->haar_feature[k]; + +// cvStartWriteStruct( fs, NULL, CV_NODE_MAP ); +// if( k ) +// { +// sprintf( buf, "node %d", k ); +// } +// else +// { +// sprintf( buf, "root node" ); +// } +// cvWriteComment( fs, buf, 1 ); + +// cvStartWriteStruct( fs, ICV_HAAR_FEATURE_NAME, CV_NODE_MAP ); + +// cvStartWriteStruct( fs, ICV_HAAR_RECTS_NAME, CV_NODE_SEQ ); +// for( l = 0; l < CV_HAAR_FEATURE_MAX && feature->rect[l].r.width != 0; ++l ) +// { +// cvStartWriteStruct( fs, NULL, CV_NODE_SEQ | CV_NODE_FLOW ); +// cvWriteInt( fs, NULL, feature->rect[l].r.x ); +// cvWriteInt( fs, NULL, feature->rect[l].r.y ); +// cvWriteInt( fs, NULL, feature->rect[l].r.width ); +// cvWriteInt( fs, NULL, feature->rect[l].r.height ); +// cvWriteReal( fs, NULL, feature->rect[l].weight ); +// cvEndWriteStruct( fs ); /* rect */ +// } +// cvEndWriteStruct( fs ); /* rects */ +// cvWriteInt( fs, ICV_HAAR_TILTED_NAME, feature->tilted ); +// cvEndWriteStruct( fs ); /* feature */ + +// cvWriteReal( fs, ICV_HAAR_THRESHOLD_NAME, tree->threshold[k]); + +// if( tree->left[k] > 0 ) +// { +// cvWriteInt( fs, ICV_HAAR_LEFT_NODE_NAME, tree->left[k] ); +// } +// else +// { +// cvWriteReal( fs, ICV_HAAR_LEFT_VAL_NAME, +// tree->alpha[-tree->left[k]] ); +// } + +// if( tree->right[k] > 0 ) +// { +// cvWriteInt( fs, ICV_HAAR_RIGHT_NODE_NAME, tree->right[k] ); +// } +// else +// { +// cvWriteReal( fs, ICV_HAAR_RIGHT_VAL_NAME, +// tree->alpha[-tree->right[k]] ); +// } + +// cvEndWriteStruct( fs ); /* split */ +// } + +// cvEndWriteStruct( fs ); /* tree */ +// } + +// cvEndWriteStruct( fs ); /* trees */ + +// cvWriteReal( fs, ICV_HAAR_STAGE_THRESHOLD_NAME, cascade->stage_classifier[i].threshold); +// cvWriteInt( fs, ICV_HAAR_PARENT_NAME, cascade->stage_classifier[i].parent ); +// cvWriteInt( fs, ICV_HAAR_NEXT_NAME, cascade->stage_classifier[i].next ); + +// cvEndWriteStruct( fs ); /* stage */ +// } /* for each stage */ + +// cvEndWriteStruct( fs ); /* stages */ +// cvEndWriteStruct( fs ); /* root */ +// } + +// static void * gpuCloneHaarClassifier( const void *struct_ptr ) +// { +// CvHaarClassifierCascade *cascade = NULL; + +// int i, j, k, n; +// const CvHaarClassifierCascade *cascade_src = +// (const CvHaarClassifierCascade *) struct_ptr; + +// n = cascade_src->count; +// cascade = gpuCreateHaarClassifierCascade(n); +// cascade->orig_window_size = cascade_src->orig_window_size; + +// for( i = 0; i < n; ++i ) +// { +// cascade->stage_classifier[i].parent = cascade_src->stage_classifier[i].parent; +// cascade->stage_classifier[i].next = cascade_src->stage_classifier[i].next; +// cascade->stage_classifier[i].child = cascade_src->stage_classifier[i].child; +// cascade->stage_classifier[i].threshold = cascade_src->stage_classifier[i].threshold; + +// cascade->stage_classifier[i].count = 0; +// cascade->stage_classifier[i].classifier = +// (CvHaarClassifier *) cvAlloc( cascade_src->stage_classifier[i].count +// * sizeof( cascade->stage_classifier[i].classifier[0] ) ); + +// cascade->stage_classifier[i].count = cascade_src->stage_classifier[i].count; + +// for( j = 0; j < cascade->stage_classifier[i].count; ++j ) +// cascade->stage_classifier[i].classifier[j].haar_feature = NULL; + +// for( j = 0; j < cascade->stage_classifier[i].count; ++j ) +// { +// const CvHaarClassifier *classifier_src = +// &cascade_src->stage_classifier[i].classifier[j]; +// CvHaarClassifier *classifier = +// &cascade->stage_classifier[i].classifier[j]; + +// classifier->count = classifier_src->count; +// classifier->haar_feature = (CvHaarFeature *) cvAlloc( +// classifier->count * ( sizeof( *classifier->haar_feature ) + +// sizeof( *classifier->threshold ) + +// sizeof( *classifier->left ) + +// sizeof( *classifier->right ) ) + +// (classifier->count + 1) * sizeof( *classifier->alpha ) ); +// classifier->threshold = (float *) (classifier->haar_feature + classifier->count); +// classifier->left = (int *) (classifier->threshold + classifier->count); +// classifier->right = (int *) (classifier->left + classifier->count); +// classifier->alpha = (float *) (classifier->right + classifier->count); +// for( k = 0; k < classifier->count; ++k ) +// { +// classifier->haar_feature[k] = classifier_src->haar_feature[k]; +// classifier->threshold[k] = classifier_src->threshold[k]; +// classifier->left[k] = classifier_src->left[k]; +// classifier->right[k] = classifier_src->right[k]; +// classifier->alpha[k] = classifier_src->alpha[k]; +// } +// classifier->alpha[classifier->count] = +// classifier_src->alpha[classifier->count]; +// } +// } + +// return cascade; +// } #if 0 CvType haar_type( CV_TYPE_NAME_HAAR, gpuIsHaarClassifier, @@ -2490,8 +2479,7 @@ size_t p_offset ) */ -CV_IMPL int -gpuRunHaarClassifierCascade( /*const CvHaarClassifierCascade *_cascade, +static int gpuRunHaarClassifierCascade( /*const CvHaarClassifierCascade *_cascade, CvPoint pt, int start_stage */) { /* diff --git a/modules/ocl/src/imgproc.cpp b/modules/ocl/src/imgproc.cpp index 27ce211..a93f86e 100644 --- a/modules/ocl/src/imgproc.cpp +++ b/modules/ocl/src/imgproc.cpp @@ -171,7 +171,7 @@ namespace cv typedef void (*gpuThresh_t)(const oclMat &src, oclMat &dst, double thresh, double maxVal, int type); - void threshold_8u(const oclMat &src, oclMat &dst, double thresh, double maxVal, int type) + static void threshold_8u(const oclMat &src, oclMat &dst, double thresh, double maxVal, int type) { CV_Assert( (src.cols == dst.cols) && (src.rows == dst.rows) ); Context *clCxt = src.clCxt; @@ -202,7 +202,7 @@ namespace cv openCLExecuteKernel(clCxt, &imgproc_threshold, kernelName, globalThreads, localThreads, args, src.oclchannels(), src.depth()); } - void threshold_32f(const oclMat &src, oclMat &dst, double thresh, double maxVal, int type) + static void threshold_32f(const oclMat &src, oclMat &dst, double thresh, double maxVal, int type) { CV_Assert( (src.cols == dst.cols) && (src.rows == dst.rows) ); Context *clCxt = src.clCxt; @@ -388,7 +388,7 @@ namespace cv //////////////////////////////////////////////////////////////////////////////////////////// // resize - void resize_gpu( const oclMat &src, oclMat &dst, double fx, double fy, int interpolation) + static void resize_gpu( const oclMat &src, oclMat &dst, double fx, double fy, int interpolation) { CV_Assert( (src.channels() == dst.channels()) ); Context *clCxt = src.clCxt; @@ -593,7 +593,7 @@ namespace cv int dstOffset = dst.offset / dst.elemSize(); int __bordertype[] = {cv::BORDER_CONSTANT, cv::BORDER_REPLICATE, BORDER_REFLECT, BORDER_WRAP, BORDER_REFLECT_101}; const char *borderstr[] = {"BORDER_CONSTANT", "BORDER_REPLICATE", "BORDER_REFLECT", "BORDER_WRAP", "BORDER_REFLECT_101"}; - int bordertype_index; + size_t bordertype_index; for(bordertype_index = 0; bordertype_index < sizeof(__bordertype) / sizeof(int); bordertype_index++) { if(__bordertype[bordertype_index] == bordertype) @@ -826,9 +826,9 @@ namespace cv { #define Sd(y,x) (Sd[y*3+x]) #define Dd(y,x) (Dd[y*3+x]) -#define det3(m) (m(0,0)*(m(1,1)*m(2,2) - m(1,2)*m(2,1)) - \ - m(0,1)*(m(1,0)*m(2,2) - m(1,2)*m(2,0)) + \ - m(0,2)*(m(1,0)*m(2,1) - m(1,1)*m(2,0))) +#define det3(m) (m(0,0)*(m(1,1)*m(2,2) - m(1,2)*m(2,1)) - \ + m(0,1)*(m(1,0)*m(2,2) - m(1,2)*m(2,0)) + \ + m(0,2)*(m(1,0)*m(2,1) - m(1,1)*m(2,0))) double *Sd = M; double *Dd = M; double d = det3(Sd); @@ -1018,12 +1018,19 @@ namespace cv int warpInd = (flags & WARP_INVERSE_MAP) >> 4; F coeffs[2][3]; - Mat coeffsMat(2, 3, CV_64F, (void *)coeffs); + + double coeffsM[2*3]; + Mat coeffsMat(2, 3, CV_64F, (void *)coeffsM); M.convertTo(coeffsMat, coeffsMat.type()); if(!warpInd) { - convert_coeffs((F *)(&coeffs[0][0])); + convert_coeffs(coeffsM); } + + for(int i = 0; i < 2; ++i) + for(int j = 0; j < 3; ++j) + coeffs[i][j] = coeffsM[i*3+j]; + warpAffine_gpu(src, dst, coeffs, interpolation); } @@ -1041,13 +1048,19 @@ namespace cv int warpInd = (flags & WARP_INVERSE_MAP) >> 4; double coeffs[3][3]; - Mat coeffsMat(3, 3, CV_64F, (void *)coeffs); + + double coeffsM[3*3]; + Mat coeffsMat(3, 3, CV_64F, (void *)coeffsM); M.convertTo(coeffsMat, coeffsMat.type()); if(!warpInd) { - invert((double *)(&coeffs[0][0])); + invert(coeffsM); } + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + coeffs[i][j] = coeffsM[i*3+j]; + warpPerspective_gpu(src, dst, coeffs, interpolation); } @@ -1144,7 +1157,7 @@ namespace cv } /////////////////////// corner ////////////////////////////// - void extractCovData(const oclMat &src, oclMat &Dx, oclMat &Dy, + static void extractCovData(const oclMat &src, oclMat &Dx, oclMat &Dy, int blockSize, int ksize, int borderType) { CV_Assert(src.type() == CV_8UC1 || src.type() == CV_32FC1); @@ -1174,7 +1187,7 @@ namespace cv CV_Assert(Dx.offset == 0 && Dy.offset == 0); } - void corner_ocl(const char *src_str, string kernelName, int block_size, float k, oclMat &Dx, oclMat &Dy, + static void corner_ocl(const char *src_str, string kernelName, int block_size, float k, oclMat &Dx, oclMat &Dy, oclMat &dst, int border_type) { char borderType[30]; @@ -1258,7 +1271,7 @@ namespace cv corner_ocl(imgproc_calcMinEigenVal, "calcMinEigenVal", blockSize, 0, Dx, Dy, dst, borderType); } /////////////////////////////////// MeanShiftfiltering /////////////////////////////////////////////// - void meanShiftFiltering_gpu(const oclMat &src, oclMat dst, int sp, int sr, int maxIter, float eps) + static void meanShiftFiltering_gpu(const oclMat &src, oclMat dst, int sp, int sr, int maxIter, float eps) { CV_Assert( (src.cols == dst.cols) && (src.rows == dst.rows) ); CV_Assert( !(dst.step & 0x3) ); @@ -1321,7 +1334,7 @@ namespace cv } - void meanShiftProc_gpu(const oclMat &src, oclMat dstr, oclMat dstsp, int sp, int sr, int maxIter, float eps) + static void meanShiftProc_gpu(const oclMat &src, oclMat dstr, oclMat dstsp, int sp, int sr, int maxIter, float eps) { //sanity checks CV_Assert( (src.cols == dstr.cols) && (src.rows == dstr.rows) && @@ -1398,7 +1411,7 @@ namespace cv const int HISTOGRAM256_BIN_COUNT = 256; } ///////////////////////////////calcHist///////////////////////////////////////////////////////////////// - void calc_sub_hist(const oclMat &mat_src, const oclMat &mat_sub_hist) + static void calc_sub_hist(const oclMat &mat_src, const oclMat &mat_sub_hist) { using namespace histograms; @@ -1477,7 +1490,7 @@ namespace cv openCLExecuteKernel(clCxt, &imgproc_histogram, kernelName, globalThreads, localThreads, args, -1, depth); } } - void merge_sub_hist(const oclMat &sub_hist, oclMat &mat_hist) + static void merge_sub_hist(const oclMat &sub_hist, oclMat &mat_hist) { using namespace histograms; @@ -1535,7 +1548,6 @@ namespace cv { int cn = src.channels(); int i, j, maxk, radius; - Size size = src.size(); CV_Assert( (src.channels() == 1 || src.channels() == 3) && src.type() == dst.type() && src.size() == dst.size() && @@ -1632,7 +1644,7 @@ inline int divUp(int total, int grain) { return (total + grain - 1) / grain; } -void convolve_run(const oclMat &src, const oclMat &temp1, oclMat &dst, string kernelName, const char **kernelString) +static void convolve_run(const oclMat &src, const oclMat &temp1, oclMat &dst, string kernelName, const char **kernelString) { CV_Assert(src.depth() == CV_32FC1); CV_Assert(temp1.depth() == CV_32F); diff --git a/modules/ocl/src/initialization.cpp b/modules/ocl/src/initialization.cpp index a8814c7..63916d9 100644 --- a/modules/ocl/src/initialization.cpp +++ b/modules/ocl/src/initialization.cpp @@ -237,23 +237,13 @@ namespace cv int getDevice(std::vector &oclinfo, int devicetype) { - cl_device_type _devicetype; switch(devicetype) { case CVCL_DEVICE_TYPE_DEFAULT: - _devicetype = CL_DEVICE_TYPE_DEFAULT; - break; case CVCL_DEVICE_TYPE_CPU: - _devicetype = CL_DEVICE_TYPE_CPU; - break; case CVCL_DEVICE_TYPE_GPU: - _devicetype = CL_DEVICE_TYPE_GPU; - break; case CVCL_DEVICE_TYPE_ACCELERATOR: - _devicetype = CL_DEVICE_TYPE_ACCELERATOR; - break; case CVCL_DEVICE_TYPE_ALL: - _devicetype = CL_DEVICE_TYPE_ALL; break; default: CV_Error(CV_GpuApiCallError, "Unkown device type"); @@ -336,7 +326,7 @@ namespace cv size_t extends_size; openCLSafeCall(clGetDeviceInfo(oclinfo.impl->devices[devnum], CL_DEVICE_EXTENSIONS, EXT_LEN, (void *)extends_set, &extends_size)); - CV_Assert(extends_size < EXT_LEN); + CV_Assert(extends_size < (size_t)EXT_LEN); extends_set[EXT_LEN - 1] = 0; memset(oclinfo.impl->extra_options, 0, 512); oclinfo.impl->double_support = 0; @@ -592,7 +582,7 @@ namespace cv size_t binarySize = ftell(fp); fseek(fp, 0, SEEK_SET); char *binary = new char[binarySize]; - fread(binary, binarySize, 1, fp); + CV_Assert(1 == fread(binary, binarySize, 1, fp)); fclose(fp); cl_int status = 0; program = clCreateProgramWithBinary(clCxt->impl->clContext, diff --git a/modules/ocl/src/interpolate_frames.cpp b/modules/ocl/src/interpolate_frames.cpp index e4f16e0..d6b4020 100644 --- a/modules/ocl/src/interpolate_frames.cpp +++ b/modules/ocl/src/interpolate_frames.cpp @@ -282,7 +282,7 @@ void interpolate::bindImgTex(const oclMat &img, cl_mem &texture) openCLFree(texture); } -#if CL_VERSION_1_2 +#ifdef CL_VERSION_1_2 cl_image_desc desc; desc.image_type = CL_MEM_OBJECT_IMAGE2D; desc.image_width = img.step / img.elemSize(); diff --git a/modules/ocl/src/match_template.cpp b/modules/ocl/src/match_template.cpp index b2c08af..8a27056 100644 --- a/modules/ocl/src/match_template.cpp +++ b/modules/ocl/src/match_template.cpp @@ -99,7 +99,7 @@ namespace cv // Evaluates optimal template's area threshold. If // template's area is less than the threshold, we use naive match // template version, otherwise FFT-based (if available) - int getTemplateThreshold(int method, int depth) + static int getTemplateThreshold(int method, int depth) { switch (method) { diff --git a/modules/ocl/src/matrix_operations.cpp b/modules/ocl/src/matrix_operations.cpp index b2baed8..b2b8b5f 100644 --- a/modules/ocl/src/matrix_operations.cpp +++ b/modules/ocl/src/matrix_operations.cpp @@ -126,7 +126,7 @@ namespace cv //////////////////////////////////////////////////////////////////////// // convert_C3C4 -void convert_C3C4(const cl_mem &src, oclMat &dst) +static void convert_C3C4(const cl_mem &src, oclMat &dst) { int dstStep_in_pixel = dst.step1() / dst.oclchannels(); int pixel_end = dst.wholecols * dst.wholerows - 1; @@ -174,7 +174,7 @@ void convert_C3C4(const cl_mem &src, oclMat &dst) } //////////////////////////////////////////////////////////////////////// // convert_C4C3 -void convert_C4C3(const oclMat &src, cl_mem &dst) +static void convert_C4C3(const oclMat &src, cl_mem &dst) { int srcStep_in_pixel = src.step1() / src.oclchannels(); int pixel_end = src.wholecols * src.wholerows - 1; @@ -336,7 +336,7 @@ inline int divUp(int total, int grain) /////////////////////////////////////////////////////////////////////////// ////////////////////////////////// CopyTo ///////////////////////////////// /////////////////////////////////////////////////////////////////////////// -void copy_to_with_mask(const oclMat &src, oclMat &dst, const oclMat &mask, string kernelName) +static void copy_to_with_mask(const oclMat &src, oclMat &dst, const oclMat &mask, string kernelName) { CV_DbgAssert( dst.rows == mask.rows && dst.cols == mask.cols && src.rows == dst.rows && src.cols == dst.cols @@ -401,7 +401,7 @@ void cv::ocl::oclMat::copyTo( oclMat &mat, const oclMat &mask) const /////////////////////////////////////////////////////////////////////////// //////////////////////////////// ConvertTo //////////////////////////////// /////////////////////////////////////////////////////////////////////////// -void convert_run(const oclMat &src, oclMat &dst, double alpha, double beta) +static void convert_run(const oclMat &src, oclMat &dst, double alpha, double beta) { string kernelName = "convert_to_S"; stringstream idxStr; @@ -472,7 +472,7 @@ oclMat &cv::ocl::oclMat::operator = (const Scalar &s) setTo(s); return *this; } -void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, string kernelName) +static void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, string kernelName) { vector > args; @@ -642,7 +642,7 @@ void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, string kern default: CV_Error(CV_StsUnsupportedFormat, "unknown depth"); } -#if CL_VERSION_1_2 +#ifdef CL_VERSION_1_2 if(dst.offset == 0 && dst.cols == dst.wholecols) { clEnqueueFillBuffer(dst.clCxt->impl->clCmdQueue, (cl_mem)dst.data, args[0].second, args[0].first, 0, dst.step * dst.rows, 0, NULL, NULL); @@ -668,7 +668,7 @@ void set_to_withoutmask_run(const oclMat &dst, const Scalar &scalar, string kern #endif } -void set_to_withmask_run(const oclMat &dst, const Scalar &scalar, const oclMat &mask, string kernelName) +static void set_to_withmask_run(const oclMat &dst, const Scalar &scalar, const oclMat &mask, string kernelName) { CV_DbgAssert( dst.rows == mask.rows && dst.cols == mask.cols); vector > args; diff --git a/modules/ocl/src/mcwutil.cpp b/modules/ocl/src/mcwutil.cpp index b4dafa5..b6c99e1 100644 --- a/modules/ocl/src/mcwutil.cpp +++ b/modules/ocl/src/mcwutil.cpp @@ -62,7 +62,7 @@ namespace cv } // provide additional methods for the user to interact with the command queue after a task is fired - void openCLExecuteKernel_2(Context *clCxt , const char **source, string kernelName, size_t globalThreads[3], + static void openCLExecuteKernel_2(Context *clCxt , const char **source, string kernelName, size_t globalThreads[3], size_t localThreads[3], vector< pair > &args, int channels, int depth, char *build_options, FLUSH_MODE finish_mode) { diff --git a/modules/ocl/src/precomp.hpp b/modules/ocl/src/precomp.hpp index 11257fd..317da59 100644 --- a/modules/ocl/src/precomp.hpp +++ b/modules/ocl/src/precomp.hpp @@ -46,7 +46,7 @@ #ifndef __OPENCV_PRECOMP_H__ #define __OPENCV_PRECOMP_H__ -#if _MSC_VER >= 1200 +#if defined _MSC_VER && _MSC_VER >= 1200 #pragma warning( disable: 4267 4324 4244 4251 4710 4711 4514 4996 ) #endif diff --git a/modules/ocl/src/pyrdown.cpp b/modules/ocl/src/pyrdown.cpp index c05a7ae..96be69b 100644 --- a/modules/ocl/src/pyrdown.cpp +++ b/modules/ocl/src/pyrdown.cpp @@ -66,7 +66,7 @@ namespace cv ////////////////////////////////////////////////////////////////////////////// /////////////////////// add subtract multiply divide ///////////////////////// ////////////////////////////////////////////////////////////////////////////// -void pyrdown_run(const oclMat &src, const oclMat &dst) +static void pyrdown_run(const oclMat &src, const oclMat &dst) { CV_Assert(src.type() == dst.type()); diff --git a/modules/ocl/src/pyrlk.cpp b/modules/ocl/src/pyrlk.cpp index 7165a8c..0e87106 100644 --- a/modules/ocl/src/pyrlk.cpp +++ b/modules/ocl/src/pyrlk.cpp @@ -115,7 +115,7 @@ inline int divUp(int total, int grain) /////////////////////////////////////////////////////////////////////////// //////////////////////////////// ConvertTo //////////////////////////////// /////////////////////////////////////////////////////////////////////////// -void convert_run_cus(const oclMat &src, oclMat &dst, double alpha, double beta) +static void convert_run_cus(const oclMat &src, oclMat &dst, double alpha, double beta) { string kernelName = "convert_to_S"; stringstream idxStr; @@ -186,7 +186,7 @@ void convertTo( const oclMat &src, oclMat &dst, int rtype, double alpha, double // setTo(s); // return *this; //} -void set_to_withoutmask_run_cus(const oclMat &dst, const Scalar &scalar, string kernelName) +static void set_to_withoutmask_run_cus(const oclMat &dst, const Scalar &scalar, string kernelName) { vector > args; @@ -356,7 +356,7 @@ void set_to_withoutmask_run_cus(const oclMat &dst, const Scalar &scalar, string default: CV_Error(CV_StsUnsupportedFormat, "unknown depth"); } -#if CL_VERSION_1_2 +#ifdef CL_VERSION_1_2 if(dst.offset == 0 && dst.cols == dst.wholecols) { clEnqueueFillBuffer(dst.clCxt->impl->clCmdQueue, (cl_mem)dst.data, args[0].second, args[0].first, 0, dst.step * dst.rows, 0, NULL, NULL); @@ -382,7 +382,7 @@ void set_to_withoutmask_run_cus(const oclMat &dst, const Scalar &scalar, string #endif } -oclMat &setTo(oclMat &src, const Scalar &scalar) +static oclMat &setTo(oclMat &src, const Scalar &scalar) { CV_Assert( src.depth() >= 0 && src.depth() <= 6 ); CV_DbgAssert( !src.empty()); @@ -402,48 +402,48 @@ oclMat &setTo(oclMat &src, const Scalar &scalar) /////////////////////////////////////////////////////////////////////////// ////////////////////////////////// CopyTo ///////////////////////////////// /////////////////////////////////////////////////////////////////////////// -void copy_to_with_mask_cus(const oclMat &src, oclMat &dst, const oclMat &mask, string kernelName) -{ - CV_DbgAssert( dst.rows == mask.rows && dst.cols == mask.cols && - src.rows == dst.rows && src.cols == dst.cols - && mask.type() == CV_8UC1); - - vector > args; - - std::string string_types[4][7] = {{"uchar", "char", "ushort", "short", "int", "float", "double"}, - {"uchar2", "char2", "ushort2", "short2", "int2", "float2", "double2"}, - {"uchar3", "char3", "ushort3", "short3", "int3", "float3", "double3"}, - {"uchar4", "char4", "ushort4", "short4", "int4", "float4", "double4"} - }; - char compile_option[32]; - sprintf(compile_option, "-D GENTYPE=%s", string_types[dst.oclchannels() - 1][dst.depth()].c_str()); - size_t localThreads[3] = {16, 16, 1}; - size_t globalThreads[3]; - - globalThreads[0] = divUp(dst.cols, localThreads[0]) * localThreads[0]; - globalThreads[1] = divUp(dst.rows, localThreads[1]) * localThreads[1]; - globalThreads[2] = 1; - - int dststep_in_pixel = dst.step / dst.elemSize(), dstoffset_in_pixel = dst.offset / dst.elemSize(); - int srcstep_in_pixel = src.step / src.elemSize(), srcoffset_in_pixel = src.offset / src.elemSize(); - - args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data )); - args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst.data )); - args.push_back( make_pair( sizeof(cl_mem) , (void *)&mask.data )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&src.cols )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&srcstep_in_pixel )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&srcoffset_in_pixel )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&dststep_in_pixel )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&dstoffset_in_pixel )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&mask.step )); - args.push_back( make_pair( sizeof(cl_int) , (void *)&mask.offset )); - - openCLExecuteKernel2(dst.clCxt , &operator_copyToM, kernelName, globalThreads, - localThreads, args, -1, -1, compile_option, CLFLUSH); -} - -void copyTo(const oclMat &src, oclMat &m ) +// static void copy_to_with_mask_cus(const oclMat &src, oclMat &dst, const oclMat &mask, string kernelName) +// { +// CV_DbgAssert( dst.rows == mask.rows && dst.cols == mask.cols && +// src.rows == dst.rows && src.cols == dst.cols +// && mask.type() == CV_8UC1); + +// vector > args; + +// std::string string_types[4][7] = {{"uchar", "char", "ushort", "short", "int", "float", "double"}, +// {"uchar2", "char2", "ushort2", "short2", "int2", "float2", "double2"}, +// {"uchar3", "char3", "ushort3", "short3", "int3", "float3", "double3"}, +// {"uchar4", "char4", "ushort4", "short4", "int4", "float4", "double4"} +// }; +// char compile_option[32]; +// sprintf(compile_option, "-D GENTYPE=%s", string_types[dst.oclchannels() - 1][dst.depth()].c_str()); +// size_t localThreads[3] = {16, 16, 1}; +// size_t globalThreads[3]; + +// globalThreads[0] = divUp(dst.cols, localThreads[0]) * localThreads[0]; +// globalThreads[1] = divUp(dst.rows, localThreads[1]) * localThreads[1]; +// globalThreads[2] = 1; + +// int dststep_in_pixel = dst.step / dst.elemSize(), dstoffset_in_pixel = dst.offset / dst.elemSize(); +// int srcstep_in_pixel = src.step / src.elemSize(), srcoffset_in_pixel = src.offset / src.elemSize(); + +// args.push_back( make_pair( sizeof(cl_mem) , (void *)&src.data )); +// args.push_back( make_pair( sizeof(cl_mem) , (void *)&dst.data )); +// args.push_back( make_pair( sizeof(cl_mem) , (void *)&mask.data )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&src.cols )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&src.rows )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&srcstep_in_pixel )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&srcoffset_in_pixel )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&dststep_in_pixel )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&dstoffset_in_pixel )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&mask.step )); +// args.push_back( make_pair( sizeof(cl_int) , (void *)&mask.offset )); + +// openCLExecuteKernel2(dst.clCxt , &operator_copyToM, kernelName, globalThreads, +// localThreads, args, -1, -1, compile_option, CLFLUSH); +// } + +static void copyTo(const oclMat &src, oclMat &m ) { CV_DbgAssert(!src.empty()); m.create(src.size(), src.type()); @@ -451,20 +451,20 @@ void copyTo(const oclMat &src, oclMat &m ) src.data, src.step, src.cols * src.elemSize(), src.rows, src.offset); } -void copyTo(const oclMat &src, oclMat &mat, const oclMat &mask) -{ - if (mask.empty()) - { - copyTo(src, mat); - } - else - { - mat.create(src.size(), src.type()); - copy_to_with_mask_cus(src, mat, mask, "copy_to_with_mask"); - } -} - -void arithmetic_run(const oclMat &src1, oclMat &dst, string kernelName, const char **kernelString, void *_scalar) +// static void copyTo(const oclMat &src, oclMat &mat, const oclMat &mask) +// { +// if (mask.empty()) +// { +// copyTo(src, mat); +// } +// else +// { +// mat.create(src.size(), src.type()); +// copy_to_with_mask_cus(src, mat, mask, "copy_to_with_mask"); +// } +// } + +static void arithmetic_run(const oclMat &src1, oclMat &dst, string kernelName, const char **kernelString, void *_scalar) { if(src1.clCxt -> impl -> double_support == 0 && src1.type() == CV_64F) { @@ -529,12 +529,12 @@ void arithmetic_run(const oclMat &src1, oclMat &dst, string kernelName, const ch openCLExecuteKernel2(clCxt, kernelString, kernelName, globalThreads, localThreads, args, -1, src1.depth(), CLFLUSH); } -void multiply_cus(const oclMat &src1, oclMat &dst, float scalar) +static void multiply_cus(const oclMat &src1, oclMat &dst, float scalar) { arithmetic_run(src1, dst, "arithm_muls", &arithm_mul, (void *)(&scalar)); } -void pyrdown_run_cus(const oclMat &src, const oclMat &dst) +static void pyrdown_run_cus(const oclMat &src, const oclMat &dst) { CV_Assert(src.type() == dst.type()); @@ -559,7 +559,7 @@ void pyrdown_run_cus(const oclMat &src, const oclMat &dst) openCLExecuteKernel2(clCxt, &pyr_down, kernelName, globalThreads, localThreads, args, src.oclchannels(), src.depth(), CLFLUSH); } -void pyrDown_cus(const oclMat &src, oclMat &dst) +static void pyrDown_cus(const oclMat &src, oclMat &dst) { CV_Assert(src.depth() <= CV_32F && src.channels() <= 4); @@ -673,7 +673,7 @@ void pyrDown_cus(const oclMat &src, oclMat &dst) // //} //} -cl_mem bindTexture(const oclMat &mat, int depth, int channels) +static cl_mem bindTexture(const oclMat &mat, int depth, int channels) { cl_mem texture; cl_image_format format; @@ -698,7 +698,7 @@ cl_mem bindTexture(const oclMat &mat, int depth, int channels) { format.image_channel_order = CL_RGBA; } -#if CL_VERSION_1_2 +#ifdef CL_VERSION_1_2 cl_image_desc desc; desc.image_type = CL_MEM_OBJECT_IMAGE2D; desc.image_width = mat.step / mat.elemSize(); @@ -730,12 +730,12 @@ cl_mem bindTexture(const oclMat &mat, int depth, int channels) return texture; } -void releaseTexture(cl_mem texture) +static void releaseTexture(cl_mem texture) { openCLFree(texture); } -void lkSparse_run(oclMat &I, oclMat &J, +static void lkSparse_run(oclMat &I, oclMat &J, const oclMat &prevPts, oclMat &nextPts, oclMat &status, oclMat& err, bool /*GET_MIN_EIGENVALS*/, int ptcount, int level, /*dim3 block, */dim3 patch, Size winSize, int iters) { @@ -915,7 +915,7 @@ void cv::ocl::PyrLKOpticalFlow::sparse(const oclMat &prevImg, const oclMat &next delete err; } -void lkDense_run(oclMat &I, oclMat &J, oclMat &u, oclMat &v, +static void lkDense_run(oclMat &I, oclMat &J, oclMat &u, oclMat &v, oclMat &prevU, oclMat &prevV, oclMat *err, Size winSize, int iters) { Context *clCxt = I.clCxt; diff --git a/modules/ocl/src/split_merge.cpp b/modules/ocl/src/split_merge.cpp index e15b06e..b071ff8 100644 --- a/modules/ocl/src/split_merge.cpp +++ b/modules/ocl/src/split_merge.cpp @@ -111,52 +111,52 @@ namespace cv //////////////////////////////////////////////////////////////////////////// ////////////////////merge////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - void merge_vector_run_no_roi(const oclMat *mat_src, size_t n, oclMat &mat_dst) - { - Context *clCxt = mat_dst.clCxt; - int channels = mat_dst.oclchannels(); - int depth = mat_dst.depth(); - - string kernelName = "merge_vector"; - - int indexes[4][7] = {{0, 0, 0, 0, 0, 0, 0}, - {4, 4, 2, 2, 1, 1, 1}, - {4, 4, 2, 2 , 1, 1, 1}, - {4, 4, 2, 2, 1, 1, 1} - }; - - size_t index = indexes[channels - 1][mat_dst.depth()]; - int cols = divUp(mat_dst.cols, index); - size_t localThreads[3] = { 64, 4, 1 }; - size_t globalThreads[3] = { divUp(cols, localThreads[0]) *localThreads[0], - divUp(mat_dst.rows, localThreads[1]) *localThreads[1], - 1 - }; - - vector > args; - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst.rows)); - args.push_back( make_pair( sizeof(cl_int), (void *)&cols)); - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst.data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst.step)); - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[0].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[0].step)); - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[1].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[1].step)); - if(n >= 3) - { - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[2].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[2].step)); - } - if(n >= 4) - { - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[3].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[3].step)); - } - - openCLExecuteKernel(clCxt, &merge_mat, kernelName, globalThreads, localThreads, args, channels, depth); - } - - void merge_vector_run(const oclMat *mat_src, size_t n, oclMat &mat_dst) + // static void merge_vector_run_no_roi(const oclMat *mat_src, size_t n, oclMat &mat_dst) + // { + // Context *clCxt = mat_dst.clCxt; + // int channels = mat_dst.oclchannels(); + // int depth = mat_dst.depth(); + + // string kernelName = "merge_vector"; + + // int indexes[4][7] = {{0, 0, 0, 0, 0, 0, 0}, + // {4, 4, 2, 2, 1, 1, 1}, + // {4, 4, 2, 2 , 1, 1, 1}, + // {4, 4, 2, 2, 1, 1, 1} + // }; + + // size_t index = indexes[channels - 1][mat_dst.depth()]; + // int cols = divUp(mat_dst.cols, index); + // size_t localThreads[3] = { 64, 4, 1 }; + // size_t globalThreads[3] = { divUp(cols, localThreads[0]) *localThreads[0], + // divUp(mat_dst.rows, localThreads[1]) *localThreads[1], + // 1 + // }; + + // vector > args; + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst.rows)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&cols)); + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst.data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst.step)); + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[0].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[0].step)); + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[1].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[1].step)); + // if(n >= 3) + // { + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[2].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[2].step)); + // } + // if(n >= 4) + // { + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src[3].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src[3].step)); + // } + + // openCLExecuteKernel(clCxt, &merge_mat, kernelName, globalThreads, localThreads, args, channels, depth); + // } + + static void merge_vector_run(const oclMat *mat_src, size_t n, oclMat &mat_dst) { if(mat_dst.clCxt -> impl -> double_support == 0 && mat_dst.type() == CV_64F) { @@ -228,7 +228,7 @@ namespace cv openCLExecuteKernel(clCxt, &merge_mat, kernelName, globalThreads, localThreads, args, channels, depth); } - void merge(const oclMat *mat_src, size_t n, oclMat &mat_dst) + static void merge(const oclMat *mat_src, size_t n, oclMat &mat_dst) { CV_Assert(mat_src); CV_Assert(n > 0); @@ -260,51 +260,51 @@ namespace cv //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////split///////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////// - void split_vector_run_no_roi(const oclMat &mat_src, oclMat *mat_dst) - { - Context *clCxt = mat_src.clCxt; - int channels = mat_src.oclchannels(); - int depth = mat_src.depth(); - - string kernelName = "split_vector"; - - int indexes[4][7] = {{0, 0, 0, 0, 0, 0, 0}, - {8, 8, 8, 8, 4, 4, 2}, - {8, 8, 8, 8 , 4, 4, 4}, - {4, 4, 2, 2, 1, 1, 1} - }; - - size_t index = indexes[channels - 1][mat_dst[0].depth()]; - int cols = divUp(mat_src.cols, index); - size_t localThreads[3] = { 64, 4, 1 }; - size_t globalThreads[3] = { divUp(cols, localThreads[0]) *localThreads[0], - divUp(mat_src.rows, localThreads[1]) *localThreads[1], - 1 - }; - - vector > args; - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src.data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src.step)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src.rows)); - args.push_back( make_pair( sizeof(cl_int), (void *)&cols)); - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[0].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[0].step)); - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[1].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[1].step)); - if(channels >= 3) - { - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[2].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[2].step)); - } - if(channels >= 4) - { - args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[3].data)); - args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[3].step)); - } - - openCLExecuteKernel(clCxt, &split_mat, kernelName, globalThreads, localThreads, args, channels, depth); - } - void split_vector_run(const oclMat &mat_src, oclMat *mat_dst) + // static void split_vector_run_no_roi(const oclMat &mat_src, oclMat *mat_dst) + // { + // Context *clCxt = mat_src.clCxt; + // int channels = mat_src.oclchannels(); + // int depth = mat_src.depth(); + + // string kernelName = "split_vector"; + + // int indexes[4][7] = {{0, 0, 0, 0, 0, 0, 0}, + // {8, 8, 8, 8, 4, 4, 2}, + // {8, 8, 8, 8 , 4, 4, 4}, + // {4, 4, 2, 2, 1, 1, 1} + // }; + + // size_t index = indexes[channels - 1][mat_dst[0].depth()]; + // int cols = divUp(mat_src.cols, index); + // size_t localThreads[3] = { 64, 4, 1 }; + // size_t globalThreads[3] = { divUp(cols, localThreads[0]) *localThreads[0], + // divUp(mat_src.rows, localThreads[1]) *localThreads[1], + // 1 + // }; + + // vector > args; + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_src.data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src.step)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_src.rows)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&cols)); + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[0].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[0].step)); + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[1].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[1].step)); + // if(channels >= 3) + // { + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[2].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[2].step)); + // } + // if(channels >= 4) + // { + // args.push_back( make_pair( sizeof(cl_mem), (void *)&mat_dst[3].data)); + // args.push_back( make_pair( sizeof(cl_int), (void *)&mat_dst[3].step)); + // } + + // openCLExecuteKernel(clCxt, &split_mat, kernelName, globalThreads, localThreads, args, channels, depth); + // } + static void split_vector_run(const oclMat &mat_src, oclMat *mat_dst) { if(mat_src.clCxt -> impl -> double_support == 0 && mat_src.type() == CV_64F) @@ -374,7 +374,7 @@ namespace cv openCLExecuteKernel(clCxt, &split_mat, kernelName, globalThreads, localThreads, args, channels, depth); } - void split(const oclMat &mat_src, oclMat *mat_dst) + static void split(const oclMat &mat_src, oclMat *mat_dst) { CV_Assert(mat_dst); diff --git a/modules/ocl/src/surf.cpp b/modules/ocl/src/surf.cpp index f42c5ae..71a7aac 100644 --- a/modules/ocl/src/surf.cpp +++ b/modules/ocl/src/surf.cpp @@ -536,7 +536,7 @@ void SURF_OCL_Invoker::bindImgTex(const oclMat &img, cl_mem &texture) openCLFree(texture); } -#if CL_VERSION_1_2 +#ifdef CL_VERSION_1_2 cl_image_desc desc; desc.image_type = CL_MEM_OBJECT_IMAGE2D; desc.image_width = img.step / img.elemSize(); diff --git a/modules/ocl/test/precomp.hpp b/modules/ocl/test/precomp.hpp index 3f6514f..c630871 100644 --- a/modules/ocl/test/precomp.hpp +++ b/modules/ocl/test/precomp.hpp @@ -38,6 +38,15 @@ // the use of this software, even if advised of the possibility of such damage. // //M*/ + +#ifdef __GNUC__ +# pragma GCC diagnostic ignored "-Wmissing-declarations" +# if defined __clang__ || defined __APPLE__ +# pragma GCC diagnostic ignored "-Wmissing-prototypes" +# pragma GCC diagnostic ignored "-Wextra" +# endif +#endif + #ifndef __OPENCV_TEST_PRECOMP_HPP__ #define __OPENCV_TEST_PRECOMP_HPP__ diff --git a/modules/ocl/test/test_arithm.cpp b/modules/ocl/test/test_arithm.cpp index 82fcb65..f643864 100644 --- a/modules/ocl/test/test_arithm.cpp +++ b/modules/ocl/test/test_arithm.cpp @@ -1449,8 +1449,8 @@ TEST_P(MagnitudeSqr, Mat) for(int j = 0; j < LOOP_TIMES; j++) { // random_roi(); - int64 start, end; - start = cv::getTickCount(); + // int64 start, end; + // start = cv::getTickCount(); for(int i = 0; i < mat1.rows; ++i) for(int j = 0; j < mat1.cols; ++j) { @@ -1465,7 +1465,7 @@ TEST_P(MagnitudeSqr, Mat) // ((float *)(dst.data))[i*dst.step/4 +j]= val1 * val1 +val2 * val2; } - end = cv::getTickCount(); + // end = cv::getTickCount(); diff --git a/modules/ocl/test/test_blend.cpp b/modules/ocl/test/test_blend.cpp index 94014c0..f9c8657 100644 --- a/modules/ocl/test/test_blend.cpp +++ b/modules/ocl/test/test_blend.cpp @@ -74,7 +74,7 @@ TEST_P(Blend, Accuracy) else blendLinearGold(img1, img2, weights1, weights2, result_gold); - EXPECT_MAT_NEAR(result_gold, result, CV_MAT_DEPTH(type) == CV_8U ? 1 : 1e-5f, NULL) + EXPECT_MAT_NEAR(result_gold, result, CV_MAT_DEPTH(type) == CV_8U ? 1.f : 1e-5f, 0); } INSTANTIATE_TEST_CASE_P(GPU_ImgProc, Blend, Combine( diff --git a/modules/ocl/test/test_color.cpp b/modules/ocl/test/test_color.cpp index 3935559..202967b 100644 --- a/modules/ocl/test/test_color.cpp +++ b/modules/ocl/test/test_color.cpp @@ -181,13 +181,13 @@ INSTANTIATE_TEST_CASE_P(OCL_ImgProc, CvtColor, testing::Combine( INSTANTIATE_TEST_CASE_P(OCL_ImgProc, CvtColor_YUV420, testing::Combine( testing::Values(cv::Size(128, 45), cv::Size(46, 132), cv::Size(1024, 1023)), - testing::Values(CV_YUV2RGBA_NV12, CV_YUV2BGRA_NV12, CV_YUV2RGB_NV12, CV_YUV2BGR_NV12) + testing::Values((int)CV_YUV2RGBA_NV12, (int)CV_YUV2BGRA_NV12, (int)CV_YUV2RGB_NV12, (int)CV_YUV2BGR_NV12) )); INSTANTIATE_TEST_CASE_P(OCL_ImgProc, CvtColor_Gray2RGB, testing::Combine( DIFFERENT_SIZES, testing::Values(MatDepth(CV_8U), MatDepth(CV_16U), MatDepth(CV_32F)), - testing::Values(CV_GRAY2BGR, CV_GRAY2BGRA, CV_GRAY2RGB, CV_GRAY2RGBA) + testing::Values((int)CV_GRAY2BGR, (int)CV_GRAY2BGRA, (int)CV_GRAY2RGB, (int)CV_GRAY2RGBA) )); } #endif diff --git a/modules/ocl/test/test_haar.cpp b/modules/ocl/test/test_haar.cpp index 52ce6a3..9bff324 100644 --- a/modules/ocl/test/test_haar.cpp +++ b/modules/ocl/test/test_haar.cpp @@ -109,15 +109,15 @@ TEST_F(Haar, FaceDetect) //double t = 0; vector faces, oclfaces; - const static Scalar colors[] = { CV_RGB(0, 0, 255), - CV_RGB(0, 128, 255), - CV_RGB(0, 255, 255), - CV_RGB(0, 255, 0), - CV_RGB(255, 128, 0), - CV_RGB(255, 255, 0), - CV_RGB(255, 0, 0), - CV_RGB(255, 0, 255) - } ; + // const static Scalar colors[] = { CV_RGB(0, 0, 255), + // CV_RGB(0, 128, 255), + // CV_RGB(0, 255, 255), + // CV_RGB(0, 255, 0), + // CV_RGB(255, 128, 0), + // CV_RGB(255, 255, 0), + // CV_RGB(255, 0, 0), + // CV_RGB(255, 0, 255) + // } ; Mat gray, smallImg(cvRound (img.rows / scale), cvRound(img.cols / scale), CV_8UC1 ); MemStorage storage(cvCreateMemStorage(0)); diff --git a/modules/ocl/test/test_imgproc.cpp b/modules/ocl/test/test_imgproc.cpp index 681c05a..97174ec 100644 --- a/modules/ocl/test/test_imgproc.cpp +++ b/modules/ocl/test/test_imgproc.cpp @@ -498,11 +498,11 @@ TEST_P(bilateralFilter, Mat) } else { - for(int i = 0; i < sizeof(bordertype) / sizeof(int); i++) + for(size_t i = 0; i < sizeof(bordertype) / sizeof(int); i++) for(int j = 0; j < LOOP_TIMES; j++) { random_roi(); - if(((bordertype[i] != cv::BORDER_CONSTANT) && (bordertype[i] != cv::BORDER_REPLICATE)) && (mat1_roi.cols <= radius) || (mat1_roi.cols <= radius) || (mat1_roi.rows <= radius) || (mat1_roi.rows <= radius)) + if(((bordertype[i] != cv::BORDER_CONSTANT) && (bordertype[i] != cv::BORDER_REPLICATE) && (mat1_roi.cols <= radius)) || (mat1_roi.cols <= radius) || (mat1_roi.rows <= radius) || (mat1_roi.rows <= radius)) { continue; } @@ -563,7 +563,7 @@ TEST_P(CopyMakeBorder, Mat) } else { - for(int i = 0; i < sizeof(bordertype) / sizeof(int); i++) + for(size_t i = 0; i < sizeof(bordertype) / sizeof(int); i++) for(int j = 0; j < LOOP_TIMES; j++) { random_roi(); @@ -911,7 +911,6 @@ PARAM_TEST_CASE(Remap, MatType, MatType, MatType, int, int) cv::RNG &rng = TS::ptr()->get_rng(); cv::Size srcSize = cv::Size(MWIDTH, MHEIGHT); - cv::Size dstSize = cv::Size(MWIDTH, MHEIGHT); cv::Size map1Size = cv::Size(MWIDTH, MHEIGHT); double min = 5, max = 16; diff --git a/modules/ocl/test/test_match_template.cpp b/modules/ocl/test/test_match_template.cpp index 673a5f7..3892513 100644 --- a/modules/ocl/test/test_match_template.cpp +++ b/modules/ocl/test/test_match_template.cpp @@ -100,7 +100,7 @@ TEST_P(MatchTemplate8U, Accuracy) EXPECT_MAT_NEAR(dst_gold, mat_dst, templ_size.area() * 1e-1, sss); -#if PERF_TEST +#ifdef PERF_TEST { P_TEST_FULL( {}, {cv::ocl::matchTemplate(ocl_image, ocl_templ, dst, method);}, {}); P_TEST_FULL( {}, {cv::matchTemplate(image, templ, dst_gold, method);}, {}); @@ -145,7 +145,7 @@ TEST_P(MatchTemplate32F, Accuracy) EXPECT_MAT_NEAR(dst_gold, mat_dst, templ_size.area() * 1e-1, sss); -#if PERF_TEST +#ifdef PERF_TEST { std::cout << "Method: " << TEMPLATE_METHOD_NAMES[method] << std::endl; std::cout << "Image Size: (" << size.width << ", " << size.height << ")" << std::endl; diff --git a/modules/ocl/test/utility.hpp b/modules/ocl/test/utility.hpp index 4ebf129..99fd334 100644 --- a/modules/ocl/test/utility.hpp +++ b/modules/ocl/test/utility.hpp @@ -76,12 +76,12 @@ double checkSimilarity(const cv::Mat &m1, const cv::Mat &m2); EXPECT_LE(checkNorm(cv::Mat(mat)), eps) \ } -//#define EXPECT_MAT_NEAR(mat1, mat2, eps) \ -//{ \ -// ASSERT_EQ(mat1.type(), mat2.type()); \ -// ASSERT_EQ(mat1.size(), mat2.size()); \ -// EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps); \ -//} +/*#define EXPECT_MAT_NEAR(mat1, mat2, eps) \ +{ \ + ASSERT_EQ(mat1.type(), mat2.type()); \ + ASSERT_EQ(mat1.size(), mat2.size()); \ + EXPECT_LE(checkNorm(cv::Mat(mat1), cv::Mat(mat2)), eps); \ +}*/ #define EXPECT_MAT_NEAR(mat1, mat2, eps,s) \ { \