init: 64 bits version of the webcam

This commit is contained in:
2026-07-13 16:31:52 +02:00
parent c0f3eeb00d
commit 07e526544d
381 changed files with 43996 additions and 9097 deletions

View File

@ -42,14 +42,23 @@
//
//M*/
#ifndef __OPENCV_CORE_UTILITY_H__
#define __OPENCV_CORE_UTILITY_H__
#ifndef OPENCV_CORE_UTILITY_H
#define OPENCV_CORE_UTILITY_H
#ifndef __cplusplus
# error utility.hpp header must be compiled as C++
#endif
#if defined(check)
# warning Detected Apple 'check' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
#endif
#include "opencv2/core.hpp"
#include <ostream>
#ifdef CV_CXX11
#include <functional>
#endif
namespace cv
{
@ -57,8 +66,8 @@ namespace cv
#ifdef CV_COLLECT_IMPL_DATA
CV_EXPORTS void setImpl(int flags); // set implementation flags and reset storage arrays
CV_EXPORTS void addImpl(int flag, const char* func = 0); // add implementation and function name to storage arrays
// Get stored implementation flags and fucntions names arrays
// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which fucntion
// Get stored implementation flags and functions names arrays
// Each implementation entry correspond to function name entry, so you can find which implementation was executed in which function
CV_EXPORTS int getImpl(std::vector<int> &impl, std::vector<String> &funName);
CV_EXPORTS bool useCollection(); // return implementation collection state
@ -98,7 +107,7 @@ CV_EXPORTS void setUseCollection(bool flag); // set implementation collection st
\code
void my_func(const cv::Mat& m)
{
cv::AutoBuffer<float> buf; // create automatic buffer containing 1000 floats
cv::AutoBuffer<float> buf(1000); // create automatic buffer containing 1000 floats
buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used,
// otherwise the buffer of "m.rows" floats will be allocated
@ -115,7 +124,7 @@ public:
//! the default constructor
AutoBuffer();
//! constructor taking the real buffer size
AutoBuffer(size_t _size);
explicit AutoBuffer(size_t _size);
//! the copy constructor
AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf);
@ -133,17 +142,29 @@ public:
void resize(size_t _size);
//! returns the current buffer size
size_t size() const;
//! returns pointer to the real buffer, stack-allocated or head-allocated
operator _Tp* ();
//! returns read-only pointer to the real buffer, stack-allocated or head-allocated
operator const _Tp* () const;
//! returns pointer to the real buffer, stack-allocated or heap-allocated
inline _Tp* data() { return ptr; }
//! returns read-only pointer to the real buffer, stack-allocated or heap-allocated
inline const _Tp* data() const { return ptr; }
#if !defined(OPENCV_DISABLE_DEPRECATED_COMPATIBILITY) // use to .data() calls instead
//! returns pointer to the real buffer, stack-allocated or heap-allocated
operator _Tp* () { return ptr; }
//! returns read-only pointer to the real buffer, stack-allocated or heap-allocated
operator const _Tp* () const { return ptr; }
#else
//! returns a reference to the element at specified location. No bounds checking is performed in Release builds.
inline _Tp& operator[] (size_t i) { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; }
//! returns a reference to the element at specified location. No bounds checking is performed in Release builds.
inline const _Tp& operator[] (size_t i) const { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; }
#endif
protected:
//! pointer to the real buffer, can point to buf if the buffer is small enough
_Tp* ptr;
//! size of the real buffer
size_t sz;
//! pre-allocated buffer. At least 1 element to confirm C++ standard reqirements
//! pre-allocated buffer. At least 1 element to confirm C++ standard requirements
_Tp buf[(fixed_size > 0) ? fixed_size : 1];
};
@ -173,13 +194,6 @@ extern "C" typedef int (*ErrorCallback)( int status, const char* func_name,
*/
CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdata=0, void** prevUserdata=0);
/** @brief Returns a text string formatted using the printf-like expression.
The function acts like sprintf but forms and returns an STL string. It can be used to form an error
message in the Exception constructor.
@param fmt printf-compatible formatting specifiers.
*/
CV_EXPORTS String format( const char* fmt, ... );
CV_EXPORTS String tempfile( const char* suffix = 0);
CV_EXPORTS void glob(String pattern, std::vector<String>& result, bool recursive = false);
@ -189,51 +203,53 @@ If threads == 0, OpenCV will disable threading optimizations and run all it's fu
sequentially. Passing threads \< 0 will reset threads number to system default. This function must
be called outside of parallel region.
OpenCV will try to run it's functions with specified threads number, but some behaviour differs from
OpenCV will try to run its functions with specified threads number, but some behaviour differs from
framework:
- `TBB` User-defined parallel constructions will run with the same threads number, if
another does not specified. If late on user creates own scheduler, OpenCV will be use it.
- `OpenMP` No special defined behaviour.
- `Concurrency` If threads == 1, OpenCV will disable threading optimizations and run it's
- `TBB` - User-defined parallel constructions will run with the same threads number, if
another is not specified. If later on user creates his own scheduler, OpenCV will use it.
- `OpenMP` - No special defined behaviour.
- `Concurrency` - If threads == 1, OpenCV will disable threading optimizations and run its
functions sequentially.
- `GCD` Supports only values \<= 0.
- `C=` No special defined behaviour.
- `GCD` - Supports only values \<= 0.
- `C=` - No special defined behaviour.
@param nthreads Number of threads used by OpenCV.
@sa getNumThreads, getThreadNum
*/
CV_EXPORTS void setNumThreads(int nthreads);
CV_EXPORTS_W void setNumThreads(int nthreads);
/** @brief Returns the number of threads used by OpenCV for parallel regions.
Always returns 1 if OpenCV is built without threading support.
The exact meaning of return value depends on the threading framework used by OpenCV library:
- `TBB` The number of threads, that OpenCV will try to use for parallel regions. If there is
- `TBB` - The number of threads, that OpenCV will try to use for parallel regions. If there is
any tbb::thread_scheduler_init in user code conflicting with OpenCV, then function returns
default number of threads used by TBB library.
- `OpenMP` An upper bound on the number of threads that could be used to form a new team.
- `Concurrency` The number of threads, that OpenCV will try to use for parallel regions.
- `GCD` Unsupported; returns the GCD thread pool limit (512) for compatibility.
- `C=` The number of threads, that OpenCV will try to use for parallel regions, if before
- `OpenMP` - An upper bound on the number of threads that could be used to form a new team.
- `Concurrency` - The number of threads, that OpenCV will try to use for parallel regions.
- `GCD` - Unsupported; returns the GCD thread pool limit (512) for compatibility.
- `C=` - The number of threads, that OpenCV will try to use for parallel regions, if before
called setNumThreads with threads \> 0, otherwise returns the number of logical CPUs,
available for the process.
@sa setNumThreads, getThreadNum
*/
CV_EXPORTS int getNumThreads();
CV_EXPORTS_W int getNumThreads();
/** @brief Returns the index of the currently executed thread within the current parallel region. Always
returns 0 if called outside of parallel region.
The exact meaning of return value depends on the threading framework used by OpenCV library:
- `TBB` Unsupported with current 4.1 TBB release. May be will be supported in future.
- `OpenMP` The thread number, within the current team, of the calling thread.
- `Concurrency` An ID for the virtual processor that the current context is executing on (0
@deprecated Current implementation doesn't corresponding to this documentation.
The exact meaning of the return value depends on the threading framework used by OpenCV library:
- `TBB` - Unsupported with current 4.1 TBB release. Maybe will be supported in future.
- `OpenMP` - The thread number, within the current team, of the calling thread.
- `Concurrency` - An ID for the virtual processor that the current context is executing on (0
for master thread and unique number for others, but not necessary 1,2,3,...).
- `GCD` System calling thread's ID. Never returns 0 inside parallel region.
- `C=` The index of the current parallel task.
- `GCD` - System calling thread's ID. Never returns 0 inside parallel region.
- `C=` - The index of the current parallel task.
@sa setNumThreads, getNumThreads
*/
CV_EXPORTS int getThreadNum();
CV_EXPORTS_W int getThreadNum();
/** @brief Returns full configuration time cmake output.
@ -243,11 +259,29 @@ architecture.
*/
CV_EXPORTS_W const String& getBuildInformation();
/** @brief Returns library version string
For example "3.4.1-dev".
@sa getMajorVersion, getMinorVersion, getRevisionVersion
*/
CV_EXPORTS_W String getVersionString();
/** @brief Returns major library version */
CV_EXPORTS_W int getVersionMajor();
/** @brief Returns minor library version */
CV_EXPORTS_W int getVersionMinor();
/** @brief Returns revision field of the library version */
CV_EXPORTS_W int getVersionRevision();
/** @brief Returns the number of ticks.
The function returns the number of ticks after the certain event (for example, when the machine was
turned on). It can be used to initialize RNG or to measure a function execution time by reading the
tick count before and after the function call. See also the tick frequency.
tick count before and after the function call.
@sa getTickFrequency, TickMeter
*/
CV_EXPORTS_W int64 getTickCount();
@ -260,9 +294,139 @@ execution time in seconds:
// do something ...
t = ((double)getTickCount() - t)/getTickFrequency();
@endcode
@sa getTickCount, TickMeter
*/
CV_EXPORTS_W double getTickFrequency();
/** @brief a Class to measure passing time.
The class computes passing time by counting the number of ticks per second. That is, the following code computes the
execution time in seconds:
@code
TickMeter tm;
tm.start();
// do something ...
tm.stop();
std::cout << tm.getTimeSec();
@endcode
It is also possible to compute the average time over multiple runs:
@code
TickMeter tm;
for (int i = 0; i < 100; i++)
{
tm.start();
// do something ...
tm.stop();
}
double average_time = tm.getTimeSec() / tm.getCounter();
std::cout << "Average time in second per iteration is: " << average_time << std::endl;
@endcode
@sa getTickCount, getTickFrequency
*/
class CV_EXPORTS_W TickMeter
{
public:
//! the default constructor
CV_WRAP TickMeter()
{
reset();
}
/**
starts counting ticks.
*/
CV_WRAP void start()
{
startTime = cv::getTickCount();
}
/**
stops counting ticks.
*/
CV_WRAP void stop()
{
int64 time = cv::getTickCount();
if (startTime == 0)
return;
++counter;
sumTime += (time - startTime);
startTime = 0;
}
/**
returns counted ticks.
*/
CV_WRAP int64 getTimeTicks() const
{
return sumTime;
}
/**
returns passed time in microseconds.
*/
CV_WRAP double getTimeMicro() const
{
return getTimeMilli()*1e3;
}
/**
returns passed time in milliseconds.
*/
CV_WRAP double getTimeMilli() const
{
return getTimeSec()*1e3;
}
/**
returns passed time in seconds.
*/
CV_WRAP double getTimeSec() const
{
return (double)getTimeTicks() / getTickFrequency();
}
/**
returns internal counter value.
*/
CV_WRAP int64 getCounter() const
{
return counter;
}
/**
resets internal values.
*/
CV_WRAP void reset()
{
startTime = 0;
sumTime = 0;
counter = 0;
}
private:
int64 counter;
int64 sumTime;
int64 startTime;
};
/** @brief output operator
@code
TickMeter tm;
tm.start();
// do something ...
tm.stop();
std::cout << tm;
@endcode
*/
static inline
std::ostream& operator << (std::ostream& out, const TickMeter& tm)
{
return out << tm.getTimeSec() << "sec";
}
/** @brief Returns the number of CPU ticks.
The function returns the current number of CPU ticks on some architectures (such as x86, x64,
@ -277,37 +441,6 @@ execution time.
*/
CV_EXPORTS_W int64 getCPUTickCount();
/** @brief Available CPU features.
remember to keep this list identical to the one in cvdef.h
*/
enum CpuFeatures {
CPU_MMX = 1,
CPU_SSE = 2,
CPU_SSE2 = 3,
CPU_SSE3 = 4,
CPU_SSSE3 = 5,
CPU_SSE4_1 = 6,
CPU_SSE4_2 = 7,
CPU_POPCNT = 8,
CPU_AVX = 10,
CPU_AVX2 = 11,
CPU_FMA3 = 12,
CPU_AVX_512F = 13,
CPU_AVX_512BW = 14,
CPU_AVX_512CD = 15,
CPU_AVX_512DQ = 16,
CPU_AVX_512ER = 17,
CPU_AVX_512IFMA512 = 18,
CPU_AVX_512PF = 19,
CPU_AVX_512VBMI = 20,
CPU_AVX_512VL = 21,
CPU_NEON = 100
};
/** @brief Returns true if the specified feature is supported by the host hardware.
The function returns true if the host hardware supports the specified feature. When user calls
@ -318,6 +451,24 @@ in OpenCV.
*/
CV_EXPORTS_W bool checkHardwareSupport(int feature);
/** @brief Returns feature name by ID
Returns empty string if feature is not defined
*/
CV_EXPORTS_W String getHardwareFeatureName(int feature);
/** @brief Returns list of CPU features enabled during compilation.
Returned value is a string containing space separated list of CPU features with following markers:
- no markers - baseline features
- prefix `*` - features enabled in dispatcher
- suffix `?` - features enabled but not available in HW
Example: `SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?`
*/
CV_EXPORTS std::string getCPUFeaturesLine();
/** @brief Returns the number of logical CPUs available for the process.
*/
CV_EXPORTS_W int getNumberOfCPUs();
@ -326,19 +477,20 @@ CV_EXPORTS_W int getNumberOfCPUs();
/** @brief Aligns a pointer to the specified number of bytes.
The function returns the aligned pointer of the same type as the input pointer:
\f[\texttt{(\_Tp*)(((size\_t)ptr + n-1) \& -n)}\f]
\f[\texttt{(_Tp*)(((size_t)ptr + n-1) & -n)}\f]
@param ptr Aligned pointer.
@param n Alignment size that must be a power of two.
*/
template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
{
CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2
return (_Tp*)(((size_t)ptr + n-1) & -n);
}
/** @brief Aligns a buffer size to the specified number of bytes.
The function returns the minimum number that is greater or equal to sz and is divisible by n :
\f[\texttt{(sz + n-1) \& -n}\f]
The function returns the minimum number that is greater than or equal to sz and is divisible by n :
\f[\texttt{(sz + n-1) & -n}\f]
@param sz Buffer size to align.
@param n Alignment size that must be a power of two.
*/
@ -348,9 +500,43 @@ static inline size_t alignSize(size_t sz, int n)
return (sz + n-1) & -n;
}
/** @brief Integer division with result round up.
Use this function instead of `ceil((float)a / b)` expressions.
@sa alignSize
*/
static inline int divUp(int a, unsigned int b)
{
CV_DbgAssert(a >= 0);
return (a + b - 1) / b;
}
/** @overload */
static inline size_t divUp(size_t a, unsigned int b)
{
return (a + b - 1) / b;
}
/** @brief Round first value up to the nearest multiple of second value.
Use this function instead of `ceil((float)a / b) * b` expressions.
@sa divUp
*/
static inline int roundUp(int a, unsigned int b)
{
CV_DbgAssert(a >= 0);
return a + b - 1 - (a + b -1) % b;
}
/** @overload */
static inline size_t roundUp(size_t a, unsigned int b)
{
return a + b - 1 - (a + b - 1) % b;
}
/** @brief Enables or disables the optimized code.
The function can be used to dynamically turn on and off optimized code (code that uses SSE2, AVX,
The function can be used to dynamically turn on and off optimized dispatched code (code that uses SSE4.2, AVX/AVX2,
and other instructions on the platforms that support it). It sets a global flag that is further
checked by OpenCV functions. Since the flag is not checked in the inner OpenCV loops, it is only
safe to call the function on the very top level in your application where you can be sure that no
@ -369,7 +555,7 @@ The function returns true if the optimized code is enabled. Otherwise, it return
*/
CV_EXPORTS_W bool useOptimized();
static inline size_t getElemSize(int type) { return CV_ELEM_SIZE(type); }
static inline size_t getElemSize(int type) { return (size_t)CV_ELEM_SIZE(type); }
/////////////////////////////// Parallel Primitives //////////////////////////////////
@ -386,15 +572,37 @@ public:
*/
CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.);
#ifdef CV_CXX11
class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody
{
private:
std::function<void(const Range&)> m_functor;
public:
ParallelLoopBodyLambdaWrapper(std::function<void(const Range&)> functor) :
m_functor(functor)
{ }
virtual void operator() (const cv::Range& range) const CV_OVERRIDE
{
m_functor(range);
}
};
inline void parallel_for_(const Range& range, std::function<void(const Range&)> functor, double nstripes=-1.)
{
parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes);
}
#endif
/////////////////////////////// forEach method of cv::Mat ////////////////////////////
template<typename _Tp, typename Functor> inline
void Mat::forEach_impl(const Functor& operation) {
if (false) {
operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast<int*>(NULL));
// If your compiler fail in this line.
operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast<int*>(0));
// If your compiler fails in this line.
// Please check that your functor signature is
// (_Tp&, const int*) <- multidimential
// or (_Tp&, void*) <- in case of you don't need current idx.
// (_Tp&, const int*) <- multi-dimensional
// or (_Tp&, void*) <- in case you don't need current idx.
}
CV_Assert(this->total() / this->size[this->dims - 1] <= INT_MAX);
@ -404,11 +612,12 @@ void Mat::forEach_impl(const Functor& operation) {
{
public:
PixelOperationWrapper(Mat_<_Tp>* const frame, const Functor& _operation)
: mat(frame), op(_operation) {};
virtual ~PixelOperationWrapper(){};
: mat(frame), op(_operation) {}
virtual ~PixelOperationWrapper(){}
// ! Overloaded virtual operator
// convert range call to row call.
virtual void operator()(const Range &range) const {
virtual void operator()(const Range &range) const CV_OVERRIDE
{
const int DIMS = mat->dims;
const int COLS = mat->size[DIMS - 1];
if (DIMS <= 2) {
@ -416,7 +625,7 @@ void Mat::forEach_impl(const Functor& operation) {
this->rowCall2(row, COLS);
}
} else {
std::vector<int> idx(COLS); /// idx is modified in this->rowCall
std::vector<int> idx(DIMS); /// idx is modified in this->rowCall
idx[DIMS - 2] = range.start - 1;
for (int line_num = range.start; line_num < range.end; ++line_num) {
@ -434,7 +643,7 @@ void Mat::forEach_impl(const Functor& operation) {
this->rowCall(&idx[0], COLS, DIMS);
}
}
};
}
private:
Mat_<_Tp>* const mat;
const Functor op;
@ -471,12 +680,12 @@ void Mat::forEach_impl(const Functor& operation) {
op(*pixel++, static_cast<const int*>(idx));
idx[1]++;
}
};
}
PixelOperationWrapper& operator=(const PixelOperationWrapper &) {
CV_Assert(false);
// We can not remove this implementation because Visual Studio warning C4822.
return *this;
};
}
};
parallel_for_(cv::Range(0, LINES), PixelOperationWrapper(reinterpret_cast<Mat_<_Tp>*>(this), operation));
@ -513,30 +722,60 @@ private:
AutoLock& operator = (const AutoLock&);
};
// TLS interface
class CV_EXPORTS TLSDataContainer
{
private:
int key_;
protected:
TLSDataContainer();
virtual ~TLSDataContainer();
public:
virtual void* createDataInstance() const = 0;
virtual void deleteDataInstance(void* data) const = 0;
void gatherData(std::vector<void*> &data) const;
#if OPENCV_ABI_COMPATIBILITY > 300
void* getData() const;
void release();
private:
#else
void release();
public:
void* getData() const;
#endif
virtual void* createDataInstance() const = 0;
virtual void deleteDataInstance(void* pData) const = 0;
int key_;
public:
void cleanup(); //! Release created TLS data container objects. It is similar to release() call, but it keeps TLS container valid.
};
// Main TLS data class
template <typename T>
class TLSData : protected TLSDataContainer
{
public:
inline TLSData() {}
inline ~TLSData() {}
inline T* get() const { return (T*)getData(); }
inline TLSData() {}
inline ~TLSData() { release(); } // Release key and delete associated data
inline T* get() const { return (T*)getData(); } // Get data associated with key
inline T& getRef() const { T* ptr = (T*)getData(); CV_Assert(ptr); return *ptr; } // Get data associated with key
// Get data from all threads
inline void gather(std::vector<T*> &data) const
{
std::vector<void*> &dataVoid = reinterpret_cast<std::vector<void*>&>(data);
gatherData(dataVoid);
}
inline void cleanup() { TLSDataContainer::cleanup(); }
private:
virtual void* createDataInstance() const { return new T; }
virtual void deleteDataInstance(void* data) const { delete (T*)data; }
virtual void* createDataInstance() const CV_OVERRIDE {return new T;} // Wrapper to allocate data by template
virtual void deleteDataInstance(void* pData) const CV_OVERRIDE {delete (T*)pData;} // Wrapper to release data by template
// Disable TLS copy operations
TLSData(TLSData &) {}
TLSData& operator =(const TLSData &) {return *this;}
};
/** @brief Designed for command line parsing
@ -572,7 +811,7 @@ The sample below demonstrates how to use CommandLineParser:
### Keys syntax
The keys parameter is a string containing several blocks, each one is enclosed in curley braces and
The keys parameter is a string containing several blocks, each one is enclosed in curly braces and
describes one argument. Each argument contains three parts separated by the `|` symbol:
-# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the `@` symbol)
@ -585,7 +824,7 @@ For example:
const String keys =
"{help h usage ? | | print this message }"
"{@image1 | | image1 for compare }"
"{@image2 | | image2 for compare }"
"{@image2 |<none>| image2 for compare }"
"{@repeat |1 | number }"
"{path |. | path to file }"
"{fps | -1.0 | fps for output video }"
@ -595,6 +834,13 @@ For example:
}
@endcode
Note that there are no default values for `help` and `timestamp` so we can check their presence using the `has()` method.
Arguments with default values are considered to be always present. Use the `get()` method in these cases to check their
actual value instead.
String keys like `get<String>("@image1")` return the empty string `""` by default - even with an empty default value.
Use the special `<none>` default value to enforce that the returned string must not be empty. (like in `get<String>("@image2")`)
### Usage
For the described keys:
@ -606,7 +852,7 @@ For the described keys:
# Bad call
$ ./app -fps=aaa
ERRORS:
Exception: can not convert: [aaa] to [double]
Parameter 'fps': can not convert: [aaa] to [double]
@endcode
*/
class CV_EXPORTS CommandLineParser
@ -636,7 +882,7 @@ public:
This method returns the path to the executable from the command line (`argv[0]`).
For example, if the application has been started with such command:
For example, if the application has been started with such a command:
@code{.sh}
$ ./bin/my-executable
@endcode
@ -723,7 +969,7 @@ public:
/** @brief Check for parsing errors
Returns true if error occured while accessing the parameters (bad conversion, missing arguments,
Returns false if error occurred while accessing the parameters (bad conversion, missing arguments,
etc.). Call @ref printErrors to print error messages list.
*/
bool check() const;
@ -742,7 +988,7 @@ public:
*/
void printMessage() const;
/** @brief Print list of errors occured
/** @brief Print list of errors occurred
@sa check
*/
@ -813,10 +1059,10 @@ AutoBuffer<_Tp, fixed_size>::allocate(size_t _size)
return;
}
deallocate();
sz = _size;
if(_size > fixed_size)
{
ptr = new _Tp[_size];
sz = _size;
}
}
@ -859,15 +1105,6 @@ template<typename _Tp, size_t fixed_size> inline size_t
AutoBuffer<_Tp, fixed_size>::size() const
{ return sz; }
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::operator _Tp* ()
{ return ptr; }
template<typename _Tp, size_t fixed_size> inline
AutoBuffer<_Tp, fixed_size>::operator const _Tp* () const
{ return ptr; }
#ifndef OPENCV_NOSTL
template<> inline std::string CommandLineParser::get<std::string>(int index, bool space_delete) const
{
return get<String>(index, space_delete);
@ -876,14 +1113,246 @@ template<> inline std::string CommandLineParser::get<std::string>(const String&
{
return get<String>(name, space_delete);
}
#endif // OPENCV_NOSTL
//! @endcond
// Basic Node class for tree building
template<class OBJECT>
class CV_EXPORTS Node
{
public:
Node()
{
m_pParent = 0;
}
Node(OBJECT& payload) : m_payload(payload)
{
m_pParent = 0;
}
~Node()
{
removeChilds();
if (m_pParent)
{
int idx = m_pParent->findChild(this);
if (idx >= 0)
m_pParent->m_childs.erase(m_pParent->m_childs.begin() + idx);
}
}
Node<OBJECT>* findChild(OBJECT& payload) const
{
for(size_t i = 0; i < this->m_childs.size(); i++)
{
if(this->m_childs[i]->m_payload == payload)
return this->m_childs[i];
}
return NULL;
}
int findChild(Node<OBJECT> *pNode) const
{
for (size_t i = 0; i < this->m_childs.size(); i++)
{
if(this->m_childs[i] == pNode)
return (int)i;
}
return -1;
}
void addChild(Node<OBJECT> *pNode)
{
if(!pNode)
return;
CV_Assert(pNode->m_pParent == 0);
pNode->m_pParent = this;
this->m_childs.push_back(pNode);
}
void removeChilds()
{
for(size_t i = 0; i < m_childs.size(); i++)
{
m_childs[i]->m_pParent = 0; // avoid excessive parent vector trimming
delete m_childs[i];
}
m_childs.clear();
}
int getDepth()
{
int count = 0;
Node *pParent = m_pParent;
while(pParent) count++, pParent = pParent->m_pParent;
return count;
}
public:
OBJECT m_payload;
Node<OBJECT>* m_pParent;
std::vector<Node<OBJECT>*> m_childs;
};
// Instrumentation external interface
namespace instr
{
#if !defined OPENCV_ABI_CHECK
enum TYPE
{
TYPE_GENERAL = 0, // OpenCV API function, e.g. exported function
TYPE_MARKER, // Information marker
TYPE_WRAPPER, // Wrapper function for implementation
TYPE_FUN, // Simple function call
};
enum IMPL
{
IMPL_PLAIN = 0,
IMPL_IPP,
IMPL_OPENCL,
};
struct NodeDataTls
{
NodeDataTls()
{
m_ticksTotal = 0;
}
uint64 m_ticksTotal;
};
class CV_EXPORTS NodeData
{
public:
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);
NodeData(NodeData &ref);
~NodeData();
NodeData& operator=(const NodeData&);
cv::String m_funName;
cv::instr::TYPE m_instrType;
cv::instr::IMPL m_implType;
const char* m_fileName;
int m_lineNum;
void* m_retAddress;
bool m_alwaysExpand;
bool m_funError;
volatile int m_counter;
volatile uint64 m_ticksTotal;
TLSData<NodeDataTls> m_tls;
int m_threads;
// No synchronization
double getTotalMs() const { return ((double)m_ticksTotal / cv::getTickFrequency()) * 1000; }
double getMeanMs() const { return (((double)m_ticksTotal/m_counter) / cv::getTickFrequency()) * 1000; }
};
bool operator==(const NodeData& lhs, const NodeData& rhs);
typedef Node<NodeData> InstrNode;
CV_EXPORTS InstrNode* getTrace();
#endif // !defined OPENCV_ABI_CHECK
CV_EXPORTS bool useInstrumentation();
CV_EXPORTS void setUseInstrumentation(bool flag);
CV_EXPORTS void resetTrace();
enum FLAGS
{
FLAGS_NONE = 0,
FLAGS_MAPPING = 0x01,
FLAGS_EXPAND_SAME_NAMES = 0x02,
};
CV_EXPORTS void setFlags(FLAGS modeFlags);
static inline void setFlags(int modeFlags) { setFlags((FLAGS)modeFlags); }
CV_EXPORTS FLAGS getFlags();
} // namespace instr
namespace samples {
//! @addtogroup core_utils_samples
// This section describes utility functions for OpenCV samples.
//
// @note Implementation of these utilities is not thread-safe.
//
//! @{
/** @brief Try to find requested data file
Search directories:
1. Directories passed via `addSamplesDataSearchPath()`
2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable
3. OPENCV_SAMPLES_DATA_PATH environment variable
If parameter value is not empty and nothing is found then stop searching.
4. Detects build/install path based on:
a. current working directory (CWD)
b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
5. Scan `<source>/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree.
6. Scan `<install>/share/OpenCV` directory if install directory is detected.
@see cv::utils::findDataFile
@param relative_path Relative path to data file
@param required Specify "file not found" handling.
If true, function prints information message and raises cv::Exception.
If false, function returns empty result
@param silentMode Disables messages
@return Returns path (absolute or relative to the current directory) or empty string if file is not found
*/
CV_EXPORTS_W cv::String findFile(const cv::String& relative_path, bool required = true, bool silentMode = false);
CV_EXPORTS_W cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode = false);
inline cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode)
{
cv::String res = findFile(relative_path, false, silentMode);
if (res.empty())
return relative_path;
return res;
}
/** @brief Override search data path by adding new search location
Use this only to override default behavior
Passed paths are used in LIFO order.
@param path Path to used samples data
*/
CV_EXPORTS_W void addSamplesDataSearchPath(const cv::String& path);
/** @brief Append samples search data sub directory
General usage is to add OpenCV modules name (`<opencv_contrib>/modules/<name>/samples/data` -> `<name>/samples/data` + `modules/<name>/samples/data`).
Passed subdirectories are used in LIFO order.
@param subdir samples data sub directory
*/
CV_EXPORTS_W void addSamplesDataSearchSubDirectory(const cv::String& subdir);
//! @}
} // namespace samples
namespace utils {
CV_EXPORTS int getThreadID();
} // namespace
} //namespace cv
#ifndef DISABLE_OPENCV_24_COMPATIBILITY
#include "opencv2/core/core_c.h"
#endif
#endif //__OPENCV_CORE_UTILITY_H__
#endif //OPENCV_CORE_UTILITY_H