diff --git a/modules/core/include/opencv2/core/core.hpp b/modules/core/include/opencv2/core/core.hpp index 40bc792c8c9b458f59d2537f9bb6cbc6b5e1ac05..8f9d54906ff6c3fb2f0b8f13156e47a80747c39a 100644 --- a/modules/core/include/opencv2/core/core.hpp +++ b/modules/core/include/opencv2/core/core.hpp @@ -2388,7 +2388,7 @@ public: PCA(InputArray data, InputArray mean, int flags, double retainedVariance); //! operator that performs PCA. The previously stored data, if any, is released PCA& operator()(InputArray data, InputArray mean, int flags, int maxComponents=0); - PCA& operator()(InputArray data, InputArray mean, int flags, double retainedVariance); + PCA& computeVar(InputArray data, InputArray mean, int flags, double retainedVariance); //! projects vector from the original space to the principal components subspace Mat project(InputArray vec) const; //! projects vector from the original space to the principal components subspace @@ -2406,7 +2406,7 @@ public: CV_EXPORTS_W void PCACompute(InputArray data, CV_OUT InputOutputArray mean, OutputArray eigenvectors, int maxComponents=0); -CV_EXPORTS_W void PCACompute(InputArray data, CV_OUT InputOutputArray mean, +CV_EXPORTS_W void PCAComputeVar(InputArray data, CV_OUT InputOutputArray mean, OutputArray eigenvectors, double retainedVariance); CV_EXPORTS_W void PCAProject(InputArray data, InputArray mean, @@ -4562,51 +4562,113 @@ template<> struct ParamType }; -// The CommandLineParser class is designed for command line arguments parsing - +/*! +"\nThe CommandLineParser class is designed for command line arguments parsing\n" + "Keys map: \n" + "Before you start to work with CommandLineParser you have to create a map for keys.\n" + " It will look like this\n" + " const char* keys =\n" + " {\n" + " { s| string| 123asd |string parameter}\n" + " { d| digit | 100 |digit parameter }\n" + " { c|noCamera|false |without camera }\n" + " { 1| |some text|help }\n" + " { 2| |333 |another help }\n" + " };\n" + "Usage syntax: \n" + " \"{\" - start of parameter string.\n" + " \"}\" - end of parameter string\n" + " \"|\" - separator between short name, full name, default value and help\n" + "Supported syntax: \n" + " --key1=arg1 \n" + " -key2=arg2 \n" + "Usage: \n" + " Imagine that the input parameters are next:\n" + " -s=string_value --digit=250 --noCamera lena.jpg 10000\n" + " CommandLineParser parser(argc, argv, keys) - create a parser object\n" + " parser.get(\"s\" or \"string\") will return you first parameter value\n" + " parser.get(\"s\", false or \"string\", false) will return you first parameter value\n" + " without spaces in end and begin\n" + " parser.get(\"d\" or \"digit\") will return you second parameter value.\n" + " It also works with 'unsigned int', 'double', and 'float' types>\n" + " parser.get(\"c\" or \"noCamera\") will return you true .\n" + " If you enter this key in commandline>\n" + " It return you false otherwise.\n" + " parser.get(\"1\") will return you the first argument without parameter (lena.jpg) \n" + " parser.get(\"2\") will return you the second argument without parameter (10000)\n" + " It also works with 'unsigned int', 'double', and 'float' types \n" +*/ class CV_EXPORTS CommandLineParser { -public: - CommandLineParser(int argc, const char* const argv[], const char* key_map); - CommandLineParser(int argc, const char* const argv[], const string& key_map); - CommandLineParser(const CommandLineParser& parser); - CommandLineParser& operator = (const CommandLineParser& parser); + public: - string getPathToApplication() const; + //! the default constructor + CommandLineParser(int argc, const char* const argv[], const char* key_map); - template - T get(const string& name, bool space_delete = true) const + //! get parameter, you can choose: delete spaces in end and begin or not + template + _Tp get(const std::string& name, bool space_delete=true) { - T val = T(); - getByName(name, space_delete, ParamType::type, (void*)&val); - return val; + if (!has(name)) + { + return _Tp(); + } + std::string str = getString(name); + return analyzeValue<_Tp>(str, space_delete); } - template - T get(int index, bool space_delete = true) const + //! print short name, full name, current value and help for all params + void printParams(); + + protected: + std::map > data; + std::string getString(const std::string& name); + + bool has(const std::string& keys); + + template + _Tp analyzeValue(const std::string& str, bool space_delete=false); + + template + static _Tp getData(const std::string& str) { - T val = T(); - getByIndex(index, space_delete, ParamType::type, (void*)&val); - return val; + _Tp res; + std::stringstream s1(str); + s1 >> res; + return res; } - - bool has(const string& keys); - bool check() const; - void about(const string& message); + template + _Tp fromStringNumber(const std::string& str);//the default conversion function for numbers - void printMessage() const; - void printErrors() const; - void printParams(); + }; -protected: - string getString(const string& name); - void getByName(const string& name, bool space_delete, int type, void* dst) const; - void getByIndex(int index, bool space_delete, int type, void* dst) const; +template<> CV_EXPORTS +bool CommandLineParser::get(const std::string& name, bool space_delete); + +template<> CV_EXPORTS +std::string CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + +template<> CV_EXPORTS +int CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + +template<> CV_EXPORTS +unsigned int CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + +template<> CV_EXPORTS +uint64 CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + +template<> CV_EXPORTS +float CommandLineParser::analyzeValue(const std::string& str, bool space_delete); + +template<> CV_EXPORTS +double CommandLineParser::analyzeValue(const std::string& str, bool space_delete); - struct Impl; - Impl* impl; -}; /////////////////////////////// Parallel Primitives ////////////////////////////////// diff --git a/modules/core/include/opencv2/core/cuda_devptrs.hpp b/modules/core/include/opencv2/core/cuda_devptrs.hpp index 257f5960e51359b51c7e1b84ec3f98cb038a4bf8..373ff290b24b5ee9b2f50c3ff8efd35999088719 100644 --- a/modules/core/include/opencv2/core/cuda_devptrs.hpp +++ b/modules/core/include/opencv2/core/cuda_devptrs.hpp @@ -123,7 +123,7 @@ namespace cv typedef PtrStep PtrStepi; -#if defined __GNUC__ +#if defined __GNUC__ #define __CV_GPU_DEPR_BEFORE__ #define __CV_GPU_DEPR_AFTER__ __attribute__ ((deprecated)) #elif defined(__MSVC__) //|| defined(__CUDACC__) @@ -140,7 +140,7 @@ namespace cv DevMem2D_() {} DevMem2D_(int rows_, int cols_, T* data_, size_t step_) : PtrStepSz(rows_, cols_, data_, step_) {} - template + template explicit __CV_GPU_DEPR_BEFORE__ DevMem2D_(const DevMem2D_& d) : PtrStepSz(d.rows, d.cols, (T*)d.data, d.step) {} } __CV_GPU_DEPR_AFTER__ ; @@ -149,6 +149,31 @@ namespace cv typedef DevMem2D_ DevMem2Df; typedef DevMem2D_ DevMem2Di; + template struct PtrElemStep_ : public PtrStep + { + PtrElemStep_(const DevMem2D_& mem) : PtrStep(mem.data, mem.step) + { + StaticAssert<256 % sizeof(T) == 0>::check(); + + PtrStep::step /= PtrStep::elem_size; + } + __CV_GPU_HOST_DEVICE__ T* ptr(int y = 0) { return PtrStep::data + y * PtrStep::step; } + __CV_GPU_HOST_DEVICE__ const T* ptr(int y = 0) const { return PtrStep::data + y * PtrStep::step; } + + __CV_GPU_HOST_DEVICE__ T& operator ()(int y, int x) { return ptr(y)[x]; } + __CV_GPU_HOST_DEVICE__ const T& operator ()(int y, int x) const { return ptr(y)[x]; } + }; + + template struct PtrStep_ : public PtrStep + { + PtrStep_() {} + PtrStep_(const DevMem2D_& mem) : PtrStep(mem.data, mem.step) {} + }; + + typedef PtrElemStep_ PtrElemStep; + typedef PtrElemStep_ PtrElemStepf; + typedef PtrElemStep_ PtrElemStepi; + //#undef __CV_GPU_DEPR_BEFORE__ //#undef __CV_GPU_DEPR_AFTER__ diff --git a/modules/core/include/opencv2/core/devmem2d.hpp b/modules/core/include/opencv2/core/devmem2d.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fc2d2f2757601c463411c41728d346dfec068b3f --- /dev/null +++ b/modules/core/include/opencv2/core/devmem2d.hpp @@ -0,0 +1,43 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other GpuMaterials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "opencv2/core/cuda_devptrs.hpp" diff --git a/modules/core/include/opencv2/core/eigen.hpp b/modules/core/include/opencv2/core/eigen.hpp index 49bd36ba3b12007f29cee6003dd353ab38d3c1bc..751734eb5a69c72a1b3a18c088ac588d4c6c8742 100644 --- a/modules/core/include/opencv2/core/eigen.hpp +++ b/modules/core/include/opencv2/core/eigen.hpp @@ -74,21 +74,6 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo } } -// Matx case -template -void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, - Matx<_Tp, _rows, _cols>& dst ) -{ - if( !(src.Flags & Eigen::RowMajorBit) ) - { - dst = Matx<_Tp, _cols, _rows>(static_cast(src.data())).t(); - } - else - { - dst = Matx<_Tp, _rows, _cols>(static_cast(src.data())); - } -} - template void cv2eigen( const Mat& src, Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst ) diff --git a/modules/core/include/opencv2/core/gpumat.hpp b/modules/core/include/opencv2/core/gpumat.hpp index c0ae17b2681c08103efd516e6eac10c563d5fb99..41e81511e37da3069c29beb019285d8ad2145207 100644 --- a/modules/core/include/opencv2/core/gpumat.hpp +++ b/modules/core/include/opencv2/core/gpumat.hpp @@ -114,8 +114,6 @@ namespace cv { namespace gpu int multiProcessorCount() const { return multi_processor_count_; } - size_t sharedMemPerBlock() const { return sharedMemPerBlock_; } - size_t freeMemory() const; size_t totalMemory() const; @@ -137,7 +135,6 @@ namespace cv { namespace gpu int multi_processor_count_; int majorVersion_; int minorVersion_; - size_t sharedMemPerBlock_; }; CV_EXPORTS void printCudaDeviceInfo(int device); @@ -272,7 +269,8 @@ namespace cv { namespace gpu template operator PtrStep<_Tp>() const; // Deprecated function - __CV_GPU_DEPR_BEFORE__ template operator DevMem2D_<_Tp>() const __CV_GPU_DEPR_AFTER__; + __CV_GPU_DEPR_BEFORE__ template operator DevMem2D_<_Tp>() const __CV_GPU_DEPR_AFTER__; + __CV_GPU_DEPR_BEFORE__ template operator PtrStep_<_Tp>() const __CV_GPU_DEPR_AFTER__; #undef __CV_GPU_DEPR_BEFORE__ #undef __CV_GPU_DEPR_AFTER__ @@ -499,7 +497,7 @@ namespace cv { namespace gpu CV_DbgAssert((unsigned)y < (unsigned)rows); return data + step * y; } - + inline GpuMat& GpuMat::operator = (Scalar s) { setTo(s); @@ -521,6 +519,11 @@ namespace cv { namespace gpu return DevMem2D_(rows, cols, (T*)data, step); } + template inline GpuMat::operator PtrStep_() const + { + return PtrStep_(static_cast< DevMem2D_ >(*this)); + } + inline GpuMat createContinuous(int rows, int cols, int type) { GpuMat m; diff --git a/modules/core/include/opencv2/core/version.hpp b/modules/core/include/opencv2/core/version.hpp index 8d47f459a8831282c183abe5114fd90fcd44f8a2..07cd4506dd1c70e92b8be6d8a65fb91cb89126da 100644 --- a/modules/core/include/opencv2/core/version.hpp +++ b/modules/core/include/opencv2/core/version.hpp @@ -49,7 +49,7 @@ #define CV_MAJOR_VERSION 2 #define CV_MINOR_VERSION 4 -#define CV_SUBMINOR_VERSION 9 +#define CV_SUBMINOR_VERSION 2 #define CVAUX_STR_EXP(__A) #__A #define CVAUX_STR(__A) CVAUX_STR_EXP(__A) diff --git a/modules/core/src/cmdparser.cpp b/modules/core/src/cmdparser.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b5c838c9db8ce06477c30e80c3f33065c6b03b7a --- /dev/null +++ b/modules/core/src/cmdparser.cpp @@ -0,0 +1,382 @@ +#include "precomp.hpp" + +#include +#include + +using namespace std; +using namespace cv; + +namespace { +void helpParser() +{ + printf("\nThe CommandLineParser class is designed for command line arguments parsing\n" + "Keys map: \n" + "Before you start to work with CommandLineParser you have to create a map for keys.\n" + " It will look like this\n" + " const char* keys =\n" + " {\n" + " { s| string| 123asd |string parameter}\n" + " { d| digit | 100 |digit parameter }\n" + " { c|noCamera|false |without camera }\n" + " { 1| |some text|help }\n" + " { 2| |333 |another help }\n" + " };\n" + "Usage syntax: \n" + " \"{\" - start of parameter string.\n" + " \"}\" - end of parameter string\n" + " \"|\" - separator between short name, full name, default value and help\n" + "Supported syntax: \n" + " --key1=arg1 \n" + " -key2=arg2 \n" + "Usage: \n" + " Imagine that the input parameters are next:\n" + " -s=string_value --digit=250 --noCamera lena.jpg 10000\n" + " CommandLineParser parser(argc, argv, keys) - create a parser object\n" + " parser.get(\"s\" or \"string\") will return you first parameter value\n" + " parser.get(\"s\", false or \"string\", false) will return you first parameter value\n" + " without spaces in end and begin\n" + " parser.get(\"d\" or \"digit\") will return you second parameter value.\n" + " It also works with 'unsigned int', 'double', and 'float' types>\n" + " parser.get(\"c\" or \"noCamera\") will return you true .\n" + " If you enter this key in commandline>\n" + " It return you false otherwise.\n" + " parser.get(\"1\") will return you the first argument without parameter (lena.jpg) \n" + " parser.get(\"2\") will return you the second argument without parameter (10000)\n" + " It also works with 'unsigned int', 'double', and 'float' types \n" + ); +} + +vector split_string(const string& str, const string& delimiters) +{ + vector res; + + string split_str = str; + size_t pos_delim = split_str.find(delimiters); + + while ( pos_delim != string::npos) + { + if (pos_delim == 0) + { + res.push_back(""); + split_str.erase(0, 1); + } + else + { + res.push_back(split_str.substr(0, pos_delim)); + split_str.erase(0, pos_delim + 1); + } + + pos_delim = split_str.find(delimiters); + } + + res.push_back(split_str); + + return res; +} + +string del_space(string name) +{ + while ((name.find_first_of(' ') == 0) && (name.length() > 0)) + name.erase(0, 1); + + while ((name.find_last_of(' ') == (name.length() - 1)) && (name.length() > 0)) + name.erase(name.end() - 1, name.end()); + + return name; +} + +}//namespace + +CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys) +{ + std::string keys_buffer; + std::string values_buffer; + std::string buffer; + std::string curName; + std::vector keysVector; + std::vector paramVector; + std::map >::iterator it; + size_t flagPosition; + int currentIndex = 1; + //bool isFound = false; + bool withNoKey = false; + bool hasValueThroughEq = false; + + keys_buffer = keys; + while (!keys_buffer.empty()) + { + + flagPosition = keys_buffer.find_first_of('}'); + flagPosition++; + buffer = keys_buffer.substr(0, flagPosition); + keys_buffer.erase(0, flagPosition); + + flagPosition = buffer.find('{'); + if (flagPosition != buffer.npos) + buffer.erase(flagPosition, (flagPosition + 1)); + + flagPosition = buffer.find('}'); + if (flagPosition != buffer.npos) + buffer.erase(flagPosition); + + paramVector = split_string(buffer, "|"); + while (paramVector.size() < 4) paramVector.push_back(""); + + buffer = paramVector[0]; + buffer += '|' + paramVector[1]; + + //if (buffer == "") CV_ERROR(CV_StsBadArg, "In CommandLineParser need set short and full name"); + + paramVector.erase(paramVector.begin(), paramVector.begin() + 2); + data[buffer] = paramVector; + } + + buffer.clear(); + keys_buffer.clear(); + paramVector.clear(); + for (int i = 1; i < argc; i++) + { + if (!argv[i]) + break; + curName = argv[i]; + if (curName.find('-') == 0 && ((curName[1] < '0') || (curName[1] > '9'))) + { + while (curName.find('-') == 0) + curName.erase(curName.begin(), (curName.begin() + 1)); + } + else + withNoKey = true; + if (curName.find('=') != curName.npos) + { + hasValueThroughEq = true; + buffer = curName; + curName.erase(curName.find('=')); + buffer.erase(0, (buffer.find('=') + 1)); + } + + values_buffer = del_space(values_buffer); + + for(it = data.begin(); it != data.end(); it++) + { + keys_buffer = it->first; + keysVector = split_string(keys_buffer, "|"); + + for (size_t j = 0; j < keysVector.size(); j++) keysVector[j] = del_space(keysVector[j]); + + values_buffer = it->second[0]; + if (((curName == keysVector[0]) || (curName == keysVector[1])) && hasValueThroughEq) + { + it->second[0] = buffer; + //isFound = true; + break; + } + + if (!hasValueThroughEq && ((curName == keysVector[0]) || (curName == keysVector[1])) + && ( + values_buffer.find("false") != values_buffer.npos || + values_buffer == "" + )) + { + it->second[0] = "true"; + //isFound = true; + break; + } + + if (!hasValueThroughEq && (values_buffer.find("false") == values_buffer.npos) && + ((curName == keysVector[0]) || (curName == keysVector[1]))) + { + it->second[0] = argv[++i]; + //isFound = true; + break; + } + + + if (withNoKey) + { + std::string noKeyStr = it->first; + if(atoi(noKeyStr.c_str()) == currentIndex) + { + it->second[0] = curName; + currentIndex++; + //isFound = true; + break; + } + } + } + + withNoKey = false; + hasValueThroughEq = false; + //isFound = false; + } +} + +bool CommandLineParser::has(const std::string& keys) +{ + std::map >::iterator it; + std::vector keysVector; + + for(it = data.begin(); it != data.end(); it++) + { + keysVector = split_string(it->first, "|"); + for (size_t i = 0; i < keysVector.size(); i++) keysVector[i] = del_space(keysVector[i]); + + if (keysVector.size() == 1) keysVector.push_back(""); + + if ((del_space(keys).compare(keysVector[0]) == 0) || + (del_space(keys).compare(keysVector[1]) == 0)) + return true; + } + + return false; +} + +std::string CommandLineParser::getString(const std::string& keys) +{ + std::map >::iterator it; + std::vector valueVector; + + for(it = data.begin(); it != data.end(); it++) + { + valueVector = split_string(it->first, "|"); + for (size_t i = 0; i < valueVector.size(); i++) valueVector[i] = del_space(valueVector[i]); + + if (valueVector.size() == 1) valueVector.push_back(""); + + if ((del_space(keys).compare(valueVector[0]) == 0) || + (del_space(keys).compare(valueVector[1]) == 0)) + return it->second[0]; + } + return string(); +} + +template + _Tp CommandLineParser::fromStringNumber(const std::string& str)//the default conversion function for numbers +{ + return getData<_Tp>(str); +} + + void CommandLineParser::printParams() + { + int col_p = 30; + int col_d = 50; + + std::map >::iterator it; + std::vector keysVector; + std::string buf; + for(it = data.begin(); it != data.end(); it++) + { + keysVector = split_string(it->first, "|"); + for (size_t i = 0; i < keysVector.size(); i++) keysVector[i] = del_space(keysVector[i]); + + cout << " "; + buf = ""; + if (keysVector[0] != "") + { + buf = "-" + keysVector[0]; + if (keysVector[1] != "") buf += ", --" + keysVector[1]; + } + else if (keysVector[1] != "") buf += "--" + keysVector[1]; + if (del_space(it->second[0]) != "") buf += "=[" + del_space(it->second[0]) + "]"; + + cout << setw(col_p-2) << left << buf; + + if ((int)buf.length() > col_p-2) + { + cout << endl << " "; + cout << setw(col_p-2) << left << " "; + } + + buf = ""; + if (del_space(it->second[1]) != "") buf += del_space(it->second[1]); + + for(;;) + { + bool tr = ((int)buf.length() > col_d-2) ? true: false; + std::string::size_type pos = 0; + + if (tr) + { + pos = buf.find_first_of(' '); + for(;;) + { + if (buf.find_first_of(' ', pos + 1 ) < (std::string::size_type)(col_d-2) && + buf.find_first_of(' ', pos + 1 ) != std::string::npos) + pos = buf.find_first_of(' ', pos + 1); + else + break; + } + pos++; + cout << setw(col_d-2) << left << buf.substr(0, pos) << endl; + } + else + { + cout << setw(col_d-2) << left << buf<< endl; + break; + } + + buf.erase(0, pos); + cout << " "; + cout << setw(col_p-2) << left << " "; + } + } + } + +template<> +bool CommandLineParser::get(const std::string& name, bool space_delete) +{ + std::string str_buf = getString(name); + + if (space_delete && str_buf != "") + { + str_buf = del_space(str_buf); + } + + if (str_buf == "true") + return true; + + return false; +} +template<> +std::string CommandLineParser::analyzeValue(const std::string& str, bool space_delete) +{ + if (space_delete) + { + return del_space(str); + } + return str; +} + +template<> +int CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) +{ + return fromStringNumber(str); +} + +template<> +unsigned int CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) +{ + return fromStringNumber(str); +} + +template<> +uint64 CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) +{ + return fromStringNumber(str); +} + +template<> +float CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) +{ + return fromStringNumber(str); +} + +template<> +double CommandLineParser::analyzeValue(const std::string& str, bool /*space_delete*/) +{ + return fromStringNumber(str); +} diff --git a/modules/core/src/command_line_parser.cpp b/modules/core/src/command_line_parser.cpp deleted file mode 100644 index b83a89902791e62f7148c1abdd00de30206d533f..0000000000000000000000000000000000000000 --- a/modules/core/src/command_line_parser.cpp +++ /dev/null @@ -1,540 +0,0 @@ - -#include "precomp.hpp" - -#include - -namespace cv -{ - -struct CommandLineParserParams -{ -public: - string help_message; - string def_value; - vector keys; - int number; -}; - - -struct CommandLineParser::Impl -{ - bool error; - string error_message; - string about_message; - - string path_to_app; - string app_name; - - vector data; - - Impl() { refcount = 1; } - Impl(int argc, const char* const argv[], const char* keys); - - vector split_range_string(const string& str, char fs, char ss) const; - vector split_string(const string& str, char symbol = ' ', bool create_empty_item = false) const; - string trim_spaces(const string& str) const; - - void apply_params(const string& key, const string& value); - void apply_params(int i, string value); - - void sort_params(); - int refcount; -}; - - -static string get_type_name(int type) -{ - if( type == Param::INT ) - return "int"; - if( type == Param::UNSIGNED_INT ) - return "unsigned"; - if( type == Param::UINT64 ) - return "unsigned long long"; - if( type == Param::FLOAT ) - return "float"; - if( type == Param::REAL ) - return "double"; - if( type == Param::STRING ) - return "string"; - return "unknown"; -} - -static void from_str(const string& str, int type, void* dst) -{ - std::stringstream ss(str); - if( type == Param::INT ) - ss >> *(int*)dst; - else if( type == Param::UNSIGNED_INT ) - ss >> *(unsigned*)dst; - else if( type == Param::UINT64 ) - ss >> *(uint64*)dst; - else if( type == Param::FLOAT ) - ss >> *(float*)dst; - else if( type == Param::REAL ) - ss >> *(double*)dst; - else if( type == Param::STRING ) - ss >> *(string*)dst; - else - throw cv::Exception(CV_StsBadArg, "unknown/unsupported parameter type", "", __FILE__, __LINE__); - - if (ss.fail()) - { - string err_msg = "can not convert: [" + str + - + "] to [" + get_type_name(type) + "]"; - - throw cv::Exception(CV_StsBadArg, err_msg, "", __FILE__, __LINE__); - } -} - -string CommandLineParser::getString(const string& name) -{ - for (size_t i = 0; i < impl->data.size(); i++) - { - for (size_t j = 0; j < impl->data[i].keys.size(); j++) - { - if (name.compare(impl->data[i].keys[j]) == 0) - { - string v = impl->data[i].def_value; - return v; - } - } - } - return string(); -} - -void CommandLineParser::getByName(const string& name, bool space_delete, int type, void* dst) const -{ - try - { - string v = ((CommandLineParser*)this)->getString(name); - if( v.empty() ) - { - impl->error = true; - impl->error_message += "Unknown parametes " + name + "\n"; - } - else - { - if (space_delete) - v = impl->trim_spaces(v); - from_str(v, type, dst); - return; - } - } - catch (std::exception& e) - { - impl->error = true; - impl->error_message += "Exception: " + string(e.what()) + "\n"; - } -} - - -void CommandLineParser::getByIndex(int index, bool space_delete, int type, void* dst) const -{ - try - { - for (size_t i = 0; i < impl->data.size(); i++) - { - if (impl->data[i].number == index) - { - string v = impl->data[i].def_value; - if (space_delete == true) v = impl->trim_spaces(v); - from_str(v, type, dst); - return; - } - } - impl->error = true; - impl->error_message += "Unknown parametes #" + format("%d", index) + "\n"; - } - catch(std::exception & e) - { - impl->error = true; - impl->error_message += "Exception: " + string(e.what()) + "\n"; - } -} - -static bool cmp_params(const CommandLineParserParams & p1, const CommandLineParserParams & p2) -{ - if (p1.number > p2.number) - return false; - - if (p1.number == -1 && p2.number == -1) - { - if (p1.keys[0].compare(p2.keys[0]) > 0) - { - return false; - } - } - - return true; -} - -CommandLineParser::CommandLineParser(int argc, const char* const argv[], const string& keys) -{ - impl = new Impl(argc, argv, keys.c_str()); -} - -CommandLineParser::CommandLineParser(int argc, const char* const argv[], const char* keys) -{ - impl = new Impl(argc, argv, keys); -} - -CommandLineParser::Impl::Impl(int argc, const char* const argv[], const char* keys) -{ - refcount = 1; - - // path to application - size_t pos_s = string(argv[0]).find_last_of("/\\"); - if (pos_s == string::npos) - { - path_to_app = ""; - app_name = string(argv[0]); - } - else - { - path_to_app = string(argv[0]).substr(0, pos_s); - app_name = string(argv[0]).substr(pos_s + 1, string(argv[0]).length() - pos_s); - } - - error = false; - error_message = ""; - - // parse keys - vector k = split_range_string(keys, '{', '}'); - - int jj = 0; - for (size_t i = 0; i < k.size(); i++) - { - vector l = split_string(k[i], '|', true); - CommandLineParserParams p; - p.keys = split_string(l[0]); - p.def_value = l[1]; - p.help_message = trim_spaces(l[2]); - p.number = -1; - if (p.keys[0][0] == '@') - { - p.number = jj; - jj++; - } - - data.push_back(p); - } - - // parse argv - jj = 0; - for (int i = 1; i < argc; i++) - { - string s = string(argv[i]); - - if (s.find('=') != string::npos && s.find('=') < s.length()) - { - vector k_v = split_string(s, '=', true); - for (int h = 0; h < 2; h++) - { - if (k_v[0][0] == '-') - k_v[0] = k_v[0].substr(1, k_v[0].length() -1); - } - apply_params(k_v[0], k_v[1]); - } - else if (s.length() > 1 && s[0] == '-') - { - for (int h = 0; h < 2; h++) - { - if (s[0] == '-') - s = s.substr(1, s.length() - 1); - } - apply_params(s, "true"); - } - else if (s[0] != '-') - { - apply_params(jj, s); - jj++; - } - } - - sort_params(); -} - - -CommandLineParser::CommandLineParser(const CommandLineParser& parser) -{ - impl = parser.impl; - CV_XADD(&impl->refcount, 1); -} - -CommandLineParser& CommandLineParser::operator = (const CommandLineParser& parser) -{ - if( this != &parser ) - { - if(CV_XADD(&impl->refcount, -1) == 1) - delete impl; - impl = parser.impl; - CV_XADD(&impl->refcount, 1); - } - return *this; -} - -void CommandLineParser::about(const string& message) -{ - impl->about_message = message; -} - -void CommandLineParser::Impl::apply_params(const string& key, const string& value) -{ - for (size_t i = 0; i < data.size(); i++) - { - for (size_t k = 0; k < data[i].keys.size(); k++) - { - if (key.compare(data[i].keys[k]) == 0) - { - data[i].def_value = value; - break; - } - } - } -} - -void CommandLineParser::Impl::apply_params(int i, string value) -{ - for (size_t j = 0; j < data.size(); j++) - { - if (data[j].number == i) - { - data[j].def_value = value; - break; - } - } -} - -void CommandLineParser::Impl::sort_params() -{ - for (size_t i = 0; i < data.size(); i++) - { - sort(data[i].keys.begin(), data[i].keys.end()); - } - - sort (data.begin(), data.end(), cmp_params); -} - -string CommandLineParser::Impl::trim_spaces(const string& str) const -{ - int left = 0, right = (int)str.length(); - while( left <= right && str[left] == ' ' ) - left++; - while( right > left && str[right-1] == ' ' ) - right--; - return left >= right ? string("") : str.substr(left, right-left); -} - -string CommandLineParser::getPathToApplication() const -{ - return impl->path_to_app; -} - -bool CommandLineParser::has(const string& name) -{ - for (size_t i = 0; i < impl->data.size(); i++) - { - for (size_t j = 0; j < impl->data[i].keys.size(); j++) - { - if (name.compare(impl->data[i].keys[j]) == 0 && string("true").compare(impl->data[i].def_value) == 0) - { - return true; - } - } - } - return false; -} - -bool CommandLineParser::check() const -{ - return impl->error == false; -} - -void CommandLineParser::printErrors() const -{ - if (impl->error) - { - std::cout << std::endl << "ERRORS:" << std::endl << impl->error_message << std::endl; - } -} - -void CommandLineParser::printParams() -{ - printMessage(); -} - -void CommandLineParser::printMessage() const -{ - if (impl->about_message != "") - std::cout << impl->about_message << std::endl; - - std::cout << "Usage: " << impl->app_name << " [params] "; - - for (size_t i = 0; i < impl->data.size(); i++) - { - if (impl->data[i].number > -1) - { - string name = impl->data[i].keys[0].substr(1, impl->data[i].keys[0].length() - 1); - std::cout << name << " "; - } - } - - std::cout << std::endl << std::endl; - - for (size_t i = 0; i < impl->data.size(); i++) - { - if (impl->data[i].number == -1) - { - std::cout << "\t"; - for (size_t j = 0; j < impl->data[i].keys.size(); j++) - { - string k = impl->data[i].keys[j]; - if (k.length() > 1) - { - std::cout << "--"; - } - else - { - std::cout << "-"; - } - std::cout << k; - - if (j != impl->data[i].keys.size() - 1) - { - std::cout << ", "; - } - } - string dv = impl->trim_spaces(impl->data[i].def_value); - if (dv.compare("") != 0) - { - std::cout << " (value:" << dv << ")"; - } - std::cout << std::endl << "\t\t" << impl->data[i].help_message << std::endl; - } - } - std::cout << std::endl; - - for (size_t i = 0; i < impl->data.size(); i++) - { - if (impl->data[i].number != -1) - { - std::cout << "\t"; - string k = impl->data[i].keys[0]; - k = k.substr(1, k.length() - 1); - - std::cout << k; - - string dv = impl->trim_spaces(impl->data[i].def_value); - if (dv.compare("") != 0) - { - std::cout << " (value:" << dv << ")"; - } - std::cout << std::endl << "\t\t" << impl->data[i].help_message << std::endl; - } - } -} - -vector CommandLineParser::Impl::split_range_string(const string& _str, char fs, char ss) const -{ - string str = _str; - vector vec; - string word = ""; - bool begin = false; - - while (!str.empty()) - { - if (str[0] == fs) - { - if (begin == true) - { - throw cv::Exception(CV_StsParseError, - string("error in split_range_string(") - + str - + string(", ") - + string(1, fs) - + string(", ") - + string(1, ss) - + string(")"), - "", __FILE__, __LINE__ - ); - } - begin = true; - word = ""; - str = str.substr(1, str.length() - 1); - } - - if (str[0] == ss) - { - if (begin == false) - { - throw cv::Exception(CV_StsParseError, - string("error in split_range_string(") - + str - + string(", ") - + string(1, fs) - + string(", ") - + string(1, ss) - + string(")"), - "", __FILE__, __LINE__ - ); - } - begin = false; - vec.push_back(word); - } - - if (begin == true) - { - word += str[0]; - } - str = str.substr(1, str.length() - 1); - } - - if (begin == true) - { - throw cv::Exception(CV_StsParseError, - string("error in split_range_string(") - + str - + string(", ") - + string(1, fs) - + string(", ") - + string(1, ss) - + string(")"), - "", __FILE__, __LINE__ - ); - } - - return vec; -} - -vector CommandLineParser::Impl::split_string(const string& _str, char symbol, bool create_empty_item) const -{ - string str = _str; - vector vec; - string word = ""; - - while (!str.empty()) - { - if (str[0] == symbol) - { - if (!word.empty() || create_empty_item) - { - vec.push_back(word); - word = ""; - } - } - else - { - word += str[0]; - } - str = str.substr(1, str.length() - 1); - } - - if (word != "" || create_empty_item) - { - vec.push_back(word); - } - - return vec; -} - -} diff --git a/modules/core/src/matmul.cpp b/modules/core/src/matmul.cpp index b71aead5300ac0c15952811531c5b8eb51466be8..b446e8b202409751a20b182ffdfe08e5faeddbcf 100644 --- a/modules/core/src/matmul.cpp +++ b/modules/core/src/matmul.cpp @@ -2900,7 +2900,7 @@ PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, int maxComp return *this; } -PCA& PCA::operator()(InputArray _data, InputArray __mean, int flags, double retainedVariance) +PCA& PCA::computeVar(InputArray _data, InputArray __mean, int flags, double retainedVariance) { Mat data = _data.getMat(), _mean = __mean.getMat(); int covar_flags = CV_COVAR_SCALE; @@ -3073,7 +3073,7 @@ void cv::PCACompute(InputArray data, InputOutputArray mean, pca.eigenvectors.copyTo(eigenvectors); } -void cv::PCACompute(InputArray data, InputOutputArray mean, +void cv::PCAComputeVar(InputArray data, InputOutputArray mean, OutputArray eigenvectors, double retainedVariance) { PCA pca; diff --git a/modules/core/src/parallel.cpp b/modules/core/src/parallel.cpp index 87bfbe9f5e96e5d33fd6a07bea75ab793169d313..3ba43884703a2e373e7f09fe6198b749b35332fe 100644 --- a/modules/core/src/parallel.cpp +++ b/modules/core/src/parallel.cpp @@ -312,6 +312,7 @@ int cv::getNumThreads(void) void cv::setNumThreads( int threads ) { + (void)threads; #ifdef HAVE_PARALLEL_FRAMEWORK numThreads = threads; #endif