From ecb707ca7b2ee76ea1e3c816776f022f87a60157 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 20 Oct 2012 16:17:41 +0400 Subject: [PATCH 1/3] Convert cl2cpp.py script to cmake New version removes inner comments and empty lines --- modules/ocl/CMakeLists.txt | 18 ++++--------- modules/ocl/cl2cpp.cmake | 34 +++++++++++++++++++++++ modules/ocl/cl2cpp.js | 40 --------------------------- modules/ocl/cl2cpp.py | 55 -------------------------------------- 4 files changed, 39 insertions(+), 108 deletions(-) create mode 100644 modules/ocl/cl2cpp.cmake delete mode 100644 modules/ocl/cl2cpp.js delete mode 100755 modules/ocl/cl2cpp.py diff --git a/modules/ocl/CMakeLists.txt b/modules/ocl/CMakeLists.txt index bd09dbe0fb..00d35ba9f4 100644 --- a/modules/ocl/CMakeLists.txt +++ b/modules/ocl/CMakeLists.txt @@ -10,20 +10,12 @@ ocv_module_include_directories() file(GLOB CL_FILES "${CMAKE_CURRENT_SOURCE_DIR}/src/kernels/*.cl") set(kernels_cpp "${CMAKE_CURRENT_BINARY_DIR}/kernels.cpp") -set(cl2cpp_script "${CMAKE_CURRENT_SOURCE_DIR}/cl2cpp.py") -set(cl2cpp_script_W32 "${CMAKE_CURRENT_SOURCE_DIR}/cl2cpp.js") +set(cl2cpp_script "${CMAKE_CURRENT_SOURCE_DIR}/cl2cpp.cmake") -IF(0) - add_custom_command( - OUTPUT ${kernels_cpp} - COMMAND wscript.exe ${cl2cpp_script_W32} "${CMAKE_CURRENT_SOURCE_DIR}/src/kernels" ${kernels_cpp} - DEPENDS ${CL_FILES} ${cl2cpp_script_W32}) -else() - add_custom_command( - OUTPUT ${kernels_cpp} - COMMAND ${PYTHON_EXECUTABLE} ${cl2cpp_script} "${CMAKE_CURRENT_SOURCE_DIR}/src/kernels" ${kernels_cpp} - DEPENDS ${CL_FILES} ${cl2cpp_script}) -ENDIF() +add_custom_command( + OUTPUT ${kernels_cpp} + COMMAND ${CMAKE_COMMAND} -DCL_DIR="${CMAKE_CURRENT_SOURCE_DIR}/src/kernels" -DOUTPUT="${kernels_cpp}" -P ${cl2cpp_script} + DEPENDS ${CL_FILES} ${cl2cpp_script}) file(GLOB lib_hdrs "include/opencv2/${name}/*.hpp" "include/opencv2/${name}/*.h") file(GLOB lib_srcs "src/*.cpp") diff --git a/modules/ocl/cl2cpp.cmake b/modules/ocl/cl2cpp.cmake new file mode 100644 index 0000000000..ca17c61b43 --- /dev/null +++ b/modules/ocl/cl2cpp.cmake @@ -0,0 +1,34 @@ +file(GLOB cl_list "${CL_DIR}/*.cl" ) + +file(WRITE ${OUTPUT} "// This file is auto-generated. Do not edit! + +namespace cv +{ +namespace ocl +{ +") + +foreach(cl ${cl_list}) + get_filename_component(cl_filename "${cl}" NAME_WE) + #message("${cl_filename}") + + file(READ "${cl}" lines) + + string(REPLACE "\r" "" lines "${lines}\n") + string(REPLACE "\t" " " lines "${lines}") + + string(REGEX REPLACE "/\\*([^*]/|\\*[^/]|[^*/])*\\*/" "" lines "${lines}") # multiline comments + string(REGEX REPLACE "[ ]*//[^\n]*\n" "\n" lines "${lines}") # single-line comments + string(REGEX REPLACE "\n[ ]*(\n[ ]*)*" "\n" lines "${lines}") # empty lines & leading whitespace + string(REGEX REPLACE "^\n" "" lines "${lines}") # leading new line + + string(REPLACE "\\" "\\\\" lines "${lines}") + string(REPLACE "\"" "\\\"" lines "${lines}") + string(REPLACE "\n" "\\n\"\n\"" lines "${lines}") + + string(REGEX REPLACE "\"$" "" lines "${lines}") # unneeded " at the eof + + file(APPEND ${OUTPUT} "const char* ${cl_filename}=\"${lines};\n") +endforeach() + +file(APPEND ${OUTPUT} "}\n}\n") \ No newline at end of file diff --git a/modules/ocl/cl2cpp.js b/modules/ocl/cl2cpp.js deleted file mode 100644 index f90160e4af..0000000000 --- a/modules/ocl/cl2cpp.js +++ /dev/null @@ -1,40 +0,0 @@ -var fso = new ActiveXObject("Scripting.FileSystemObject"), shell = new ActiveXObject("WScript.Shell"), args = WScript.Arguments, indir = args[0], outname = args[1], outDir, scriptFullPath = WScript.ScriptFullName; -function getDir(a) { - return a.substring(0, a.lastIndexOf("\\") || a.lastIndexOf("/")) -} -if (!indir || !outname) { - var scriptPath = getDir(WScript.ScriptFullName.toString()), - indir = indir || scriptPath + "/src/kernels"; - outname || (outname = scriptPath + "/kernels.cpp", outDir = scriptPath) -} else { - outDir = getDir(outname); - try { - fso.CreateFolder(outDir) - } catch (err) {} - -} -var infldr = fso.GetFolder(indir), clrx = /([\w-]+)\.cl$/i, stripBeginningRx = /^(\s)+/i, stripSinglelineMstyle = /\/\*.*?\*\//ig, outStream = fso.OpenTextFile(outname, 2, !0, -2); -outStream.write("// This file is auto-generated. Do not edit!\n\nnamespace cv{\n\tnamespace ocl{\n"); -for (var res, cl_file, l, state, countFiles = 0, codeRows = 0, removedRows = 0, filei = new Enumerator(infldr.Files); !filei.atEnd(); filei.moveNext()) - if (cl_file = filei.item(), res = cl_file.Name.match(clrx)) { - var cl_filename = res[1], - inStream = cl_file.OpenAsTextStream(1); - outStream.writeLine("\t\tconst char* " + cl_filename + "="); - state = 0; - for (countFiles++; !inStream.AtEndOfStream; ) { - l = inStream.readLine(); - stripSinglelineMstyle.lastIndex = 0; - l = l.replace(stripSinglelineMstyle, ""); - var mline = l.indexOf("/*"); - 0 <= mline ? (l = l.substr(0, mline), - state = 1) : (mline = l.indexOf("*/"), 0 <= mline && (l = l.substr(mline + 2), state = 0)); - var slineBegin = l.indexOf("//"); - 0 <= slineBegin && (l = l.substr(0, slineBegin)); - 1 == state || !l ? removedRows++ : (l = l.replace(stripBeginningRx, "$1"), l = l.replace("\\", "\\\\"), l = l.replace("\r", ""), l = l.replace('"', '\\"'), l = l.replace("\t", " "), codeRows++, outStream.writeLine('\t\t\t"' + l + '\\n"')) - } - outStream.writeLine("\t\t;"); - inStream.close() - } -outStream.writeLine("\t\t}\n\t}"); -outStream.close(); -shell.Popup("Merging OpenCL Kernels into cpp file has been FINISHED!\nFiles : " + countFiles + "\nCode rows : " + codeRows + "\nRemoved rows : " + removedRows, 1, "OpenCL Kernels to cpp file", 64); diff --git a/modules/ocl/cl2cpp.py b/modules/ocl/cl2cpp.py deleted file mode 100755 index f68d763d9d..0000000000 --- a/modules/ocl/cl2cpp.py +++ /dev/null @@ -1,55 +0,0 @@ -import os, os.path, sys, glob - -indir = sys.argv[1] -outname = sys.argv[2] -#indir = "/Users/vp/work/ocv/opencv/modules/ocl/src/kernels" -#outname = "/Users/vp/work/ocv.build/xcode/modules/ocl/kernels.cpp" - -try: - os.mkdir(os.path.dirname(outname)) -except OSError: - pass - -cl_list = glob.glob(os.path.join(indir, "*.cl")) -kfile = open(outname, "wt") - -kfile.write("""// This file is auto-generated. Do not edit! - -namespace cv -{ -namespace ocl -{ -""") - -for cl in cl_list: - cl_file = open(cl, "rt") - cl_filename = os.path.basename(cl) - cl_filename = cl_filename[:cl_filename.rfind(".")] - kfile.write("const char* %s=" % cl_filename) - state = 0 - - for cl_line in cl_file.readlines(): - l = cl_line.strip() - # skip the leading comments - if l.startswith("//") and l.find("*/") < 0: - if state == 0: - state = 1 - else: - if state == 1 or l.find("*/") >= 0: - state = 2 - - if state == 1: - continue - - l = l.replace("\\", "\\\\") - l = l.replace("\r", "") - l = l.replace("\"", "\\\"") - l = l.replace("\t", " ") - kfile.write("\"%s\\n\"\n" % l) - kfile.write(";\n") - cl_file.close() - -kfile.write("""} -} -""") -kfile.close() From d6aa3bd8edb10b8554a7ef65198cf95da1c59cd5 Mon Sep 17 00:00:00 2001 From: LeonidBeynenson Date: Tue, 23 Oct 2012 21:37:27 +0400 Subject: [PATCH 2/3] Made changes in cv::Algorithm made it to give more verbose errors when arguments of wrong types are passed, added setters with types (e.g. setInt, etc) --- modules/core/include/opencv2/core/core.hpp | 32 ++- .../core/include/opencv2/core/internal.hpp | 10 +- .../core/include/opencv2/core/operations.hpp | 16 ++ modules/core/src/algorithm.cpp | 216 ++++++++++++++++-- 4 files changed, 247 insertions(+), 27 deletions(-) diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 39f2f25c10..561d26b3a4 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -4341,15 +4341,24 @@ public: CV_WRAP vector getMatVector(const string& name) const; CV_WRAP Ptr getAlgorithm(const string& name) const; - CV_WRAP_AS(setInt) void set(const string& name, int value); - CV_WRAP_AS(setDouble) void set(const string& name, double value); - CV_WRAP_AS(setBool) void set(const string& name, bool value); - CV_WRAP_AS(setString) void set(const string& name, const string& value); - CV_WRAP_AS(setMat) void set(const string& name, const Mat& value); - CV_WRAP_AS(setMatVector) void set(const string& name, const vector& value); - CV_WRAP_AS(setAlgorithm) void set(const string& name, const Ptr& value); + void set(const string& name, int value); + void set(const string& name, double value); + void set(const string& name, bool value); + void set(const string& name, const string& value); + void set(const string& name, const Mat& value); + void set(const string& name, const vector& value); + void set(const string& name, const Ptr& value); template void set(const string& name, const Ptr<_Tp>& value); + CV_WRAP void setInt(const string& name, int value); + CV_WRAP void setDouble(const string& name, double value); + CV_WRAP void setBool(const string& name, bool value); + CV_WRAP void setString(const string& name, const string& value); + CV_WRAP void setMat(const string& name, const Mat& value); + CV_WRAP void setMatVector(const string& name, const vector& value); + CV_WRAP void setAlgorithm(const string& name, const Ptr& value); + template void setAlgorithm(const string& name, const Ptr<_Tp>& value); + void set(const char* name, int value); void set(const char* name, double value); void set(const char* name, bool value); @@ -4359,6 +4368,15 @@ public: void set(const char* name, const Ptr& value); template void set(const char* name, const Ptr<_Tp>& value); + void setInt(const char* name, int value); + void setDouble(const char* name, double value); + void setBool(const char* name, bool value); + void setString(const char* name, const string& value); + void setMat(const char* name, const Mat& value); + void setMatVector(const char* name, const vector& value); + void setAlgorithm(const char* name, const Ptr& value); + template void setAlgorithm(const char* name, const Ptr<_Tp>& value); + CV_WRAP string paramHelp(const string& name) const; int paramType(const char* name) const; CV_WRAP int paramType(const string& name) const; diff --git a/modules/core/include/opencv2/core/internal.hpp b/modules/core/include/opencv2/core/internal.hpp index f19b798e11..b1d8cf8486 100644 --- a/modules/core/include/opencv2/core/internal.hpp +++ b/modules/core/include/opencv2/core/internal.hpp @@ -263,20 +263,20 @@ namespace cv } //namespace cv #define CV_INIT_ALGORITHM(classname, algname, memberinit) \ - static Algorithm* create##classname() \ + static ::cv::Algorithm* create##classname() \ { \ return new classname; \ } \ \ - static AlgorithmInfo& classname##_info() \ + static ::cv::AlgorithmInfo& classname##_info() \ { \ - static AlgorithmInfo classname##_info_var(algname, create##classname); \ + static ::cv::AlgorithmInfo classname##_info_var(algname, create##classname); \ return classname##_info_var; \ } \ \ - static AlgorithmInfo& classname##_info_auto = classname##_info(); \ + static ::cv::AlgorithmInfo& classname##_info_auto = classname##_info(); \ \ - AlgorithmInfo* classname::info() const \ + ::cv::AlgorithmInfo* classname::info() const \ { \ static volatile bool initialized = false; \ \ diff --git a/modules/core/include/opencv2/core/operations.hpp b/modules/core/include/opencv2/core/operations.hpp index ae279a2e05..2f5f9205cf 100644 --- a/modules/core/include/opencv2/core/operations.hpp +++ b/modules/core/include/opencv2/core/operations.hpp @@ -3921,6 +3921,22 @@ inline void Algorithm::set(const string& _name, const Ptr<_Tp>& value) this->set<_Tp>(_name.c_str(), value); } +template +inline void Algorithm::setAlgorithm(const char* _name, const Ptr<_Tp>& value) +{ + Ptr algo_ptr = value. template ptr(); + if (algo_ptr.empty()) { + CV_Error( CV_StsUnsupportedFormat, "unknown/unsupported Ptr type of the second parameter of the method Algorithm::set"); + } + info()->set(this, _name, ParamType::type, &algo_ptr); +} + +template +inline void Algorithm::setAlgorithm(const string& _name, const Ptr<_Tp>& value) +{ + this->set<_Tp>(_name.c_str(), value); +} + template inline typename ParamType<_Tp>::member_type Algorithm::get(const string& _name) const { typename ParamType<_Tp>::member_type value; diff --git a/modules/core/src/algorithm.cpp b/modules/core/src/algorithm.cpp index 090fdf1cc0..90350d8bf6 100644 --- a/modules/core/src/algorithm.cpp +++ b/modules/core/src/algorithm.cpp @@ -114,7 +114,7 @@ template inline const _ValueTp* findstr(const sorted_vector& value) info()->set(this, parameter, ParamType::type, &value); } + +void Algorithm::setInt(const string& parameter, int value) +{ + info()->set(this, parameter.c_str(), ParamType::type, &value); +} + +void Algorithm::setDouble(const string& parameter, double value) +{ + info()->set(this, parameter.c_str(), ParamType::type, &value); +} + +void Algorithm::setBool(const string& parameter, bool value) +{ + info()->set(this, parameter.c_str(), ParamType::type, &value); +} + +void Algorithm::setString(const string& parameter, const string& value) +{ + info()->set(this, parameter.c_str(), ParamType::type, &value); +} + +void Algorithm::setMat(const string& parameter, const Mat& value) +{ + info()->set(this, parameter.c_str(), ParamType::type, &value); +} + +void Algorithm::setMatVector(const string& parameter, const vector& value) +{ + info()->set(this, parameter.c_str(), ParamType >::type, &value); +} + +void Algorithm::setAlgorithm(const string& parameter, const Ptr& value) +{ + info()->set(this, parameter.c_str(), ParamType::type, &value); +} + +void Algorithm::setInt(const char* parameter, int value) +{ + info()->set(this, parameter, ParamType::type, &value); +} + +void Algorithm::setDouble(const char* parameter, double value) +{ + info()->set(this, parameter, ParamType::type, &value); +} + +void Algorithm::setBool(const char* parameter, bool value) +{ + info()->set(this, parameter, ParamType::type, &value); +} + +void Algorithm::setString(const char* parameter, const string& value) +{ + info()->set(this, parameter, ParamType::type, &value); +} + +void Algorithm::setMat(const char* parameter, const Mat& value) +{ + info()->set(this, parameter, ParamType::type, &value); +} + +void Algorithm::setMatVector(const char* parameter, const vector& value) +{ + info()->set(this, parameter, ParamType >::type, &value); +} + +void Algorithm::setAlgorithm(const char* parameter, const Ptr& value) +{ + info()->set(this, parameter, ParamType::type, &value); +} + + + int Algorithm::getInt(const string& parameter) const { return get(parameter); @@ -441,6 +514,68 @@ union GetSetParam void (Algorithm::*set_algo)(const Ptr&); }; +static string getNameOfType(int argType); + +static string getNameOfType(int argType) +{ + switch(argType) + { + case Param::INT: return "integer"; + case Param::SHORT: return "short"; + case Param::BOOLEAN: return "boolean"; + case Param::REAL: return "double"; + case Param::STRING: return "string"; + case Param::MAT: return "cv::Mat"; + case Param::MAT_VECTOR: return "std::vector"; + case Param::ALGORITHM: return "algorithm"; + default: CV_Error(CV_StsBadArg, "Wrong argument type"); + } + return ""; +} +static string getErrorMessageForWrongArgumentInSetter(string algoName, string paramName, int paramType, int argType); +static string getErrorMessageForWrongArgumentInSetter(string algoName, string paramName, int paramType, int argType) +{ + string message = string("Argument error: the setter") + + " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName + +"', the parameter has " + getNameOfType(paramType) + " type, "; + + if (paramType == Param::INT || paramType == Param::BOOLEAN || paramType == Param::REAL) + { + message += "so it should be set by integer, boolean, or double value, "; + } + else if (paramType == Param::SHORT) + { + message += "so it should be set by integer value, "; + } + message += "but the setter was called with " + getNameOfType(argType) + " value"; + + return message; +} + +static string getErrorMessageForWrongArgumentInGetter(string algoName, string paramName, int paramType, int argType); +static string getErrorMessageForWrongArgumentInGetter(string algoName, string paramName, int paramType, int argType) +{ + string message = string("Argument error: the getter") + + " method was called for the parameter '" + paramName + "' of the algorithm '" + algoName + +"', the parameter has " + getNameOfType(paramType) + " type, "; + + if (paramType == Param::BOOLEAN) + { + message += "so it should be get as integer, boolean, or double value, "; + } + else if (paramType == Param::INT) + { + message += "so it should be get as integer or double value, "; + } + else if (paramType == Param::SHORT) + { + message += "so it should be get as integer value, "; + } + message += "but the getter was called to get a " + getNameOfType(argType) + " value"; + + return message; +} + void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, const void* value, bool force) const { const Param* p = findstr(data->params, parameter); @@ -456,8 +591,11 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con if( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL ) { - CV_Assert( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN || - (p->type == Param::SHORT && argType == Param::INT) ); + if ( !( p->type == Param::INT || p->type == Param::REAL || p->type == Param::BOOLEAN || (p->type == Param::SHORT && argType == Param::INT)) ) + { + string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } if( p->type == Param::INT ) { @@ -500,7 +638,11 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con } else if( argType == Param::STRING ) { - CV_Assert( p->type == Param::STRING ); + if( p->type != Param::STRING ) + { + string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } const string& val = *(const string*)value; if( p->setter ) @@ -510,7 +652,11 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con } else if( argType == Param::MAT ) { - CV_Assert( p->type == Param::MAT ); + if( p->type != Param::MAT ) + { + string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } const Mat& val = *(const Mat*)value; if( p->setter ) @@ -520,7 +666,11 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con } else if( argType == Param::MAT_VECTOR ) { - CV_Assert( p->type == Param::MAT_VECTOR ); + if( p->type != Param::MAT_VECTOR ) + { + string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } const vector& val = *(const vector*)value; if( p->setter ) @@ -530,7 +680,11 @@ void AlgorithmInfo::set(Algorithm* algo, const char* parameter, int argType, con } else if( argType == Param::ALGORITHM ) { - CV_Assert( p->type == Param::ALGORITHM ); + if( p->type != Param::ALGORITHM ) + { + string message = getErrorMessageForWrongArgumentInSetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } const Ptr& val = *(const Ptr*)value; if( p->setter ) @@ -555,7 +709,11 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argTyp { if( p->type == Param::INT ) { - CV_Assert( argType == Param::INT || argType == Param::REAL ); + if (!( argType == Param::INT || argType == Param::REAL )) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } int val = p->getter ? (algo->*f.get_int)() : *(int*)((uchar*)algo + p->offset); if( argType == Param::INT ) @@ -565,14 +723,22 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argTyp } else if( p->type == Param::SHORT ) { - CV_Assert( argType == Param::INT ); + if( argType != Param::INT ) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } int val = p->getter ? (algo->*f.get_int)() : *(short*)((uchar*)algo + p->offset); *(int*)value = val; } else if( p->type == Param::BOOLEAN ) { - CV_Assert( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL ); + if (!( argType == Param::INT || argType == Param::BOOLEAN || argType == Param::REAL )) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } bool val = p->getter ? (algo->*f.get_bool)() : *(bool*)((uchar*)algo + p->offset); if( argType == Param::INT ) @@ -584,7 +750,11 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argTyp } else { - CV_Assert( argType == Param::REAL ); + if( argType != Param::REAL ) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } double val = p->getter ? (algo->*f.get_double)() : *(double*)((uchar*)algo + p->offset); *(double*)value = val; @@ -592,28 +762,44 @@ void AlgorithmInfo::get(const Algorithm* algo, const char* parameter, int argTyp } else if( argType == Param::STRING ) { - CV_Assert( p->type == Param::STRING ); + if( p->type != Param::STRING ) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } *(string*)value = p->getter ? (algo->*f.get_string)() : *(string*)((uchar*)algo + p->offset); } else if( argType == Param::MAT ) { - CV_Assert( p->type == Param::MAT ); + if( p->type != Param::MAT ) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } *(Mat*)value = p->getter ? (algo->*f.get_mat)() : *(Mat*)((uchar*)algo + p->offset); } else if( argType == Param::MAT_VECTOR ) { - CV_Assert( p->type == Param::MAT_VECTOR ); + if( p->type != Param::MAT_VECTOR ) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } *(vector*)value = p->getter ? (algo->*f.get_mat_vector)() : *(vector*)((uchar*)algo + p->offset); } else if( argType == Param::ALGORITHM ) { - CV_Assert( p->type == Param::ALGORITHM ); + if( p->type != Param::ALGORITHM ) + { + string message = getErrorMessageForWrongArgumentInGetter(algo->name(), parameter, p->type, argType); + CV_Error(CV_StsBadArg, message); + } *(Ptr*)value = p->getter ? (algo->*f.get_algo)() : *(Ptr*)((uchar*)algo + p->offset); From 63397e825c965f71162d49233fc940bc15205d61 Mon Sep 17 00:00:00 2001 From: Andrey Kamaev Date: Sat, 20 Oct 2012 16:37:46 +0400 Subject: [PATCH 3/3] Cleanup CMakeLists.txt of ocl module --- modules/ocl/CMakeLists.txt | 18 +++++++----------- modules/ocl/src/precomp.hpp | 10 ++++------ 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/modules/ocl/CMakeLists.txt b/modules/ocl/CMakeLists.txt index 00d35ba9f4..5cbf57cbc3 100644 --- a/modules/ocl/CMakeLists.txt +++ b/modules/ocl/CMakeLists.txt @@ -4,7 +4,7 @@ if(NOT HAVE_OPENCL) endif() set(the_description "OpenCL-accelerated Computer Vision") -ocv_add_module(ocl opencv_core opencv_imgproc opencv_calib3d opencv_objdetect opencv_video opencv_nonfree opencv_ts) +ocv_add_module(ocl opencv_core opencv_imgproc opencv_features2d opencv_objdetect opencv_video) ocv_module_include_directories() @@ -27,7 +27,7 @@ source_group("Src\\Host" FILES ${lib_srcs} ${lib_int_hdrs} ${kernels_cpp}) if (HAVE_OPENCL) set(ocl_link_libs ${OPENCL_LIBRARIES}) if(OPENCL_INCLUDE_DIR) - ocv_include_directories(${OPENCL_INCLUDE_DIR}) + ocv_include_directories(${OPENCL_INCLUDE_DIR}) endif() if (HAVE_CLAMDFFT) set(ocl_link_libs ${ocl_link_libs} ${CLAMDFFT_LIBRARIES}) @@ -39,17 +39,12 @@ if (HAVE_OPENCL) endif() endif() -ocv_set_module_sources( - HEADERS ${lib_hdrs} - SOURCES ${lib_int_hdrs} ${lib_srcs} - ) - -set(OPENCV_MODULE_opencv_ocl_SOURCES ${OPENCV_MODULE_opencv_ocl_SOURCES} ${kernels_cpp}) +ocv_set_module_sources(HEADERS ${lib_hdrs} SOURCES ${lib_int_hdrs} ${lib_srcs} ${kernels_cpp}) ocv_create_module(${ocl_link_libs}) install(FILES ${lib_hdrs} - DESTINATION include/opencv2/${name} - COMPONENT main) + DESTINATION include/opencv2/${name} + COMPONENT main) ocv_add_precompiled_headers(${the_module}) @@ -61,6 +56,7 @@ file(GLOB test_hdrs "test/*.hpp" "test/*.h") ocv_add_accuracy_tests(FILES "Include" ${test_hdrs} FILES "Src" ${test_srcs}) + ################################################################################################################ ################################ OpenCL Module Performance ################################################## ################################################################################################################ @@ -68,4 +64,4 @@ file(GLOB perf_srcs "perf/*.cpp") file(GLOB perf_hdrs "perf/*.hpp" "perf/*.h") ocv_add_perf_tests(FILES "Include" ${perf_hdrs} - FILES "Src" ${perf_srcs}) + FILES "Src" ${perf_srcs}) diff --git a/modules/ocl/src/precomp.hpp b/modules/ocl/src/precomp.hpp index 33f89dffcb..41b488ad4e 100644 --- a/modules/ocl/src/precomp.hpp +++ b/modules/ocl/src/precomp.hpp @@ -63,16 +63,14 @@ #include #include -#include "opencv2/ocl/ocl.hpp" - -#include "opencv2/imgproc/imgproc.hpp" - -#include "opencv2/objdetect/objdetect.hpp" #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core/core_c.h" -//#include "opencv2/highgui/highgui.hpp" +#include "opencv2/objdetect/objdetect.hpp" +#include "opencv2/ocl/ocl.hpp" + #include "opencv2/core/internal.hpp" +//#include "opencv2/highgui/highgui.hpp" #define __ATI__