openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/utility.hpp@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto | 0:0e0631af0305 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 2 | // |
RyoheiHagimoto | 0:0e0631af0305 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
RyoheiHagimoto | 0:0e0631af0305 | 4 | // |
RyoheiHagimoto | 0:0e0631af0305 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
RyoheiHagimoto | 0:0e0631af0305 | 6 | // If you do not agree to this license, do not download, install, |
RyoheiHagimoto | 0:0e0631af0305 | 7 | // copy or use the software. |
RyoheiHagimoto | 0:0e0631af0305 | 8 | // |
RyoheiHagimoto | 0:0e0631af0305 | 9 | // |
RyoheiHagimoto | 0:0e0631af0305 | 10 | // License Agreement |
RyoheiHagimoto | 0:0e0631af0305 | 11 | // For Open Source Computer Vision Library |
RyoheiHagimoto | 0:0e0631af0305 | 12 | // |
RyoheiHagimoto | 0:0e0631af0305 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 16 | // Copyright (C) 2015, Itseez Inc., all rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 17 | // Third party copyrights are property of their respective owners. |
RyoheiHagimoto | 0:0e0631af0305 | 18 | // |
RyoheiHagimoto | 0:0e0631af0305 | 19 | // Redistribution and use in source and binary forms, with or without modification, |
RyoheiHagimoto | 0:0e0631af0305 | 20 | // are permitted provided that the following conditions are met: |
RyoheiHagimoto | 0:0e0631af0305 | 21 | // |
RyoheiHagimoto | 0:0e0631af0305 | 22 | // * Redistribution's of source code must retain the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 23 | // this list of conditions and the following disclaimer. |
RyoheiHagimoto | 0:0e0631af0305 | 24 | // |
RyoheiHagimoto | 0:0e0631af0305 | 25 | // * Redistribution's in binary form must reproduce the above copyright notice, |
RyoheiHagimoto | 0:0e0631af0305 | 26 | // this list of conditions and the following disclaimer in the documentation |
RyoheiHagimoto | 0:0e0631af0305 | 27 | // and/or other materials provided with the distribution. |
RyoheiHagimoto | 0:0e0631af0305 | 28 | // |
RyoheiHagimoto | 0:0e0631af0305 | 29 | // * The name of the copyright holders may not be used to endorse or promote products |
RyoheiHagimoto | 0:0e0631af0305 | 30 | // derived from this software without specific prior written permission. |
RyoheiHagimoto | 0:0e0631af0305 | 31 | // |
RyoheiHagimoto | 0:0e0631af0305 | 32 | // This software is provided by the copyright holders and contributors "as is" and |
RyoheiHagimoto | 0:0e0631af0305 | 33 | // any express or implied warranties, including, but not limited to, the implied |
RyoheiHagimoto | 0:0e0631af0305 | 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
RyoheiHagimoto | 0:0e0631af0305 | 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
RyoheiHagimoto | 0:0e0631af0305 | 36 | // indirect, incidental, special, exemplary, or consequential damages |
RyoheiHagimoto | 0:0e0631af0305 | 37 | // (including, but not limited to, procurement of substitute goods or services; |
RyoheiHagimoto | 0:0e0631af0305 | 38 | // loss of use, data, or profits; or business interruption) however caused |
RyoheiHagimoto | 0:0e0631af0305 | 39 | // and on any theory of liability, whether in contract, strict liability, |
RyoheiHagimoto | 0:0e0631af0305 | 40 | // or tort (including negligence or otherwise) arising in any way out of |
RyoheiHagimoto | 0:0e0631af0305 | 41 | // the use of this software, even if advised of the possibility of such damage. |
RyoheiHagimoto | 0:0e0631af0305 | 42 | // |
RyoheiHagimoto | 0:0e0631af0305 | 43 | //M*/ |
RyoheiHagimoto | 0:0e0631af0305 | 44 | |
RyoheiHagimoto | 0:0e0631af0305 | 45 | #ifndef OPENCV_CORE_UTILITY_H |
RyoheiHagimoto | 0:0e0631af0305 | 46 | #define OPENCV_CORE_UTILITY_H |
RyoheiHagimoto | 0:0e0631af0305 | 47 | |
RyoheiHagimoto | 0:0e0631af0305 | 48 | #ifndef __cplusplus |
RyoheiHagimoto | 0:0e0631af0305 | 49 | # error utility.hpp header must be compiled as C++ |
RyoheiHagimoto | 0:0e0631af0305 | 50 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 51 | |
RyoheiHagimoto | 0:0e0631af0305 | 52 | #if defined(check) |
RyoheiHagimoto | 0:0e0631af0305 | 53 | # warning Detected Apple 'check' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. |
RyoheiHagimoto | 0:0e0631af0305 | 54 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 55 | |
RyoheiHagimoto | 0:0e0631af0305 | 56 | #include "opencv2/core.hpp" |
RyoheiHagimoto | 0:0e0631af0305 | 57 | |
RyoheiHagimoto | 0:0e0631af0305 | 58 | namespace cv |
RyoheiHagimoto | 0:0e0631af0305 | 59 | { |
RyoheiHagimoto | 0:0e0631af0305 | 60 | |
RyoheiHagimoto | 0:0e0631af0305 | 61 | #ifdef CV_COLLECT_IMPL_DATA |
RyoheiHagimoto | 0:0e0631af0305 | 62 | CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays |
RyoheiHagimoto | 0:0e0631af0305 | 63 | CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays |
RyoheiHagimoto | 0:0e0631af0305 | 64 | // Get stored implementation flags and fucntions names arrays |
RyoheiHagimoto | 0:0e0631af0305 | 65 | // Each implementation entry correspond to function name entry, so you can find which implementation was executed in which fucntion |
RyoheiHagimoto | 0:0e0631af0305 | 66 | CV_EXPORTS int getImpl(std::vector<int> &impl, std::vector<String> &funName); |
RyoheiHagimoto | 0:0e0631af0305 | 67 | |
RyoheiHagimoto | 0:0e0631af0305 | 68 | CV_EXPORTS bool useCollection(); // return implementation collection state |
RyoheiHagimoto | 0:0e0631af0305 | 69 | CV_EXPORTS void setUseCollection(bool flag); // set implementation collection state |
RyoheiHagimoto | 0:0e0631af0305 | 70 | |
RyoheiHagimoto | 0:0e0631af0305 | 71 | #define CV_IMPL_PLAIN 0x01 // native CPU OpenCV implementation |
RyoheiHagimoto | 0:0e0631af0305 | 72 | #define CV_IMPL_OCL 0x02 // OpenCL implementation |
RyoheiHagimoto | 0:0e0631af0305 | 73 | #define CV_IMPL_IPP 0x04 // IPP implementation |
RyoheiHagimoto | 0:0e0631af0305 | 74 | #define CV_IMPL_MT 0x10 // multithreaded implementation |
RyoheiHagimoto | 0:0e0631af0305 | 75 | |
RyoheiHagimoto | 0:0e0631af0305 | 76 | #define CV_IMPL_ADD(impl) \ |
RyoheiHagimoto | 0:0e0631af0305 | 77 | if(cv::useCollection()) \ |
RyoheiHagimoto | 0:0e0631af0305 | 78 | { \ |
RyoheiHagimoto | 0:0e0631af0305 | 79 | cv::addImpl(impl, CV_Func); \ |
RyoheiHagimoto | 0:0e0631af0305 | 80 | } |
RyoheiHagimoto | 0:0e0631af0305 | 81 | #else |
RyoheiHagimoto | 0:0e0631af0305 | 82 | #define CV_IMPL_ADD(impl) |
RyoheiHagimoto | 0:0e0631af0305 | 83 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 84 | |
RyoheiHagimoto | 0:0e0631af0305 | 85 | //! @addtogroup core_utils |
RyoheiHagimoto | 0:0e0631af0305 | 86 | //! @{ |
RyoheiHagimoto | 0:0e0631af0305 | 87 | |
RyoheiHagimoto | 0:0e0631af0305 | 88 | /** @brief Automatically Allocated Buffer Class |
RyoheiHagimoto | 0:0e0631af0305 | 89 | |
RyoheiHagimoto | 0:0e0631af0305 | 90 | The class is used for temporary buffers in functions and methods. |
RyoheiHagimoto | 0:0e0631af0305 | 91 | If a temporary buffer is usually small (a few K's of memory), |
RyoheiHagimoto | 0:0e0631af0305 | 92 | but its size depends on the parameters, it makes sense to create a small |
RyoheiHagimoto | 0:0e0631af0305 | 93 | fixed-size array on stack and use it if it's large enough. If the required buffer size |
RyoheiHagimoto | 0:0e0631af0305 | 94 | is larger than the fixed size, another buffer of sufficient size is allocated dynamically |
RyoheiHagimoto | 0:0e0631af0305 | 95 | and released after the processing. Therefore, in typical cases, when the buffer size is small, |
RyoheiHagimoto | 0:0e0631af0305 | 96 | there is no overhead associated with malloc()/free(). |
RyoheiHagimoto | 0:0e0631af0305 | 97 | At the same time, there is no limit on the size of processed data. |
RyoheiHagimoto | 0:0e0631af0305 | 98 | |
RyoheiHagimoto | 0:0e0631af0305 | 99 | This is what AutoBuffer does. The template takes 2 parameters - type of the buffer elements and |
RyoheiHagimoto | 0:0e0631af0305 | 100 | the number of stack-allocated elements. Here is how the class is used: |
RyoheiHagimoto | 0:0e0631af0305 | 101 | |
RyoheiHagimoto | 0:0e0631af0305 | 102 | \code |
RyoheiHagimoto | 0:0e0631af0305 | 103 | void my_func(const cv::Mat& m) |
RyoheiHagimoto | 0:0e0631af0305 | 104 | { |
RyoheiHagimoto | 0:0e0631af0305 | 105 | cv::AutoBuffer<float> buf; // create automatic buffer containing 1000 floats |
RyoheiHagimoto | 0:0e0631af0305 | 106 | |
RyoheiHagimoto | 0:0e0631af0305 | 107 | buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used, |
RyoheiHagimoto | 0:0e0631af0305 | 108 | // otherwise the buffer of "m.rows" floats will be allocated |
RyoheiHagimoto | 0:0e0631af0305 | 109 | // dynamically and deallocated in cv::AutoBuffer destructor |
RyoheiHagimoto | 0:0e0631af0305 | 110 | ... |
RyoheiHagimoto | 0:0e0631af0305 | 111 | } |
RyoheiHagimoto | 0:0e0631af0305 | 112 | \endcode |
RyoheiHagimoto | 0:0e0631af0305 | 113 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 114 | template<typename _Tp, size_t fixed_size = 1024/sizeof(_Tp)+8> class AutoBuffer |
RyoheiHagimoto | 0:0e0631af0305 | 115 | { |
RyoheiHagimoto | 0:0e0631af0305 | 116 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 117 | typedef _Tp value_type; |
RyoheiHagimoto | 0:0e0631af0305 | 118 | |
RyoheiHagimoto | 0:0e0631af0305 | 119 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 120 | AutoBuffer(); |
RyoheiHagimoto | 0:0e0631af0305 | 121 | //! constructor taking the real buffer size |
RyoheiHagimoto | 0:0e0631af0305 | 122 | AutoBuffer(size_t _size); |
RyoheiHagimoto | 0:0e0631af0305 | 123 | |
RyoheiHagimoto | 0:0e0631af0305 | 124 | //! the copy constructor |
RyoheiHagimoto | 0:0e0631af0305 | 125 | AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 126 | //! the assignment operator |
RyoheiHagimoto | 0:0e0631af0305 | 127 | AutoBuffer<_Tp, fixed_size>& operator = (const AutoBuffer<_Tp, fixed_size>& buf); |
RyoheiHagimoto | 0:0e0631af0305 | 128 | |
RyoheiHagimoto | 0:0e0631af0305 | 129 | //! destructor. calls deallocate() |
RyoheiHagimoto | 0:0e0631af0305 | 130 | ~AutoBuffer(); |
RyoheiHagimoto | 0:0e0631af0305 | 131 | |
RyoheiHagimoto | 0:0e0631af0305 | 132 | //! allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used |
RyoheiHagimoto | 0:0e0631af0305 | 133 | void allocate(size_t _size); |
RyoheiHagimoto | 0:0e0631af0305 | 134 | //! deallocates the buffer if it was dynamically allocated |
RyoheiHagimoto | 0:0e0631af0305 | 135 | void deallocate(); |
RyoheiHagimoto | 0:0e0631af0305 | 136 | //! resizes the buffer and preserves the content |
RyoheiHagimoto | 0:0e0631af0305 | 137 | void resize(size_t _size); |
RyoheiHagimoto | 0:0e0631af0305 | 138 | //! returns the current buffer size |
RyoheiHagimoto | 0:0e0631af0305 | 139 | size_t size() const; |
RyoheiHagimoto | 0:0e0631af0305 | 140 | //! returns pointer to the real buffer, stack-allocated or head-allocated |
RyoheiHagimoto | 0:0e0631af0305 | 141 | operator _Tp* (); |
RyoheiHagimoto | 0:0e0631af0305 | 142 | //! returns read-only pointer to the real buffer, stack-allocated or head-allocated |
RyoheiHagimoto | 0:0e0631af0305 | 143 | operator const _Tp* () const; |
RyoheiHagimoto | 0:0e0631af0305 | 144 | |
RyoheiHagimoto | 0:0e0631af0305 | 145 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 146 | //! pointer to the real buffer, can point to buf if the buffer is small enough |
RyoheiHagimoto | 0:0e0631af0305 | 147 | _Tp* ptr; |
RyoheiHagimoto | 0:0e0631af0305 | 148 | //! size of the real buffer |
RyoheiHagimoto | 0:0e0631af0305 | 149 | size_t sz; |
RyoheiHagimoto | 0:0e0631af0305 | 150 | //! pre-allocated buffer. At least 1 element to confirm C++ standard reqirements |
RyoheiHagimoto | 0:0e0631af0305 | 151 | _Tp buf[(fixed_size > 0) ? fixed_size : 1]; |
RyoheiHagimoto | 0:0e0631af0305 | 152 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 153 | |
RyoheiHagimoto | 0:0e0631af0305 | 154 | /** @brief Sets/resets the break-on-error mode. |
RyoheiHagimoto | 0:0e0631af0305 | 155 | |
RyoheiHagimoto | 0:0e0631af0305 | 156 | When the break-on-error mode is set, the default error handler issues a hardware exception, which |
RyoheiHagimoto | 0:0e0631af0305 | 157 | can make debugging more convenient. |
RyoheiHagimoto | 0:0e0631af0305 | 158 | |
RyoheiHagimoto | 0:0e0631af0305 | 159 | \return the previous state |
RyoheiHagimoto | 0:0e0631af0305 | 160 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 161 | CV_EXPORTS bool setBreakOnError(bool flag); |
RyoheiHagimoto | 0:0e0631af0305 | 162 | |
RyoheiHagimoto | 0:0e0631af0305 | 163 | extern "C" typedef int (*ErrorCallback)( int status, const char* func_name, |
RyoheiHagimoto | 0:0e0631af0305 | 164 | const char* err_msg, const char* file_name, |
RyoheiHagimoto | 0:0e0631af0305 | 165 | int line, void* userdata ); |
RyoheiHagimoto | 0:0e0631af0305 | 166 | |
RyoheiHagimoto | 0:0e0631af0305 | 167 | |
RyoheiHagimoto | 0:0e0631af0305 | 168 | /** @brief Sets the new error handler and the optional user data. |
RyoheiHagimoto | 0:0e0631af0305 | 169 | |
RyoheiHagimoto | 0:0e0631af0305 | 170 | The function sets the new error handler, called from cv::error(). |
RyoheiHagimoto | 0:0e0631af0305 | 171 | |
RyoheiHagimoto | 0:0e0631af0305 | 172 | \param errCallback the new error handler. If NULL, the default error handler is used. |
RyoheiHagimoto | 0:0e0631af0305 | 173 | \param userdata the optional user data pointer, passed to the callback. |
RyoheiHagimoto | 0:0e0631af0305 | 174 | \param prevUserdata the optional output parameter where the previous user data pointer is stored |
RyoheiHagimoto | 0:0e0631af0305 | 175 | |
RyoheiHagimoto | 0:0e0631af0305 | 176 | \return the previous error handler |
RyoheiHagimoto | 0:0e0631af0305 | 177 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 178 | CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdata=0, void** prevUserdata=0); |
RyoheiHagimoto | 0:0e0631af0305 | 179 | |
RyoheiHagimoto | 0:0e0631af0305 | 180 | /** @brief Returns a text string formatted using the printf-like expression. |
RyoheiHagimoto | 0:0e0631af0305 | 181 | |
RyoheiHagimoto | 0:0e0631af0305 | 182 | The function acts like sprintf but forms and returns an STL string. It can be used to form an error |
RyoheiHagimoto | 0:0e0631af0305 | 183 | message in the Exception constructor. |
RyoheiHagimoto | 0:0e0631af0305 | 184 | @param fmt printf-compatible formatting specifiers. |
RyoheiHagimoto | 0:0e0631af0305 | 185 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 186 | CV_EXPORTS String format( const char* fmt, ... ); |
RyoheiHagimoto | 0:0e0631af0305 | 187 | CV_EXPORTS String tempfile( const char* suffix = 0); |
RyoheiHagimoto | 0:0e0631af0305 | 188 | CV_EXPORTS void glob(String pattern, std::vector<String>& result, bool recursive = false); |
RyoheiHagimoto | 0:0e0631af0305 | 189 | |
RyoheiHagimoto | 0:0e0631af0305 | 190 | /** @brief OpenCV will try to set the number of threads for the next parallel region. |
RyoheiHagimoto | 0:0e0631af0305 | 191 | |
RyoheiHagimoto | 0:0e0631af0305 | 192 | If threads == 0, OpenCV will disable threading optimizations and run all it's functions |
RyoheiHagimoto | 0:0e0631af0305 | 193 | sequentially. Passing threads \< 0 will reset threads number to system default. This function must |
RyoheiHagimoto | 0:0e0631af0305 | 194 | be called outside of parallel region. |
RyoheiHagimoto | 0:0e0631af0305 | 195 | |
RyoheiHagimoto | 0:0e0631af0305 | 196 | OpenCV will try to run it's functions with specified threads number, but some behaviour differs from |
RyoheiHagimoto | 0:0e0631af0305 | 197 | framework: |
RyoheiHagimoto | 0:0e0631af0305 | 198 | - `TBB` – User-defined parallel constructions will run with the same threads number, if |
RyoheiHagimoto | 0:0e0631af0305 | 199 | another does not specified. If late on user creates own scheduler, OpenCV will be use it. |
RyoheiHagimoto | 0:0e0631af0305 | 200 | - `OpenMP` – No special defined behaviour. |
RyoheiHagimoto | 0:0e0631af0305 | 201 | - `Concurrency` – If threads == 1, OpenCV will disable threading optimizations and run it's |
RyoheiHagimoto | 0:0e0631af0305 | 202 | functions sequentially. |
RyoheiHagimoto | 0:0e0631af0305 | 203 | - `GCD` – Supports only values \<= 0. |
RyoheiHagimoto | 0:0e0631af0305 | 204 | - `C=` – No special defined behaviour. |
RyoheiHagimoto | 0:0e0631af0305 | 205 | @param nthreads Number of threads used by OpenCV. |
RyoheiHagimoto | 0:0e0631af0305 | 206 | @sa getNumThreads, getThreadNum |
RyoheiHagimoto | 0:0e0631af0305 | 207 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 208 | CV_EXPORTS_W void setNumThreads(int nthreads); |
RyoheiHagimoto | 0:0e0631af0305 | 209 | |
RyoheiHagimoto | 0:0e0631af0305 | 210 | /** @brief Returns the number of threads used by OpenCV for parallel regions. |
RyoheiHagimoto | 0:0e0631af0305 | 211 | |
RyoheiHagimoto | 0:0e0631af0305 | 212 | Always returns 1 if OpenCV is built without threading support. |
RyoheiHagimoto | 0:0e0631af0305 | 213 | |
RyoheiHagimoto | 0:0e0631af0305 | 214 | The exact meaning of return value depends on the threading framework used by OpenCV library: |
RyoheiHagimoto | 0:0e0631af0305 | 215 | - `TBB` – The number of threads, that OpenCV will try to use for parallel regions. If there is |
RyoheiHagimoto | 0:0e0631af0305 | 216 | any tbb::thread_scheduler_init in user code conflicting with OpenCV, then function returns |
RyoheiHagimoto | 0:0e0631af0305 | 217 | default number of threads used by TBB library. |
RyoheiHagimoto | 0:0e0631af0305 | 218 | - `OpenMP` – An upper bound on the number of threads that could be used to form a new team. |
RyoheiHagimoto | 0:0e0631af0305 | 219 | - `Concurrency` – The number of threads, that OpenCV will try to use for parallel regions. |
RyoheiHagimoto | 0:0e0631af0305 | 220 | - `GCD` – Unsupported; returns the GCD thread pool limit (512) for compatibility. |
RyoheiHagimoto | 0:0e0631af0305 | 221 | - `C=` – The number of threads, that OpenCV will try to use for parallel regions, if before |
RyoheiHagimoto | 0:0e0631af0305 | 222 | called setNumThreads with threads \> 0, otherwise returns the number of logical CPUs, |
RyoheiHagimoto | 0:0e0631af0305 | 223 | available for the process. |
RyoheiHagimoto | 0:0e0631af0305 | 224 | @sa setNumThreads, getThreadNum |
RyoheiHagimoto | 0:0e0631af0305 | 225 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 226 | CV_EXPORTS_W int getNumThreads(); |
RyoheiHagimoto | 0:0e0631af0305 | 227 | |
RyoheiHagimoto | 0:0e0631af0305 | 228 | /** @brief Returns the index of the currently executed thread within the current parallel region. Always |
RyoheiHagimoto | 0:0e0631af0305 | 229 | returns 0 if called outside of parallel region. |
RyoheiHagimoto | 0:0e0631af0305 | 230 | |
RyoheiHagimoto | 0:0e0631af0305 | 231 | The exact meaning of return value depends on the threading framework used by OpenCV library: |
RyoheiHagimoto | 0:0e0631af0305 | 232 | - `TBB` – Unsupported with current 4.1 TBB release. May be will be supported in future. |
RyoheiHagimoto | 0:0e0631af0305 | 233 | - `OpenMP` – The thread number, within the current team, of the calling thread. |
RyoheiHagimoto | 0:0e0631af0305 | 234 | - `Concurrency` – An ID for the virtual processor that the current context is executing on (0 |
RyoheiHagimoto | 0:0e0631af0305 | 235 | for master thread and unique number for others, but not necessary 1,2,3,...). |
RyoheiHagimoto | 0:0e0631af0305 | 236 | - `GCD` – System calling thread's ID. Never returns 0 inside parallel region. |
RyoheiHagimoto | 0:0e0631af0305 | 237 | - `C=` – The index of the current parallel task. |
RyoheiHagimoto | 0:0e0631af0305 | 238 | @sa setNumThreads, getNumThreads |
RyoheiHagimoto | 0:0e0631af0305 | 239 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 240 | CV_EXPORTS_W int getThreadNum(); |
RyoheiHagimoto | 0:0e0631af0305 | 241 | |
RyoheiHagimoto | 0:0e0631af0305 | 242 | /** @brief Returns full configuration time cmake output. |
RyoheiHagimoto | 0:0e0631af0305 | 243 | |
RyoheiHagimoto | 0:0e0631af0305 | 244 | Returned value is raw cmake output including version control system revision, compiler version, |
RyoheiHagimoto | 0:0e0631af0305 | 245 | compiler flags, enabled modules and third party libraries, etc. Output format depends on target |
RyoheiHagimoto | 0:0e0631af0305 | 246 | architecture. |
RyoheiHagimoto | 0:0e0631af0305 | 247 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 248 | CV_EXPORTS_W const String& getBuildInformation(); |
RyoheiHagimoto | 0:0e0631af0305 | 249 | |
RyoheiHagimoto | 0:0e0631af0305 | 250 | /** @brief Returns the number of ticks. |
RyoheiHagimoto | 0:0e0631af0305 | 251 | |
RyoheiHagimoto | 0:0e0631af0305 | 252 | The function returns the number of ticks after the certain event (for example, when the machine was |
RyoheiHagimoto | 0:0e0631af0305 | 253 | turned on). It can be used to initialize RNG or to measure a function execution time by reading the |
RyoheiHagimoto | 0:0e0631af0305 | 254 | tick count before and after the function call. |
RyoheiHagimoto | 0:0e0631af0305 | 255 | @sa getTickFrequency, TickMeter |
RyoheiHagimoto | 0:0e0631af0305 | 256 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 257 | CV_EXPORTS_W int64 getTickCount(); |
RyoheiHagimoto | 0:0e0631af0305 | 258 | |
RyoheiHagimoto | 0:0e0631af0305 | 259 | /** @brief Returns the number of ticks per second. |
RyoheiHagimoto | 0:0e0631af0305 | 260 | |
RyoheiHagimoto | 0:0e0631af0305 | 261 | The function returns the number of ticks per second. That is, the following code computes the |
RyoheiHagimoto | 0:0e0631af0305 | 262 | execution time in seconds: |
RyoheiHagimoto | 0:0e0631af0305 | 263 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 264 | double t = (double)getTickCount(); |
RyoheiHagimoto | 0:0e0631af0305 | 265 | // do something ... |
RyoheiHagimoto | 0:0e0631af0305 | 266 | t = ((double)getTickCount() - t)/getTickFrequency(); |
RyoheiHagimoto | 0:0e0631af0305 | 267 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 268 | @sa getTickCount, TickMeter |
RyoheiHagimoto | 0:0e0631af0305 | 269 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 270 | CV_EXPORTS_W double getTickFrequency(); |
RyoheiHagimoto | 0:0e0631af0305 | 271 | |
RyoheiHagimoto | 0:0e0631af0305 | 272 | /** @brief a Class to measure passing time. |
RyoheiHagimoto | 0:0e0631af0305 | 273 | |
RyoheiHagimoto | 0:0e0631af0305 | 274 | The class computes passing time by counting the number of ticks per second. That is, the following code computes the |
RyoheiHagimoto | 0:0e0631af0305 | 275 | execution time in seconds: |
RyoheiHagimoto | 0:0e0631af0305 | 276 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 277 | TickMeter tm; |
RyoheiHagimoto | 0:0e0631af0305 | 278 | tm.start(); |
RyoheiHagimoto | 0:0e0631af0305 | 279 | // do something ... |
RyoheiHagimoto | 0:0e0631af0305 | 280 | tm.stop(); |
RyoheiHagimoto | 0:0e0631af0305 | 281 | std::cout << tm.getTimeSec(); |
RyoheiHagimoto | 0:0e0631af0305 | 282 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 283 | @sa getTickCount, getTickFrequency |
RyoheiHagimoto | 0:0e0631af0305 | 284 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 285 | |
RyoheiHagimoto | 0:0e0631af0305 | 286 | class CV_EXPORTS_W TickMeter |
RyoheiHagimoto | 0:0e0631af0305 | 287 | { |
RyoheiHagimoto | 0:0e0631af0305 | 288 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 289 | //! the default constructor |
RyoheiHagimoto | 0:0e0631af0305 | 290 | CV_WRAP TickMeter() |
RyoheiHagimoto | 0:0e0631af0305 | 291 | { |
RyoheiHagimoto | 0:0e0631af0305 | 292 | reset(); |
RyoheiHagimoto | 0:0e0631af0305 | 293 | } |
RyoheiHagimoto | 0:0e0631af0305 | 294 | |
RyoheiHagimoto | 0:0e0631af0305 | 295 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 296 | starts counting ticks. |
RyoheiHagimoto | 0:0e0631af0305 | 297 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 298 | CV_WRAP void start() |
RyoheiHagimoto | 0:0e0631af0305 | 299 | { |
RyoheiHagimoto | 0:0e0631af0305 | 300 | startTime = cv::getTickCount(); |
RyoheiHagimoto | 0:0e0631af0305 | 301 | } |
RyoheiHagimoto | 0:0e0631af0305 | 302 | |
RyoheiHagimoto | 0:0e0631af0305 | 303 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 304 | stops counting ticks. |
RyoheiHagimoto | 0:0e0631af0305 | 305 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 306 | CV_WRAP void stop() |
RyoheiHagimoto | 0:0e0631af0305 | 307 | { |
RyoheiHagimoto | 0:0e0631af0305 | 308 | int64 time = cv::getTickCount(); |
RyoheiHagimoto | 0:0e0631af0305 | 309 | if (startTime == 0) |
RyoheiHagimoto | 0:0e0631af0305 | 310 | return; |
RyoheiHagimoto | 0:0e0631af0305 | 311 | ++counter; |
RyoheiHagimoto | 0:0e0631af0305 | 312 | sumTime += (time - startTime); |
RyoheiHagimoto | 0:0e0631af0305 | 313 | startTime = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 314 | } |
RyoheiHagimoto | 0:0e0631af0305 | 315 | |
RyoheiHagimoto | 0:0e0631af0305 | 316 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 317 | returns counted ticks. |
RyoheiHagimoto | 0:0e0631af0305 | 318 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 319 | CV_WRAP int64 getTimeTicks() const |
RyoheiHagimoto | 0:0e0631af0305 | 320 | { |
RyoheiHagimoto | 0:0e0631af0305 | 321 | return sumTime; |
RyoheiHagimoto | 0:0e0631af0305 | 322 | } |
RyoheiHagimoto | 0:0e0631af0305 | 323 | |
RyoheiHagimoto | 0:0e0631af0305 | 324 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 325 | returns passed time in microseconds. |
RyoheiHagimoto | 0:0e0631af0305 | 326 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 327 | CV_WRAP double getTimeMicro() const |
RyoheiHagimoto | 0:0e0631af0305 | 328 | { |
RyoheiHagimoto | 0:0e0631af0305 | 329 | return getTimeMilli()*1e3; |
RyoheiHagimoto | 0:0e0631af0305 | 330 | } |
RyoheiHagimoto | 0:0e0631af0305 | 331 | |
RyoheiHagimoto | 0:0e0631af0305 | 332 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 333 | returns passed time in milliseconds. |
RyoheiHagimoto | 0:0e0631af0305 | 334 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 335 | CV_WRAP double getTimeMilli() const |
RyoheiHagimoto | 0:0e0631af0305 | 336 | { |
RyoheiHagimoto | 0:0e0631af0305 | 337 | return getTimeSec()*1e3; |
RyoheiHagimoto | 0:0e0631af0305 | 338 | } |
RyoheiHagimoto | 0:0e0631af0305 | 339 | |
RyoheiHagimoto | 0:0e0631af0305 | 340 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 341 | returns passed time in seconds. |
RyoheiHagimoto | 0:0e0631af0305 | 342 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 343 | CV_WRAP double getTimeSec() const |
RyoheiHagimoto | 0:0e0631af0305 | 344 | { |
RyoheiHagimoto | 0:0e0631af0305 | 345 | return (double)getTimeTicks() / getTickFrequency(); |
RyoheiHagimoto | 0:0e0631af0305 | 346 | } |
RyoheiHagimoto | 0:0e0631af0305 | 347 | |
RyoheiHagimoto | 0:0e0631af0305 | 348 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 349 | returns internal counter value. |
RyoheiHagimoto | 0:0e0631af0305 | 350 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 351 | CV_WRAP int64 getCounter() const |
RyoheiHagimoto | 0:0e0631af0305 | 352 | { |
RyoheiHagimoto | 0:0e0631af0305 | 353 | return counter; |
RyoheiHagimoto | 0:0e0631af0305 | 354 | } |
RyoheiHagimoto | 0:0e0631af0305 | 355 | |
RyoheiHagimoto | 0:0e0631af0305 | 356 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 357 | resets internal values. |
RyoheiHagimoto | 0:0e0631af0305 | 358 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 359 | CV_WRAP void reset() |
RyoheiHagimoto | 0:0e0631af0305 | 360 | { |
RyoheiHagimoto | 0:0e0631af0305 | 361 | startTime = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 362 | sumTime = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 363 | counter = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 364 | } |
RyoheiHagimoto | 0:0e0631af0305 | 365 | |
RyoheiHagimoto | 0:0e0631af0305 | 366 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 367 | int64 counter; |
RyoheiHagimoto | 0:0e0631af0305 | 368 | int64 sumTime; |
RyoheiHagimoto | 0:0e0631af0305 | 369 | int64 startTime; |
RyoheiHagimoto | 0:0e0631af0305 | 370 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 371 | |
RyoheiHagimoto | 0:0e0631af0305 | 372 | /** @brief output operator |
RyoheiHagimoto | 0:0e0631af0305 | 373 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 374 | TickMeter tm; |
RyoheiHagimoto | 0:0e0631af0305 | 375 | tm.start(); |
RyoheiHagimoto | 0:0e0631af0305 | 376 | // do something ... |
RyoheiHagimoto | 0:0e0631af0305 | 377 | tm.stop(); |
RyoheiHagimoto | 0:0e0631af0305 | 378 | std::cout << tm; |
RyoheiHagimoto | 0:0e0631af0305 | 379 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 380 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 381 | |
RyoheiHagimoto | 0:0e0631af0305 | 382 | static inline |
RyoheiHagimoto | 0:0e0631af0305 | 383 | std::ostream& operator << (std::ostream& out, const TickMeter& tm) |
RyoheiHagimoto | 0:0e0631af0305 | 384 | { |
RyoheiHagimoto | 0:0e0631af0305 | 385 | return out << tm.getTimeSec() << "sec"; |
RyoheiHagimoto | 0:0e0631af0305 | 386 | } |
RyoheiHagimoto | 0:0e0631af0305 | 387 | |
RyoheiHagimoto | 0:0e0631af0305 | 388 | /** @brief Returns the number of CPU ticks. |
RyoheiHagimoto | 0:0e0631af0305 | 389 | |
RyoheiHagimoto | 0:0e0631af0305 | 390 | The function returns the current number of CPU ticks on some architectures (such as x86, x64, |
RyoheiHagimoto | 0:0e0631af0305 | 391 | PowerPC). On other platforms the function is equivalent to getTickCount. It can also be used for |
RyoheiHagimoto | 0:0e0631af0305 | 392 | very accurate time measurements, as well as for RNG initialization. Note that in case of multi-CPU |
RyoheiHagimoto | 0:0e0631af0305 | 393 | systems a thread, from which getCPUTickCount is called, can be suspended and resumed at another CPU |
RyoheiHagimoto | 0:0e0631af0305 | 394 | with its own counter. So, theoretically (and practically) the subsequent calls to the function do |
RyoheiHagimoto | 0:0e0631af0305 | 395 | not necessary return the monotonously increasing values. Also, since a modern CPU varies the CPU |
RyoheiHagimoto | 0:0e0631af0305 | 396 | frequency depending on the load, the number of CPU clocks spent in some code cannot be directly |
RyoheiHagimoto | 0:0e0631af0305 | 397 | converted to time units. Therefore, getTickCount is generally a preferable solution for measuring |
RyoheiHagimoto | 0:0e0631af0305 | 398 | execution time. |
RyoheiHagimoto | 0:0e0631af0305 | 399 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 400 | CV_EXPORTS_W int64 getCPUTickCount(); |
RyoheiHagimoto | 0:0e0631af0305 | 401 | |
RyoheiHagimoto | 0:0e0631af0305 | 402 | /** @brief Returns true if the specified feature is supported by the host hardware. |
RyoheiHagimoto | 0:0e0631af0305 | 403 | |
RyoheiHagimoto | 0:0e0631af0305 | 404 | The function returns true if the host hardware supports the specified feature. When user calls |
RyoheiHagimoto | 0:0e0631af0305 | 405 | setUseOptimized(false), the subsequent calls to checkHardwareSupport() will return false until |
RyoheiHagimoto | 0:0e0631af0305 | 406 | setUseOptimized(true) is called. This way user can dynamically switch on and off the optimized code |
RyoheiHagimoto | 0:0e0631af0305 | 407 | in OpenCV. |
RyoheiHagimoto | 0:0e0631af0305 | 408 | @param feature The feature of interest, one of cv::CpuFeatures |
RyoheiHagimoto | 0:0e0631af0305 | 409 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 410 | CV_EXPORTS_W bool checkHardwareSupport(int feature); |
RyoheiHagimoto | 0:0e0631af0305 | 411 | |
RyoheiHagimoto | 0:0e0631af0305 | 412 | /** @brief Returns the number of logical CPUs available for the process. |
RyoheiHagimoto | 0:0e0631af0305 | 413 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 414 | CV_EXPORTS_W int getNumberOfCPUs(); |
RyoheiHagimoto | 0:0e0631af0305 | 415 | |
RyoheiHagimoto | 0:0e0631af0305 | 416 | |
RyoheiHagimoto | 0:0e0631af0305 | 417 | /** @brief Aligns a pointer to the specified number of bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 418 | |
RyoheiHagimoto | 0:0e0631af0305 | 419 | The function returns the aligned pointer of the same type as the input pointer: |
RyoheiHagimoto | 0:0e0631af0305 | 420 | \f[\texttt{(_Tp*)(((size_t)ptr + n-1) & -n)}\f] |
RyoheiHagimoto | 0:0e0631af0305 | 421 | @param ptr Aligned pointer. |
RyoheiHagimoto | 0:0e0631af0305 | 422 | @param n Alignment size that must be a power of two. |
RyoheiHagimoto | 0:0e0631af0305 | 423 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 424 | template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp)) |
RyoheiHagimoto | 0:0e0631af0305 | 425 | { |
RyoheiHagimoto | 0:0e0631af0305 | 426 | return (_Tp*)(((size_t)ptr + n-1) & -n); |
RyoheiHagimoto | 0:0e0631af0305 | 427 | } |
RyoheiHagimoto | 0:0e0631af0305 | 428 | |
RyoheiHagimoto | 0:0e0631af0305 | 429 | /** @brief Aligns a buffer size to the specified number of bytes. |
RyoheiHagimoto | 0:0e0631af0305 | 430 | |
RyoheiHagimoto | 0:0e0631af0305 | 431 | The function returns the minimum number that is greater or equal to sz and is divisible by n : |
RyoheiHagimoto | 0:0e0631af0305 | 432 | \f[\texttt{(sz + n-1) & -n}\f] |
RyoheiHagimoto | 0:0e0631af0305 | 433 | @param sz Buffer size to align. |
RyoheiHagimoto | 0:0e0631af0305 | 434 | @param n Alignment size that must be a power of two. |
RyoheiHagimoto | 0:0e0631af0305 | 435 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 436 | static inline size_t alignSize(size_t sz, int n) |
RyoheiHagimoto | 0:0e0631af0305 | 437 | { |
RyoheiHagimoto | 0:0e0631af0305 | 438 | CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2 |
RyoheiHagimoto | 0:0e0631af0305 | 439 | return (sz + n-1) & -n; |
RyoheiHagimoto | 0:0e0631af0305 | 440 | } |
RyoheiHagimoto | 0:0e0631af0305 | 441 | |
RyoheiHagimoto | 0:0e0631af0305 | 442 | /** @brief Enables or disables the optimized code. |
RyoheiHagimoto | 0:0e0631af0305 | 443 | |
RyoheiHagimoto | 0:0e0631af0305 | 444 | The function can be used to dynamically turn on and off optimized code (code that uses SSE2, AVX, |
RyoheiHagimoto | 0:0e0631af0305 | 445 | and other instructions on the platforms that support it). It sets a global flag that is further |
RyoheiHagimoto | 0:0e0631af0305 | 446 | checked by OpenCV functions. Since the flag is not checked in the inner OpenCV loops, it is only |
RyoheiHagimoto | 0:0e0631af0305 | 447 | safe to call the function on the very top level in your application where you can be sure that no |
RyoheiHagimoto | 0:0e0631af0305 | 448 | other OpenCV function is currently executed. |
RyoheiHagimoto | 0:0e0631af0305 | 449 | |
RyoheiHagimoto | 0:0e0631af0305 | 450 | By default, the optimized code is enabled unless you disable it in CMake. The current status can be |
RyoheiHagimoto | 0:0e0631af0305 | 451 | retrieved using useOptimized. |
RyoheiHagimoto | 0:0e0631af0305 | 452 | @param onoff The boolean flag specifying whether the optimized code should be used (onoff=true) |
RyoheiHagimoto | 0:0e0631af0305 | 453 | or not (onoff=false). |
RyoheiHagimoto | 0:0e0631af0305 | 454 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 455 | CV_EXPORTS_W void setUseOptimized(bool onoff); |
RyoheiHagimoto | 0:0e0631af0305 | 456 | |
RyoheiHagimoto | 0:0e0631af0305 | 457 | /** @brief Returns the status of optimized code usage. |
RyoheiHagimoto | 0:0e0631af0305 | 458 | |
RyoheiHagimoto | 0:0e0631af0305 | 459 | The function returns true if the optimized code is enabled. Otherwise, it returns false. |
RyoheiHagimoto | 0:0e0631af0305 | 460 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 461 | CV_EXPORTS_W bool useOptimized(); |
RyoheiHagimoto | 0:0e0631af0305 | 462 | |
RyoheiHagimoto | 0:0e0631af0305 | 463 | static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); } |
RyoheiHagimoto | 0:0e0631af0305 | 464 | |
RyoheiHagimoto | 0:0e0631af0305 | 465 | /////////////////////////////// Parallel Primitives ////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 466 | |
RyoheiHagimoto | 0:0e0631af0305 | 467 | /** @brief Base class for parallel data processors |
RyoheiHagimoto | 0:0e0631af0305 | 468 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 469 | class CV_EXPORTS ParallelLoopBody |
RyoheiHagimoto | 0:0e0631af0305 | 470 | { |
RyoheiHagimoto | 0:0e0631af0305 | 471 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 472 | virtual ~ParallelLoopBody(); |
RyoheiHagimoto | 0:0e0631af0305 | 473 | virtual void operator() (const Range& range) const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 474 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 475 | |
RyoheiHagimoto | 0:0e0631af0305 | 476 | /** @brief Parallel data processor |
RyoheiHagimoto | 0:0e0631af0305 | 477 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 478 | CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.); |
RyoheiHagimoto | 0:0e0631af0305 | 479 | |
RyoheiHagimoto | 0:0e0631af0305 | 480 | /////////////////////////////// forEach method of cv::Mat //////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 481 | template<typename _Tp, typename Functor> inline |
RyoheiHagimoto | 0:0e0631af0305 | 482 | void Mat::forEach_impl(const Functor& operation) { |
RyoheiHagimoto | 0:0e0631af0305 | 483 | if (false) { |
RyoheiHagimoto | 0:0e0631af0305 | 484 | operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast<int*>(0)); |
RyoheiHagimoto | 0:0e0631af0305 | 485 | // If your compiler fail in this line. |
RyoheiHagimoto | 0:0e0631af0305 | 486 | // Please check that your functor signature is |
RyoheiHagimoto | 0:0e0631af0305 | 487 | // (_Tp&, const int*) <- multidimential |
RyoheiHagimoto | 0:0e0631af0305 | 488 | // or (_Tp&, void*) <- in case of you don't need current idx. |
RyoheiHagimoto | 0:0e0631af0305 | 489 | } |
RyoheiHagimoto | 0:0e0631af0305 | 490 | |
RyoheiHagimoto | 0:0e0631af0305 | 491 | CV_Assert(this->total() / this->size[this->dims - 1] <= INT_MAX); |
RyoheiHagimoto | 0:0e0631af0305 | 492 | const int LINES = static_cast<int>(this->total() / this->size[this->dims - 1]); |
RyoheiHagimoto | 0:0e0631af0305 | 493 | |
RyoheiHagimoto | 0:0e0631af0305 | 494 | class PixelOperationWrapper :public ParallelLoopBody |
RyoheiHagimoto | 0:0e0631af0305 | 495 | { |
RyoheiHagimoto | 0:0e0631af0305 | 496 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 497 | PixelOperationWrapper(Mat_<_Tp>* const frame, const Functor& _operation) |
RyoheiHagimoto | 0:0e0631af0305 | 498 | : mat(frame), op(_operation) {} |
RyoheiHagimoto | 0:0e0631af0305 | 499 | virtual ~PixelOperationWrapper(){} |
RyoheiHagimoto | 0:0e0631af0305 | 500 | // ! Overloaded virtual operator |
RyoheiHagimoto | 0:0e0631af0305 | 501 | // convert range call to row call. |
RyoheiHagimoto | 0:0e0631af0305 | 502 | virtual void operator()(const Range &range) const { |
RyoheiHagimoto | 0:0e0631af0305 | 503 | const int DIMS = mat->dims; |
RyoheiHagimoto | 0:0e0631af0305 | 504 | const int COLS = mat->size[DIMS - 1]; |
RyoheiHagimoto | 0:0e0631af0305 | 505 | if (DIMS <= 2) { |
RyoheiHagimoto | 0:0e0631af0305 | 506 | for (int row = range.start; row < range.end; ++row) { |
RyoheiHagimoto | 0:0e0631af0305 | 507 | this->rowCall2(row, COLS); |
RyoheiHagimoto | 0:0e0631af0305 | 508 | } |
RyoheiHagimoto | 0:0e0631af0305 | 509 | } else { |
RyoheiHagimoto | 0:0e0631af0305 | 510 | std::vector<int> idx(COLS); /// idx is modified in this->rowCall |
RyoheiHagimoto | 0:0e0631af0305 | 511 | idx[DIMS - 2] = range.start - 1; |
RyoheiHagimoto | 0:0e0631af0305 | 512 | |
RyoheiHagimoto | 0:0e0631af0305 | 513 | for (int line_num = range.start; line_num < range.end; ++line_num) { |
RyoheiHagimoto | 0:0e0631af0305 | 514 | idx[DIMS - 2]++; |
RyoheiHagimoto | 0:0e0631af0305 | 515 | for (int i = DIMS - 2; i >= 0; --i) { |
RyoheiHagimoto | 0:0e0631af0305 | 516 | if (idx[i] >= mat->size[i]) { |
RyoheiHagimoto | 0:0e0631af0305 | 517 | idx[i - 1] += idx[i] / mat->size[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 518 | idx[i] %= mat->size[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 519 | continue; // carry-over; |
RyoheiHagimoto | 0:0e0631af0305 | 520 | } |
RyoheiHagimoto | 0:0e0631af0305 | 521 | else { |
RyoheiHagimoto | 0:0e0631af0305 | 522 | break; |
RyoheiHagimoto | 0:0e0631af0305 | 523 | } |
RyoheiHagimoto | 0:0e0631af0305 | 524 | } |
RyoheiHagimoto | 0:0e0631af0305 | 525 | this->rowCall(&idx[0], COLS, DIMS); |
RyoheiHagimoto | 0:0e0631af0305 | 526 | } |
RyoheiHagimoto | 0:0e0631af0305 | 527 | } |
RyoheiHagimoto | 0:0e0631af0305 | 528 | } |
RyoheiHagimoto | 0:0e0631af0305 | 529 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 530 | Mat_<_Tp>* const mat; |
RyoheiHagimoto | 0:0e0631af0305 | 531 | const Functor op; |
RyoheiHagimoto | 0:0e0631af0305 | 532 | // ! Call operator for each elements in this row. |
RyoheiHagimoto | 0:0e0631af0305 | 533 | inline void rowCall(int* const idx, const int COLS, const int DIMS) const { |
RyoheiHagimoto | 0:0e0631af0305 | 534 | int &col = idx[DIMS - 1]; |
RyoheiHagimoto | 0:0e0631af0305 | 535 | col = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 536 | _Tp* pixel = &(mat->template at<_Tp>(idx)); |
RyoheiHagimoto | 0:0e0631af0305 | 537 | |
RyoheiHagimoto | 0:0e0631af0305 | 538 | while (col < COLS) { |
RyoheiHagimoto | 0:0e0631af0305 | 539 | op(*pixel, const_cast<const int*>(idx)); |
RyoheiHagimoto | 0:0e0631af0305 | 540 | pixel++; col++; |
RyoheiHagimoto | 0:0e0631af0305 | 541 | } |
RyoheiHagimoto | 0:0e0631af0305 | 542 | col = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 543 | } |
RyoheiHagimoto | 0:0e0631af0305 | 544 | // ! Call operator for each elements in this row. 2d mat special version. |
RyoheiHagimoto | 0:0e0631af0305 | 545 | inline void rowCall2(const int row, const int COLS) const { |
RyoheiHagimoto | 0:0e0631af0305 | 546 | union Index{ |
RyoheiHagimoto | 0:0e0631af0305 | 547 | int body[2]; |
RyoheiHagimoto | 0:0e0631af0305 | 548 | operator const int*() const { |
RyoheiHagimoto | 0:0e0631af0305 | 549 | return reinterpret_cast<const int*>(this); |
RyoheiHagimoto | 0:0e0631af0305 | 550 | } |
RyoheiHagimoto | 0:0e0631af0305 | 551 | int& operator[](const int i) { |
RyoheiHagimoto | 0:0e0631af0305 | 552 | return body[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 553 | } |
RyoheiHagimoto | 0:0e0631af0305 | 554 | } idx = {{row, 0}}; |
RyoheiHagimoto | 0:0e0631af0305 | 555 | // Special union is needed to avoid |
RyoheiHagimoto | 0:0e0631af0305 | 556 | // "error: array subscript is above array bounds [-Werror=array-bounds]" |
RyoheiHagimoto | 0:0e0631af0305 | 557 | // when call the functor `op` such that access idx[3]. |
RyoheiHagimoto | 0:0e0631af0305 | 558 | |
RyoheiHagimoto | 0:0e0631af0305 | 559 | _Tp* pixel = &(mat->template at<_Tp>(idx)); |
RyoheiHagimoto | 0:0e0631af0305 | 560 | const _Tp* const pixel_end = pixel + COLS; |
RyoheiHagimoto | 0:0e0631af0305 | 561 | while(pixel < pixel_end) { |
RyoheiHagimoto | 0:0e0631af0305 | 562 | op(*pixel++, static_cast<const int*>(idx)); |
RyoheiHagimoto | 0:0e0631af0305 | 563 | idx[1]++; |
RyoheiHagimoto | 0:0e0631af0305 | 564 | } |
RyoheiHagimoto | 0:0e0631af0305 | 565 | } |
RyoheiHagimoto | 0:0e0631af0305 | 566 | PixelOperationWrapper& operator=(const PixelOperationWrapper &) { |
RyoheiHagimoto | 0:0e0631af0305 | 567 | CV_Assert(false); |
RyoheiHagimoto | 0:0e0631af0305 | 568 | // We can not remove this implementation because Visual Studio warning C4822. |
RyoheiHagimoto | 0:0e0631af0305 | 569 | return *this; |
RyoheiHagimoto | 0:0e0631af0305 | 570 | } |
RyoheiHagimoto | 0:0e0631af0305 | 571 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 572 | |
RyoheiHagimoto | 0:0e0631af0305 | 573 | parallel_for_(cv::Range(0, LINES), PixelOperationWrapper(reinterpret_cast<Mat_<_Tp>*>(this), operation)); |
RyoheiHagimoto | 0:0e0631af0305 | 574 | } |
RyoheiHagimoto | 0:0e0631af0305 | 575 | |
RyoheiHagimoto | 0:0e0631af0305 | 576 | /////////////////////////// Synchronization Primitives /////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 577 | |
RyoheiHagimoto | 0:0e0631af0305 | 578 | class CV_EXPORTS Mutex |
RyoheiHagimoto | 0:0e0631af0305 | 579 | { |
RyoheiHagimoto | 0:0e0631af0305 | 580 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 581 | Mutex(); |
RyoheiHagimoto | 0:0e0631af0305 | 582 | ~Mutex(); |
RyoheiHagimoto | 0:0e0631af0305 | 583 | Mutex(const Mutex& m); |
RyoheiHagimoto | 0:0e0631af0305 | 584 | Mutex& operator = (const Mutex& m); |
RyoheiHagimoto | 0:0e0631af0305 | 585 | |
RyoheiHagimoto | 0:0e0631af0305 | 586 | void lock(); |
RyoheiHagimoto | 0:0e0631af0305 | 587 | bool trylock(); |
RyoheiHagimoto | 0:0e0631af0305 | 588 | void unlock(); |
RyoheiHagimoto | 0:0e0631af0305 | 589 | |
RyoheiHagimoto | 0:0e0631af0305 | 590 | struct Impl; |
RyoheiHagimoto | 0:0e0631af0305 | 591 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 592 | Impl* impl; |
RyoheiHagimoto | 0:0e0631af0305 | 593 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 594 | |
RyoheiHagimoto | 0:0e0631af0305 | 595 | class CV_EXPORTS AutoLock |
RyoheiHagimoto | 0:0e0631af0305 | 596 | { |
RyoheiHagimoto | 0:0e0631af0305 | 597 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 598 | AutoLock(Mutex& m) : mutex(&m) { mutex->lock(); } |
RyoheiHagimoto | 0:0e0631af0305 | 599 | ~AutoLock() { mutex->unlock(); } |
RyoheiHagimoto | 0:0e0631af0305 | 600 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 601 | Mutex* mutex; |
RyoheiHagimoto | 0:0e0631af0305 | 602 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 603 | AutoLock(const AutoLock&); |
RyoheiHagimoto | 0:0e0631af0305 | 604 | AutoLock& operator = (const AutoLock&); |
RyoheiHagimoto | 0:0e0631af0305 | 605 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 606 | |
RyoheiHagimoto | 0:0e0631af0305 | 607 | // TLS interface |
RyoheiHagimoto | 0:0e0631af0305 | 608 | class CV_EXPORTS TLSDataContainer |
RyoheiHagimoto | 0:0e0631af0305 | 609 | { |
RyoheiHagimoto | 0:0e0631af0305 | 610 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 611 | TLSDataContainer(); |
RyoheiHagimoto | 0:0e0631af0305 | 612 | virtual ~TLSDataContainer(); |
RyoheiHagimoto | 0:0e0631af0305 | 613 | |
RyoheiHagimoto | 0:0e0631af0305 | 614 | void gatherData(std::vector<void*> &data) const; |
RyoheiHagimoto | 0:0e0631af0305 | 615 | #if OPENCV_ABI_COMPATIBILITY > 300 |
RyoheiHagimoto | 0:0e0631af0305 | 616 | void* getData() const; |
RyoheiHagimoto | 0:0e0631af0305 | 617 | void release(); |
RyoheiHagimoto | 0:0e0631af0305 | 618 | |
RyoheiHagimoto | 0:0e0631af0305 | 619 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 620 | #else |
RyoheiHagimoto | 0:0e0631af0305 | 621 | void release(); |
RyoheiHagimoto | 0:0e0631af0305 | 622 | |
RyoheiHagimoto | 0:0e0631af0305 | 623 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 624 | void* getData() const; |
RyoheiHagimoto | 0:0e0631af0305 | 625 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 626 | virtual void* createDataInstance() const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 627 | virtual void deleteDataInstance(void* pData) const = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 628 | |
RyoheiHagimoto | 0:0e0631af0305 | 629 | int key_; |
RyoheiHagimoto | 0:0e0631af0305 | 630 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 631 | |
RyoheiHagimoto | 0:0e0631af0305 | 632 | // Main TLS data class |
RyoheiHagimoto | 0:0e0631af0305 | 633 | template <typename T> |
RyoheiHagimoto | 0:0e0631af0305 | 634 | class TLSData : protected TLSDataContainer |
RyoheiHagimoto | 0:0e0631af0305 | 635 | { |
RyoheiHagimoto | 0:0e0631af0305 | 636 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 637 | inline TLSData() {} |
RyoheiHagimoto | 0:0e0631af0305 | 638 | inline ~TLSData() { release(); } // Release key and delete associated data |
RyoheiHagimoto | 0:0e0631af0305 | 639 | inline T* get() const { return (T*)getData(); } // Get data assosiated with key |
RyoheiHagimoto | 0:0e0631af0305 | 640 | |
RyoheiHagimoto | 0:0e0631af0305 | 641 | // Get data from all threads |
RyoheiHagimoto | 0:0e0631af0305 | 642 | inline void gather(std::vector<T*> &data) const |
RyoheiHagimoto | 0:0e0631af0305 | 643 | { |
RyoheiHagimoto | 0:0e0631af0305 | 644 | std::vector<void*> &dataVoid = reinterpret_cast<std::vector<void*>&>(data); |
RyoheiHagimoto | 0:0e0631af0305 | 645 | gatherData(dataVoid); |
RyoheiHagimoto | 0:0e0631af0305 | 646 | } |
RyoheiHagimoto | 0:0e0631af0305 | 647 | |
RyoheiHagimoto | 0:0e0631af0305 | 648 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 649 | virtual void* createDataInstance() const {return new T;} // Wrapper to allocate data by template |
RyoheiHagimoto | 0:0e0631af0305 | 650 | virtual void deleteDataInstance(void* pData) const {delete (T*)pData;} // Wrapper to release data by template |
RyoheiHagimoto | 0:0e0631af0305 | 651 | |
RyoheiHagimoto | 0:0e0631af0305 | 652 | // Disable TLS copy operations |
RyoheiHagimoto | 0:0e0631af0305 | 653 | TLSData(TLSData &) {} |
RyoheiHagimoto | 0:0e0631af0305 | 654 | TLSData& operator =(const TLSData &) {return *this;} |
RyoheiHagimoto | 0:0e0631af0305 | 655 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 656 | |
RyoheiHagimoto | 0:0e0631af0305 | 657 | /** @brief Designed for command line parsing |
RyoheiHagimoto | 0:0e0631af0305 | 658 | |
RyoheiHagimoto | 0:0e0631af0305 | 659 | The sample below demonstrates how to use CommandLineParser: |
RyoheiHagimoto | 0:0e0631af0305 | 660 | @code |
RyoheiHagimoto | 0:0e0631af0305 | 661 | CommandLineParser parser(argc, argv, keys); |
RyoheiHagimoto | 0:0e0631af0305 | 662 | parser.about("Application name v1.0.0"); |
RyoheiHagimoto | 0:0e0631af0305 | 663 | |
RyoheiHagimoto | 0:0e0631af0305 | 664 | if (parser.has("help")) |
RyoheiHagimoto | 0:0e0631af0305 | 665 | { |
RyoheiHagimoto | 0:0e0631af0305 | 666 | parser.printMessage(); |
RyoheiHagimoto | 0:0e0631af0305 | 667 | return 0; |
RyoheiHagimoto | 0:0e0631af0305 | 668 | } |
RyoheiHagimoto | 0:0e0631af0305 | 669 | |
RyoheiHagimoto | 0:0e0631af0305 | 670 | int N = parser.get<int>("N"); |
RyoheiHagimoto | 0:0e0631af0305 | 671 | double fps = parser.get<double>("fps"); |
RyoheiHagimoto | 0:0e0631af0305 | 672 | String path = parser.get<String>("path"); |
RyoheiHagimoto | 0:0e0631af0305 | 673 | |
RyoheiHagimoto | 0:0e0631af0305 | 674 | use_time_stamp = parser.has("timestamp"); |
RyoheiHagimoto | 0:0e0631af0305 | 675 | |
RyoheiHagimoto | 0:0e0631af0305 | 676 | String img1 = parser.get<String>(0); |
RyoheiHagimoto | 0:0e0631af0305 | 677 | String img2 = parser.get<String>(1); |
RyoheiHagimoto | 0:0e0631af0305 | 678 | |
RyoheiHagimoto | 0:0e0631af0305 | 679 | int repeat = parser.get<int>(2); |
RyoheiHagimoto | 0:0e0631af0305 | 680 | |
RyoheiHagimoto | 0:0e0631af0305 | 681 | if (!parser.check()) |
RyoheiHagimoto | 0:0e0631af0305 | 682 | { |
RyoheiHagimoto | 0:0e0631af0305 | 683 | parser.printErrors(); |
RyoheiHagimoto | 0:0e0631af0305 | 684 | return 0; |
RyoheiHagimoto | 0:0e0631af0305 | 685 | } |
RyoheiHagimoto | 0:0e0631af0305 | 686 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 687 | |
RyoheiHagimoto | 0:0e0631af0305 | 688 | ### Keys syntax |
RyoheiHagimoto | 0:0e0631af0305 | 689 | |
RyoheiHagimoto | 0:0e0631af0305 | 690 | The keys parameter is a string containing several blocks, each one is enclosed in curley braces and |
RyoheiHagimoto | 0:0e0631af0305 | 691 | describes one argument. Each argument contains three parts separated by the `|` symbol: |
RyoheiHagimoto | 0:0e0631af0305 | 692 | |
RyoheiHagimoto | 0:0e0631af0305 | 693 | -# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the `@` symbol) |
RyoheiHagimoto | 0:0e0631af0305 | 694 | -# default value will be used if the argument was not provided (can be empty) |
RyoheiHagimoto | 0:0e0631af0305 | 695 | -# help message (can be empty) |
RyoheiHagimoto | 0:0e0631af0305 | 696 | |
RyoheiHagimoto | 0:0e0631af0305 | 697 | For example: |
RyoheiHagimoto | 0:0e0631af0305 | 698 | |
RyoheiHagimoto | 0:0e0631af0305 | 699 | @code{.cpp} |
RyoheiHagimoto | 0:0e0631af0305 | 700 | const String keys = |
RyoheiHagimoto | 0:0e0631af0305 | 701 | "{help h usage ? | | print this message }" |
RyoheiHagimoto | 0:0e0631af0305 | 702 | "{@image1 | | image1 for compare }" |
RyoheiHagimoto | 0:0e0631af0305 | 703 | "{@image2 |<none>| image2 for compare }" |
RyoheiHagimoto | 0:0e0631af0305 | 704 | "{@repeat |1 | number }" |
RyoheiHagimoto | 0:0e0631af0305 | 705 | "{path |. | path to file }" |
RyoheiHagimoto | 0:0e0631af0305 | 706 | "{fps | -1.0 | fps for output video }" |
RyoheiHagimoto | 0:0e0631af0305 | 707 | "{N count |100 | count of objects }" |
RyoheiHagimoto | 0:0e0631af0305 | 708 | "{ts timestamp | | use time stamp }" |
RyoheiHagimoto | 0:0e0631af0305 | 709 | ; |
RyoheiHagimoto | 0:0e0631af0305 | 710 | } |
RyoheiHagimoto | 0:0e0631af0305 | 711 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 712 | |
RyoheiHagimoto | 0:0e0631af0305 | 713 | Note that there are no default values for `help` and `timestamp` so we can check their presence using the `has()` method. |
RyoheiHagimoto | 0:0e0631af0305 | 714 | Arguments with default values are considered to be always present. Use the `get()` method in these cases to check their |
RyoheiHagimoto | 0:0e0631af0305 | 715 | actual value instead. |
RyoheiHagimoto | 0:0e0631af0305 | 716 | |
RyoheiHagimoto | 0:0e0631af0305 | 717 | String keys like `get<String>("@image1")` return the empty string `""` by default - even with an empty default value. |
RyoheiHagimoto | 0:0e0631af0305 | 718 | Use the special `<none>` default value to enforce that the returned string must not be empty. (like in `get<String>("@image2")`) |
RyoheiHagimoto | 0:0e0631af0305 | 719 | |
RyoheiHagimoto | 0:0e0631af0305 | 720 | ### Usage |
RyoheiHagimoto | 0:0e0631af0305 | 721 | |
RyoheiHagimoto | 0:0e0631af0305 | 722 | For the described keys: |
RyoheiHagimoto | 0:0e0631af0305 | 723 | |
RyoheiHagimoto | 0:0e0631af0305 | 724 | @code{.sh} |
RyoheiHagimoto | 0:0e0631af0305 | 725 | # Good call (3 positional parameters: image1, image2 and repeat; N is 200, ts is true) |
RyoheiHagimoto | 0:0e0631af0305 | 726 | $ ./app -N=200 1.png 2.jpg 19 -ts |
RyoheiHagimoto | 0:0e0631af0305 | 727 | |
RyoheiHagimoto | 0:0e0631af0305 | 728 | # Bad call |
RyoheiHagimoto | 0:0e0631af0305 | 729 | $ ./app -fps=aaa |
RyoheiHagimoto | 0:0e0631af0305 | 730 | ERRORS: |
RyoheiHagimoto | 0:0e0631af0305 | 731 | Parameter 'fps': can not convert: [aaa] to [double] |
RyoheiHagimoto | 0:0e0631af0305 | 732 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 733 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 734 | class CV_EXPORTS CommandLineParser |
RyoheiHagimoto | 0:0e0631af0305 | 735 | { |
RyoheiHagimoto | 0:0e0631af0305 | 736 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 737 | |
RyoheiHagimoto | 0:0e0631af0305 | 738 | /** @brief Constructor |
RyoheiHagimoto | 0:0e0631af0305 | 739 | |
RyoheiHagimoto | 0:0e0631af0305 | 740 | Initializes command line parser object |
RyoheiHagimoto | 0:0e0631af0305 | 741 | |
RyoheiHagimoto | 0:0e0631af0305 | 742 | @param argc number of command line arguments (from main()) |
RyoheiHagimoto | 0:0e0631af0305 | 743 | @param argv array of command line arguments (from main()) |
RyoheiHagimoto | 0:0e0631af0305 | 744 | @param keys string describing acceptable command line parameters (see class description for syntax) |
RyoheiHagimoto | 0:0e0631af0305 | 745 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 746 | CommandLineParser(int argc, const char* const argv[], const String& keys); |
RyoheiHagimoto | 0:0e0631af0305 | 747 | |
RyoheiHagimoto | 0:0e0631af0305 | 748 | /** @brief Copy constructor */ |
RyoheiHagimoto | 0:0e0631af0305 | 749 | CommandLineParser(const CommandLineParser& parser); |
RyoheiHagimoto | 0:0e0631af0305 | 750 | |
RyoheiHagimoto | 0:0e0631af0305 | 751 | /** @brief Assignment operator */ |
RyoheiHagimoto | 0:0e0631af0305 | 752 | CommandLineParser& operator = (const CommandLineParser& parser); |
RyoheiHagimoto | 0:0e0631af0305 | 753 | |
RyoheiHagimoto | 0:0e0631af0305 | 754 | /** @brief Destructor */ |
RyoheiHagimoto | 0:0e0631af0305 | 755 | ~CommandLineParser(); |
RyoheiHagimoto | 0:0e0631af0305 | 756 | |
RyoheiHagimoto | 0:0e0631af0305 | 757 | /** @brief Returns application path |
RyoheiHagimoto | 0:0e0631af0305 | 758 | |
RyoheiHagimoto | 0:0e0631af0305 | 759 | This method returns the path to the executable from the command line (`argv[0]`). |
RyoheiHagimoto | 0:0e0631af0305 | 760 | |
RyoheiHagimoto | 0:0e0631af0305 | 761 | For example, if the application has been started with such command: |
RyoheiHagimoto | 0:0e0631af0305 | 762 | @code{.sh} |
RyoheiHagimoto | 0:0e0631af0305 | 763 | $ ./bin/my-executable |
RyoheiHagimoto | 0:0e0631af0305 | 764 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 765 | this method will return `./bin`. |
RyoheiHagimoto | 0:0e0631af0305 | 766 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 767 | String getPathToApplication() const; |
RyoheiHagimoto | 0:0e0631af0305 | 768 | |
RyoheiHagimoto | 0:0e0631af0305 | 769 | /** @brief Access arguments by name |
RyoheiHagimoto | 0:0e0631af0305 | 770 | |
RyoheiHagimoto | 0:0e0631af0305 | 771 | Returns argument converted to selected type. If the argument is not known or can not be |
RyoheiHagimoto | 0:0e0631af0305 | 772 | converted to selected type, the error flag is set (can be checked with @ref check). |
RyoheiHagimoto | 0:0e0631af0305 | 773 | |
RyoheiHagimoto | 0:0e0631af0305 | 774 | For example, define: |
RyoheiHagimoto | 0:0e0631af0305 | 775 | @code{.cpp} |
RyoheiHagimoto | 0:0e0631af0305 | 776 | String keys = "{N count||}"; |
RyoheiHagimoto | 0:0e0631af0305 | 777 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 778 | |
RyoheiHagimoto | 0:0e0631af0305 | 779 | Call: |
RyoheiHagimoto | 0:0e0631af0305 | 780 | @code{.sh} |
RyoheiHagimoto | 0:0e0631af0305 | 781 | $ ./my-app -N=20 |
RyoheiHagimoto | 0:0e0631af0305 | 782 | # or |
RyoheiHagimoto | 0:0e0631af0305 | 783 | $ ./my-app --count=20 |
RyoheiHagimoto | 0:0e0631af0305 | 784 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 785 | |
RyoheiHagimoto | 0:0e0631af0305 | 786 | Access: |
RyoheiHagimoto | 0:0e0631af0305 | 787 | @code{.cpp} |
RyoheiHagimoto | 0:0e0631af0305 | 788 | int N = parser.get<int>("N"); |
RyoheiHagimoto | 0:0e0631af0305 | 789 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 790 | |
RyoheiHagimoto | 0:0e0631af0305 | 791 | @param name name of the argument |
RyoheiHagimoto | 0:0e0631af0305 | 792 | @param space_delete remove spaces from the left and right of the string |
RyoheiHagimoto | 0:0e0631af0305 | 793 | @tparam T the argument will be converted to this type if possible |
RyoheiHagimoto | 0:0e0631af0305 | 794 | |
RyoheiHagimoto | 0:0e0631af0305 | 795 | @note You can access positional arguments by their `@`-prefixed name: |
RyoheiHagimoto | 0:0e0631af0305 | 796 | @code{.cpp} |
RyoheiHagimoto | 0:0e0631af0305 | 797 | parser.get<String>("@image"); |
RyoheiHagimoto | 0:0e0631af0305 | 798 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 799 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 800 | template <typename T> |
RyoheiHagimoto | 0:0e0631af0305 | 801 | T get(const String& name, bool space_delete = true) const |
RyoheiHagimoto | 0:0e0631af0305 | 802 | { |
RyoheiHagimoto | 0:0e0631af0305 | 803 | T val = T(); |
RyoheiHagimoto | 0:0e0631af0305 | 804 | getByName(name, space_delete, ParamType<T>::type, (void*)&val); |
RyoheiHagimoto | 0:0e0631af0305 | 805 | return val; |
RyoheiHagimoto | 0:0e0631af0305 | 806 | } |
RyoheiHagimoto | 0:0e0631af0305 | 807 | |
RyoheiHagimoto | 0:0e0631af0305 | 808 | /** @brief Access positional arguments by index |
RyoheiHagimoto | 0:0e0631af0305 | 809 | |
RyoheiHagimoto | 0:0e0631af0305 | 810 | Returns argument converted to selected type. Indexes are counted from zero. |
RyoheiHagimoto | 0:0e0631af0305 | 811 | |
RyoheiHagimoto | 0:0e0631af0305 | 812 | For example, define: |
RyoheiHagimoto | 0:0e0631af0305 | 813 | @code{.cpp} |
RyoheiHagimoto | 0:0e0631af0305 | 814 | String keys = "{@arg1||}{@arg2||}" |
RyoheiHagimoto | 0:0e0631af0305 | 815 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 816 | |
RyoheiHagimoto | 0:0e0631af0305 | 817 | Call: |
RyoheiHagimoto | 0:0e0631af0305 | 818 | @code{.sh} |
RyoheiHagimoto | 0:0e0631af0305 | 819 | ./my-app abc qwe |
RyoheiHagimoto | 0:0e0631af0305 | 820 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 821 | |
RyoheiHagimoto | 0:0e0631af0305 | 822 | Access arguments: |
RyoheiHagimoto | 0:0e0631af0305 | 823 | @code{.cpp} |
RyoheiHagimoto | 0:0e0631af0305 | 824 | String val_1 = parser.get<String>(0); // returns "abc", arg1 |
RyoheiHagimoto | 0:0e0631af0305 | 825 | String val_2 = parser.get<String>(1); // returns "qwe", arg2 |
RyoheiHagimoto | 0:0e0631af0305 | 826 | @endcode |
RyoheiHagimoto | 0:0e0631af0305 | 827 | |
RyoheiHagimoto | 0:0e0631af0305 | 828 | @param index index of the argument |
RyoheiHagimoto | 0:0e0631af0305 | 829 | @param space_delete remove spaces from the left and right of the string |
RyoheiHagimoto | 0:0e0631af0305 | 830 | @tparam T the argument will be converted to this type if possible |
RyoheiHagimoto | 0:0e0631af0305 | 831 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 832 | template <typename T> |
RyoheiHagimoto | 0:0e0631af0305 | 833 | T get(int index, bool space_delete = true) const |
RyoheiHagimoto | 0:0e0631af0305 | 834 | { |
RyoheiHagimoto | 0:0e0631af0305 | 835 | T val = T(); |
RyoheiHagimoto | 0:0e0631af0305 | 836 | getByIndex(index, space_delete, ParamType<T>::type, (void*)&val); |
RyoheiHagimoto | 0:0e0631af0305 | 837 | return val; |
RyoheiHagimoto | 0:0e0631af0305 | 838 | } |
RyoheiHagimoto | 0:0e0631af0305 | 839 | |
RyoheiHagimoto | 0:0e0631af0305 | 840 | /** @brief Check if field was provided in the command line |
RyoheiHagimoto | 0:0e0631af0305 | 841 | |
RyoheiHagimoto | 0:0e0631af0305 | 842 | @param name argument name to check |
RyoheiHagimoto | 0:0e0631af0305 | 843 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 844 | bool has(const String& name) const; |
RyoheiHagimoto | 0:0e0631af0305 | 845 | |
RyoheiHagimoto | 0:0e0631af0305 | 846 | /** @brief Check for parsing errors |
RyoheiHagimoto | 0:0e0631af0305 | 847 | |
RyoheiHagimoto | 0:0e0631af0305 | 848 | Returns true if error occured while accessing the parameters (bad conversion, missing arguments, |
RyoheiHagimoto | 0:0e0631af0305 | 849 | etc.). Call @ref printErrors to print error messages list. |
RyoheiHagimoto | 0:0e0631af0305 | 850 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 851 | bool check() const; |
RyoheiHagimoto | 0:0e0631af0305 | 852 | |
RyoheiHagimoto | 0:0e0631af0305 | 853 | /** @brief Set the about message |
RyoheiHagimoto | 0:0e0631af0305 | 854 | |
RyoheiHagimoto | 0:0e0631af0305 | 855 | The about message will be shown when @ref printMessage is called, right before arguments table. |
RyoheiHagimoto | 0:0e0631af0305 | 856 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 857 | void about(const String& message); |
RyoheiHagimoto | 0:0e0631af0305 | 858 | |
RyoheiHagimoto | 0:0e0631af0305 | 859 | /** @brief Print help message |
RyoheiHagimoto | 0:0e0631af0305 | 860 | |
RyoheiHagimoto | 0:0e0631af0305 | 861 | This method will print standard help message containing the about message and arguments description. |
RyoheiHagimoto | 0:0e0631af0305 | 862 | |
RyoheiHagimoto | 0:0e0631af0305 | 863 | @sa about |
RyoheiHagimoto | 0:0e0631af0305 | 864 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 865 | void printMessage() const; |
RyoheiHagimoto | 0:0e0631af0305 | 866 | |
RyoheiHagimoto | 0:0e0631af0305 | 867 | /** @brief Print list of errors occured |
RyoheiHagimoto | 0:0e0631af0305 | 868 | |
RyoheiHagimoto | 0:0e0631af0305 | 869 | @sa check |
RyoheiHagimoto | 0:0e0631af0305 | 870 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 871 | void printErrors() const; |
RyoheiHagimoto | 0:0e0631af0305 | 872 | |
RyoheiHagimoto | 0:0e0631af0305 | 873 | protected: |
RyoheiHagimoto | 0:0e0631af0305 | 874 | void getByName(const String& name, bool space_delete, int type, void* dst) const; |
RyoheiHagimoto | 0:0e0631af0305 | 875 | void getByIndex(int index, bool space_delete, int type, void* dst) const; |
RyoheiHagimoto | 0:0e0631af0305 | 876 | |
RyoheiHagimoto | 0:0e0631af0305 | 877 | struct Impl; |
RyoheiHagimoto | 0:0e0631af0305 | 878 | Impl* impl; |
RyoheiHagimoto | 0:0e0631af0305 | 879 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 880 | |
RyoheiHagimoto | 0:0e0631af0305 | 881 | //! @} core_utils |
RyoheiHagimoto | 0:0e0631af0305 | 882 | |
RyoheiHagimoto | 0:0e0631af0305 | 883 | //! @cond IGNORED |
RyoheiHagimoto | 0:0e0631af0305 | 884 | |
RyoheiHagimoto | 0:0e0631af0305 | 885 | /////////////////////////////// AutoBuffer implementation //////////////////////////////////////// |
RyoheiHagimoto | 0:0e0631af0305 | 886 | |
RyoheiHagimoto | 0:0e0631af0305 | 887 | template<typename _Tp, size_t fixed_size> inline |
RyoheiHagimoto | 0:0e0631af0305 | 888 | AutoBuffer<_Tp, fixed_size>::AutoBuffer() |
RyoheiHagimoto | 0:0e0631af0305 | 889 | { |
RyoheiHagimoto | 0:0e0631af0305 | 890 | ptr = buf; |
RyoheiHagimoto | 0:0e0631af0305 | 891 | sz = fixed_size; |
RyoheiHagimoto | 0:0e0631af0305 | 892 | } |
RyoheiHagimoto | 0:0e0631af0305 | 893 | |
RyoheiHagimoto | 0:0e0631af0305 | 894 | template<typename _Tp, size_t fixed_size> inline |
RyoheiHagimoto | 0:0e0631af0305 | 895 | AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size) |
RyoheiHagimoto | 0:0e0631af0305 | 896 | { |
RyoheiHagimoto | 0:0e0631af0305 | 897 | ptr = buf; |
RyoheiHagimoto | 0:0e0631af0305 | 898 | sz = fixed_size; |
RyoheiHagimoto | 0:0e0631af0305 | 899 | allocate(_size); |
RyoheiHagimoto | 0:0e0631af0305 | 900 | } |
RyoheiHagimoto | 0:0e0631af0305 | 901 | |
RyoheiHagimoto | 0:0e0631af0305 | 902 | template<typename _Tp, size_t fixed_size> inline |
RyoheiHagimoto | 0:0e0631af0305 | 903 | AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf ) |
RyoheiHagimoto | 0:0e0631af0305 | 904 | { |
RyoheiHagimoto | 0:0e0631af0305 | 905 | ptr = buf; |
RyoheiHagimoto | 0:0e0631af0305 | 906 | sz = fixed_size; |
RyoheiHagimoto | 0:0e0631af0305 | 907 | allocate(abuf.size()); |
RyoheiHagimoto | 0:0e0631af0305 | 908 | for( size_t i = 0; i < sz; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 909 | ptr[i] = abuf.ptr[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 910 | } |
RyoheiHagimoto | 0:0e0631af0305 | 911 | |
RyoheiHagimoto | 0:0e0631af0305 | 912 | template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>& |
RyoheiHagimoto | 0:0e0631af0305 | 913 | AutoBuffer<_Tp, fixed_size>::operator = (const AutoBuffer<_Tp, fixed_size>& abuf) |
RyoheiHagimoto | 0:0e0631af0305 | 914 | { |
RyoheiHagimoto | 0:0e0631af0305 | 915 | if( this != &abuf ) |
RyoheiHagimoto | 0:0e0631af0305 | 916 | { |
RyoheiHagimoto | 0:0e0631af0305 | 917 | deallocate(); |
RyoheiHagimoto | 0:0e0631af0305 | 918 | allocate(abuf.size()); |
RyoheiHagimoto | 0:0e0631af0305 | 919 | for( size_t i = 0; i < sz; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 920 | ptr[i] = abuf.ptr[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 921 | } |
RyoheiHagimoto | 0:0e0631af0305 | 922 | return *this; |
RyoheiHagimoto | 0:0e0631af0305 | 923 | } |
RyoheiHagimoto | 0:0e0631af0305 | 924 | |
RyoheiHagimoto | 0:0e0631af0305 | 925 | template<typename _Tp, size_t fixed_size> inline |
RyoheiHagimoto | 0:0e0631af0305 | 926 | AutoBuffer<_Tp, fixed_size>::~AutoBuffer() |
RyoheiHagimoto | 0:0e0631af0305 | 927 | { deallocate(); } |
RyoheiHagimoto | 0:0e0631af0305 | 928 | |
RyoheiHagimoto | 0:0e0631af0305 | 929 | template<typename _Tp, size_t fixed_size> inline void |
RyoheiHagimoto | 0:0e0631af0305 | 930 | AutoBuffer<_Tp, fixed_size>::allocate(size_t _size) |
RyoheiHagimoto | 0:0e0631af0305 | 931 | { |
RyoheiHagimoto | 0:0e0631af0305 | 932 | if(_size <= sz) |
RyoheiHagimoto | 0:0e0631af0305 | 933 | { |
RyoheiHagimoto | 0:0e0631af0305 | 934 | sz = _size; |
RyoheiHagimoto | 0:0e0631af0305 | 935 | return; |
RyoheiHagimoto | 0:0e0631af0305 | 936 | } |
RyoheiHagimoto | 0:0e0631af0305 | 937 | deallocate(); |
RyoheiHagimoto | 0:0e0631af0305 | 938 | sz = _size; |
RyoheiHagimoto | 0:0e0631af0305 | 939 | if(_size > fixed_size) |
RyoheiHagimoto | 0:0e0631af0305 | 940 | { |
RyoheiHagimoto | 0:0e0631af0305 | 941 | ptr = new _Tp[_size]; |
RyoheiHagimoto | 0:0e0631af0305 | 942 | } |
RyoheiHagimoto | 0:0e0631af0305 | 943 | } |
RyoheiHagimoto | 0:0e0631af0305 | 944 | |
RyoheiHagimoto | 0:0e0631af0305 | 945 | template<typename _Tp, size_t fixed_size> inline void |
RyoheiHagimoto | 0:0e0631af0305 | 946 | AutoBuffer<_Tp, fixed_size>::deallocate() |
RyoheiHagimoto | 0:0e0631af0305 | 947 | { |
RyoheiHagimoto | 0:0e0631af0305 | 948 | if( ptr != buf ) |
RyoheiHagimoto | 0:0e0631af0305 | 949 | { |
RyoheiHagimoto | 0:0e0631af0305 | 950 | delete[] ptr; |
RyoheiHagimoto | 0:0e0631af0305 | 951 | ptr = buf; |
RyoheiHagimoto | 0:0e0631af0305 | 952 | sz = fixed_size; |
RyoheiHagimoto | 0:0e0631af0305 | 953 | } |
RyoheiHagimoto | 0:0e0631af0305 | 954 | } |
RyoheiHagimoto | 0:0e0631af0305 | 955 | |
RyoheiHagimoto | 0:0e0631af0305 | 956 | template<typename _Tp, size_t fixed_size> inline void |
RyoheiHagimoto | 0:0e0631af0305 | 957 | AutoBuffer<_Tp, fixed_size>::resize(size_t _size) |
RyoheiHagimoto | 0:0e0631af0305 | 958 | { |
RyoheiHagimoto | 0:0e0631af0305 | 959 | if(_size <= sz) |
RyoheiHagimoto | 0:0e0631af0305 | 960 | { |
RyoheiHagimoto | 0:0e0631af0305 | 961 | sz = _size; |
RyoheiHagimoto | 0:0e0631af0305 | 962 | return; |
RyoheiHagimoto | 0:0e0631af0305 | 963 | } |
RyoheiHagimoto | 0:0e0631af0305 | 964 | size_t i, prevsize = sz, minsize = MIN(prevsize, _size); |
RyoheiHagimoto | 0:0e0631af0305 | 965 | _Tp* prevptr = ptr; |
RyoheiHagimoto | 0:0e0631af0305 | 966 | |
RyoheiHagimoto | 0:0e0631af0305 | 967 | ptr = _size > fixed_size ? new _Tp[_size] : buf; |
RyoheiHagimoto | 0:0e0631af0305 | 968 | sz = _size; |
RyoheiHagimoto | 0:0e0631af0305 | 969 | |
RyoheiHagimoto | 0:0e0631af0305 | 970 | if( ptr != prevptr ) |
RyoheiHagimoto | 0:0e0631af0305 | 971 | for( i = 0; i < minsize; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 972 | ptr[i] = prevptr[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 973 | for( i = prevsize; i < _size; i++ ) |
RyoheiHagimoto | 0:0e0631af0305 | 974 | ptr[i] = _Tp(); |
RyoheiHagimoto | 0:0e0631af0305 | 975 | |
RyoheiHagimoto | 0:0e0631af0305 | 976 | if( prevptr != buf ) |
RyoheiHagimoto | 0:0e0631af0305 | 977 | delete[] prevptr; |
RyoheiHagimoto | 0:0e0631af0305 | 978 | } |
RyoheiHagimoto | 0:0e0631af0305 | 979 | |
RyoheiHagimoto | 0:0e0631af0305 | 980 | template<typename _Tp, size_t fixed_size> inline size_t |
RyoheiHagimoto | 0:0e0631af0305 | 981 | AutoBuffer<_Tp, fixed_size>::size() const |
RyoheiHagimoto | 0:0e0631af0305 | 982 | { return sz; } |
RyoheiHagimoto | 0:0e0631af0305 | 983 | |
RyoheiHagimoto | 0:0e0631af0305 | 984 | template<typename _Tp, size_t fixed_size> inline |
RyoheiHagimoto | 0:0e0631af0305 | 985 | AutoBuffer<_Tp, fixed_size>::operator _Tp* () |
RyoheiHagimoto | 0:0e0631af0305 | 986 | { return ptr; } |
RyoheiHagimoto | 0:0e0631af0305 | 987 | |
RyoheiHagimoto | 0:0e0631af0305 | 988 | template<typename _Tp, size_t fixed_size> inline |
RyoheiHagimoto | 0:0e0631af0305 | 989 | AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const |
RyoheiHagimoto | 0:0e0631af0305 | 990 | { return ptr; } |
RyoheiHagimoto | 0:0e0631af0305 | 991 | |
RyoheiHagimoto | 0:0e0631af0305 | 992 | #ifndef OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 993 | template<> inline std::string CommandLineParser::get<std::string>(int index, bool space_delete) const |
RyoheiHagimoto | 0:0e0631af0305 | 994 | { |
RyoheiHagimoto | 0:0e0631af0305 | 995 | return get<String>(index, space_delete); |
RyoheiHagimoto | 0:0e0631af0305 | 996 | } |
RyoheiHagimoto | 0:0e0631af0305 | 997 | template<> inline std::string CommandLineParser::get<std::string>(const String& name, bool space_delete) const |
RyoheiHagimoto | 0:0e0631af0305 | 998 | { |
RyoheiHagimoto | 0:0e0631af0305 | 999 | return get<String>(name, space_delete); |
RyoheiHagimoto | 0:0e0631af0305 | 1000 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1001 | #endif // OPENCV_NOSTL |
RyoheiHagimoto | 0:0e0631af0305 | 1002 | |
RyoheiHagimoto | 0:0e0631af0305 | 1003 | //! @endcond |
RyoheiHagimoto | 0:0e0631af0305 | 1004 | |
RyoheiHagimoto | 0:0e0631af0305 | 1005 | |
RyoheiHagimoto | 0:0e0631af0305 | 1006 | // Basic Node class for tree building |
RyoheiHagimoto | 0:0e0631af0305 | 1007 | template<class OBJECT> |
RyoheiHagimoto | 0:0e0631af0305 | 1008 | class CV_EXPORTS Node |
RyoheiHagimoto | 0:0e0631af0305 | 1009 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1010 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 1011 | Node() |
RyoheiHagimoto | 0:0e0631af0305 | 1012 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1013 | m_pParent = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1014 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1015 | Node(OBJECT& payload) : m_payload(payload) |
RyoheiHagimoto | 0:0e0631af0305 | 1016 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1017 | m_pParent = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1018 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1019 | ~Node() |
RyoheiHagimoto | 0:0e0631af0305 | 1020 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1021 | removeChilds(); |
RyoheiHagimoto | 0:0e0631af0305 | 1022 | if (m_pParent) |
RyoheiHagimoto | 0:0e0631af0305 | 1023 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1024 | int idx = m_pParent->findChild(this); |
RyoheiHagimoto | 0:0e0631af0305 | 1025 | if (idx >= 0) |
RyoheiHagimoto | 0:0e0631af0305 | 1026 | m_pParent->m_childs.erase(m_pParent->m_childs.begin() + idx); |
RyoheiHagimoto | 0:0e0631af0305 | 1027 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1028 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1029 | |
RyoheiHagimoto | 0:0e0631af0305 | 1030 | Node<OBJECT>* findChild(OBJECT& payload) const |
RyoheiHagimoto | 0:0e0631af0305 | 1031 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1032 | for(size_t i = 0; i < this->m_childs.size(); i++) |
RyoheiHagimoto | 0:0e0631af0305 | 1033 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1034 | if(this->m_childs[i]->m_payload == payload) |
RyoheiHagimoto | 0:0e0631af0305 | 1035 | return this->m_childs[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 1036 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1037 | return NULL; |
RyoheiHagimoto | 0:0e0631af0305 | 1038 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1039 | |
RyoheiHagimoto | 0:0e0631af0305 | 1040 | int findChild(Node<OBJECT> *pNode) const |
RyoheiHagimoto | 0:0e0631af0305 | 1041 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1042 | for (size_t i = 0; i < this->m_childs.size(); i++) |
RyoheiHagimoto | 0:0e0631af0305 | 1043 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1044 | if(this->m_childs[i] == pNode) |
RyoheiHagimoto | 0:0e0631af0305 | 1045 | return (int)i; |
RyoheiHagimoto | 0:0e0631af0305 | 1046 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1047 | return -1; |
RyoheiHagimoto | 0:0e0631af0305 | 1048 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1049 | |
RyoheiHagimoto | 0:0e0631af0305 | 1050 | void addChild(Node<OBJECT> *pNode) |
RyoheiHagimoto | 0:0e0631af0305 | 1051 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1052 | if(!pNode) |
RyoheiHagimoto | 0:0e0631af0305 | 1053 | return; |
RyoheiHagimoto | 0:0e0631af0305 | 1054 | |
RyoheiHagimoto | 0:0e0631af0305 | 1055 | CV_Assert(pNode->m_pParent == 0); |
RyoheiHagimoto | 0:0e0631af0305 | 1056 | pNode->m_pParent = this; |
RyoheiHagimoto | 0:0e0631af0305 | 1057 | this->m_childs.push_back(pNode); |
RyoheiHagimoto | 0:0e0631af0305 | 1058 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1059 | |
RyoheiHagimoto | 0:0e0631af0305 | 1060 | void removeChilds() |
RyoheiHagimoto | 0:0e0631af0305 | 1061 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1062 | for(size_t i = 0; i < m_childs.size(); i++) |
RyoheiHagimoto | 0:0e0631af0305 | 1063 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1064 | m_childs[i]->m_pParent = 0; // avoid excessive parent vector trimming |
RyoheiHagimoto | 0:0e0631af0305 | 1065 | delete m_childs[i]; |
RyoheiHagimoto | 0:0e0631af0305 | 1066 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1067 | m_childs.clear(); |
RyoheiHagimoto | 0:0e0631af0305 | 1068 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1069 | |
RyoheiHagimoto | 0:0e0631af0305 | 1070 | int getDepth() |
RyoheiHagimoto | 0:0e0631af0305 | 1071 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1072 | int count = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1073 | Node *pParent = m_pParent; |
RyoheiHagimoto | 0:0e0631af0305 | 1074 | while(pParent) count++, pParent = pParent->m_pParent; |
RyoheiHagimoto | 0:0e0631af0305 | 1075 | return count; |
RyoheiHagimoto | 0:0e0631af0305 | 1076 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1077 | |
RyoheiHagimoto | 0:0e0631af0305 | 1078 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 1079 | OBJECT m_payload; |
RyoheiHagimoto | 0:0e0631af0305 | 1080 | Node<OBJECT>* m_pParent; |
RyoheiHagimoto | 0:0e0631af0305 | 1081 | std::vector<Node<OBJECT>*> m_childs; |
RyoheiHagimoto | 0:0e0631af0305 | 1082 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1083 | |
RyoheiHagimoto | 0:0e0631af0305 | 1084 | // Instrumentation external interface |
RyoheiHagimoto | 0:0e0631af0305 | 1085 | namespace instr |
RyoheiHagimoto | 0:0e0631af0305 | 1086 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1087 | |
RyoheiHagimoto | 0:0e0631af0305 | 1088 | #if !defined OPENCV_ABI_CHECK |
RyoheiHagimoto | 0:0e0631af0305 | 1089 | |
RyoheiHagimoto | 0:0e0631af0305 | 1090 | enum TYPE |
RyoheiHagimoto | 0:0e0631af0305 | 1091 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1092 | TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function |
RyoheiHagimoto | 0:0e0631af0305 | 1093 | TYPE_MARKER, // Information marker |
RyoheiHagimoto | 0:0e0631af0305 | 1094 | TYPE_WRAPPER, // Wrapper function for implementation |
RyoheiHagimoto | 0:0e0631af0305 | 1095 | TYPE_FUN, // Simple function call |
RyoheiHagimoto | 0:0e0631af0305 | 1096 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1097 | |
RyoheiHagimoto | 0:0e0631af0305 | 1098 | enum IMPL |
RyoheiHagimoto | 0:0e0631af0305 | 1099 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1100 | IMPL_PLAIN = 0, |
RyoheiHagimoto | 0:0e0631af0305 | 1101 | IMPL_IPP, |
RyoheiHagimoto | 0:0e0631af0305 | 1102 | IMPL_OPENCL, |
RyoheiHagimoto | 0:0e0631af0305 | 1103 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1104 | |
RyoheiHagimoto | 0:0e0631af0305 | 1105 | struct NodeDataTls |
RyoheiHagimoto | 0:0e0631af0305 | 1106 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1107 | NodeDataTls() |
RyoheiHagimoto | 0:0e0631af0305 | 1108 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1109 | m_ticksTotal = 0; |
RyoheiHagimoto | 0:0e0631af0305 | 1110 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1111 | uint64 m_ticksTotal; |
RyoheiHagimoto | 0:0e0631af0305 | 1112 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1113 | |
RyoheiHagimoto | 0:0e0631af0305 | 1114 | class CV_EXPORTS NodeData |
RyoheiHagimoto | 0:0e0631af0305 | 1115 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1116 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 1117 | NodeData(const char* funName = 0, const char* fileName = NULL, int lineNum = 0, void* retAddress = NULL, bool alwaysExpand = false, cv::instr::TYPE instrType = TYPE_GENERAL, cv::instr::IMPL implType = IMPL_PLAIN); |
RyoheiHagimoto | 0:0e0631af0305 | 1118 | NodeData(NodeData &ref); |
RyoheiHagimoto | 0:0e0631af0305 | 1119 | ~NodeData(); |
RyoheiHagimoto | 0:0e0631af0305 | 1120 | NodeData& operator=(const NodeData&); |
RyoheiHagimoto | 0:0e0631af0305 | 1121 | |
RyoheiHagimoto | 0:0e0631af0305 | 1122 | cv::String m_funName; |
RyoheiHagimoto | 0:0e0631af0305 | 1123 | cv::instr::TYPE m_instrType; |
RyoheiHagimoto | 0:0e0631af0305 | 1124 | cv::instr::IMPL m_implType; |
RyoheiHagimoto | 0:0e0631af0305 | 1125 | const char* m_fileName; |
RyoheiHagimoto | 0:0e0631af0305 | 1126 | int m_lineNum; |
RyoheiHagimoto | 0:0e0631af0305 | 1127 | void* m_retAddress; |
RyoheiHagimoto | 0:0e0631af0305 | 1128 | bool m_alwaysExpand; |
RyoheiHagimoto | 0:0e0631af0305 | 1129 | bool m_funError; |
RyoheiHagimoto | 0:0e0631af0305 | 1130 | |
RyoheiHagimoto | 0:0e0631af0305 | 1131 | volatile int m_counter; |
RyoheiHagimoto | 0:0e0631af0305 | 1132 | volatile uint64 m_ticksTotal; |
RyoheiHagimoto | 0:0e0631af0305 | 1133 | TLSData<NodeDataTls> m_tls; |
RyoheiHagimoto | 0:0e0631af0305 | 1134 | int m_threads; |
RyoheiHagimoto | 0:0e0631af0305 | 1135 | |
RyoheiHagimoto | 0:0e0631af0305 | 1136 | // No synchronization |
RyoheiHagimoto | 0:0e0631af0305 | 1137 | double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; } |
RyoheiHagimoto | 0:0e0631af0305 | 1138 | double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; } |
RyoheiHagimoto | 0:0e0631af0305 | 1139 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1140 | bool operator==(const NodeData& lhs, const NodeData& rhs); |
RyoheiHagimoto | 0:0e0631af0305 | 1141 | |
RyoheiHagimoto | 0:0e0631af0305 | 1142 | typedef Node<NodeData> InstrNode; |
RyoheiHagimoto | 0:0e0631af0305 | 1143 | |
RyoheiHagimoto | 0:0e0631af0305 | 1144 | CV_EXPORTS InstrNode* getTrace(); |
RyoheiHagimoto | 0:0e0631af0305 | 1145 | |
RyoheiHagimoto | 0:0e0631af0305 | 1146 | #endif // !defined OPENCV_ABI_CHECK |
RyoheiHagimoto | 0:0e0631af0305 | 1147 | |
RyoheiHagimoto | 0:0e0631af0305 | 1148 | |
RyoheiHagimoto | 0:0e0631af0305 | 1149 | CV_EXPORTS bool useInstrumentation(); |
RyoheiHagimoto | 0:0e0631af0305 | 1150 | CV_EXPORTS void setUseInstrumentation(bool flag); |
RyoheiHagimoto | 0:0e0631af0305 | 1151 | CV_EXPORTS void resetTrace(); |
RyoheiHagimoto | 0:0e0631af0305 | 1152 | |
RyoheiHagimoto | 0:0e0631af0305 | 1153 | enum FLAGS |
RyoheiHagimoto | 0:0e0631af0305 | 1154 | { |
RyoheiHagimoto | 0:0e0631af0305 | 1155 | FLAGS_NONE = 0, |
RyoheiHagimoto | 0:0e0631af0305 | 1156 | FLAGS_MAPPING = 0x01, |
RyoheiHagimoto | 0:0e0631af0305 | 1157 | FLAGS_EXPAND_SAME_NAMES = 0x02, |
RyoheiHagimoto | 0:0e0631af0305 | 1158 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 1159 | |
RyoheiHagimoto | 0:0e0631af0305 | 1160 | CV_EXPORTS void setFlags(FLAGS modeFlags); |
RyoheiHagimoto | 0:0e0631af0305 | 1161 | static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); } |
RyoheiHagimoto | 0:0e0631af0305 | 1162 | CV_EXPORTS FLAGS getFlags(); |
RyoheiHagimoto | 0:0e0631af0305 | 1163 | } |
RyoheiHagimoto | 0:0e0631af0305 | 1164 | |
RyoheiHagimoto | 0:0e0631af0305 | 1165 | } //namespace cv |
RyoheiHagimoto | 0:0e0631af0305 | 1166 | |
RyoheiHagimoto | 0:0e0631af0305 | 1167 | #ifndef DISABLE_OPENCV_24_COMPATIBILITY |
RyoheiHagimoto | 0:0e0631af0305 | 1168 | #include "opencv2/core/core_c.h" |
RyoheiHagimoto | 0:0e0631af0305 | 1169 | #endif |
RyoheiHagimoto | 0:0e0631af0305 | 1170 | |
RyoheiHagimoto | 0:0e0631af0305 | 1171 | #endif //OPENCV_CORE_UTILITY_H |